threshold number of records

ricky.10 04 Feb, 2010
Hi, I'm italian and my english is not good,
I'm creating a form for my website. how to threshold number of records?
Data submitted in the 50th, can appear a message that says there's more space?
Thanks a lot!
GreyHead 04 Feb, 2010
Hi ricky.10,

I'm not sure that I understand. Please post in Italian and I'll try a Google translation.

Non sono sicuro di aver capito. Si prega di post in lingua italiana e cercherò una traduzione di Google.

Bob
ricky.10 07 Feb, 2010
Hi Bob,
thanks for your answer.
Io vorrei limitare a 20 i records che possono essere inseriti in un database utilizzando un form creato con ChronoForms.
Gli utenti del mio sito, quando nel form sono stati inseriti 20 records, dovrebbero ricevere un messaggio che impedisce l'inserimento di altri dati.
E' possibile?
Thanks a lot!!!

Riccardo

Google translation:
I would like to limit to 20 the records that can be inserted into a database using a form created with ChronoForms.
The users of my site, when in form were inserted 20 records, should receive a message that prevents the inclusion of additional data.
GreyHead 07 Feb, 2010
Hi Riccardo,

Yes, you can do this.

You need to add a check at the beginning of the Form HTML and show a message if the count is more than 20 records.
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
  SELECT COUNT(*)
    FROM `#_some_table`
    WHERE `user_id` = ".$user->id."
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 20 ) {
  echo "Avete già 20 record";
  return;
}
?>
Not tested and will need debugging. You will need to enter the correct table and column names.

Bob

Google translation:
Sì, è possibile effettuare questa operazione.

È necessario aggiungere un controllo all'inizio del form HTML e mostrare un messaggio se il conteggio è più di 20 record.

Non testato e avrà bisogno di debug. Sarà necessario inserire la tabella corretta e nomi di colonna.
GreyHead 03 Mar, 2010
Hi Riccardo,

I can tell nothing useful from looking at the form.

What have you done with the code I posted earlier?

Bob
ricky.10 03 Mar, 2010
Hi Bob,
I inserted the code you've mentioned, but I did not understand how to reference the column that interests me.
The point where I enter the table name and column is this:

FROM `#` _some_table
WHERE `user_id` = ". $ User-> id."

Right?
But How I enter the name of the column, in my case "primoturno", for the choice "option 1"?
Sorry if questions seem trivial, but I'm inexperienced about the php code.
Thank you

Riccardo
GreyHead 03 Mar, 2010
Hi Riccardo,

That doesn't look much like the code that I posted, there are several bits missing or misplaced.

It looks as though you need to find a basic MySQL tutorial to understand how this works.

Bob
baljee 27 Mar, 2010
Hi GreyHead,

i am looking for a simple way of displaying the number of records in my chronoconnectivity page. I saw the code above and thought this would solve my problem. Modified the code as follows:

<?php

$db =& JFactory::getDBO();
$query = "SELECT COUNT(*) FROM 'jos_chronoforms_vrienden'";
$db->setQuery($query);
$count = $db->loadResult();

echo "recordtotal :".$count;
?>

the value $count isn't filled. Any ideas? Table name is correct. Also tried it with the # in front.

THanks in advance,

Baljé

p.s. i also tried count($rows) this returns 0.
GreyHead 27 Mar, 2010
Hi baljee,

You need backquotes `` round the tablename (not single quotes)
$query = "SELECT COUNT(*) FROM `jos_chronoforms_vrienden`";

Bob
baljee 27 Mar, 2010
Thanks, that did the trick!

Super response time
This topic is locked and no more replies can be posted.