Forum Moderators: coopster

Message Too Old, No Replies

How to display a specific page based on query results?

If one record, show original form, if many show a table

         

otto_man

12:25 pm on Aug 4, 2003 (gmt 0)

10+ Year Member



If the query only returns one row then I would like the result to be returned to the original form and displayed in the appropriate fields. If the query returns more than one row, I would like the results to be displayed in a table on a new page. If I cannot display the table on a new page, is it possible to use a conditional on the original form that determines how query results will be displayed, e.g. if (rows <= 1) display form, else build table? Thank you for reading through my question - any advice would be greatly appreciated.

jatar_k

5:48 pm on Aug 4, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld otto_man,

Sure that is possible. If you are using mysql you could use mysql_num_rows [ca2.php.net] and then choose whether to have the table or the form. You could probably use a switch actually

$query = mysql_query("select * from table where somecol='someval'");
$numrows = mysql_num_rows($query);

switch ($numrows) {
case 0:
echo "no results";
break;
case 1:
//put results into form
break;
default:
//load results into table
break;
}

or something like that