database query problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, i have a page which views th content of tables, each row in one page,
there is a combo box which shows the IDs of each row, and when user
click on one, it redirects him to the same page with the new ID
there is two problems.
when there is no records in the dataabse i get mysql error.
and when i view the IDs in combo box i want them to be like 1 2  3 


/* this is to choose the last ID in the table if no ID is posted in the page */
if (!isset($id1)){
 @ $db = mysql_connect ($server, $user, $pass);
 mysql_select_db($db_name);
$test_tr = mysql_query("select purchase_id from purchase order by
purchase_id desc limit 1");
while ($record=mysql_fetch_array($test_tr)){
 $id1 = $record['purchase_id'];
}
mysql_close($db);
}
/* this is to list the IDs of the rows in the combo box, i want to
display them in form of 1,  2, 3 instead of the actual IDs numebrs */
@ $db = mysql_connect ($server, $user, $pass);
mysql_select_db($db_name);
$id = array();
$test_tr = mysql_query("select * from purchase order by purchase_id");
while ($record=mysql_fetch_array($test_tr)){
 $id[] = $record['purchase_id'];
}
/* this is where i get the row info to be displayed in the page, i
want it to not to display an error if there is no records in the
database */
@ $db = mysql_connect ($server, $user, $pass);
mysql_select_db($db_name);
$test_tr = mysql_query("select * from purchase WHERE purchase_id=$id1 ");
while ($record=mysql_fetch_array($test_tr)){
echo "whatever";
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux