|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Help - trying to return 2 mysql_query commands
Can anyone help, I have a PHP script that returns a list of products categorys and also the number products within those categories.
The trouble I have is that it displays the first category and number of products and thats it. The error it comes back with is "mysql_fetch_array(): 8 is not a valid MySQL result resource" however when I remove the following two lines it displays all the categories (but obviously not the number of products within them) $countResult = mysql_query("SELECT count(*) AS num FROM products WHERE cat_id=$cat_id",$conn); $num = mysql_result($countResult,0,"num"); I have tested the SQL and it works The script is:- function cat_list($conn) { global $db_name; global $db_prod_table; global $db_cat_table; $sql = "SELECT * FROM $db_cat_table ORDER BY cat_name"; $result = mysql_query($sql,$conn) or die (mysql_error()); $cat_list ="<table width='800' border='0' cellspacing='2' cellpadding='4'> <tr> <td width='50' bgcolor='#000099'>ID</td> <td width='450' bgcolor='#000099'><b>Category Name</b></td> <td width='200' bgcolor='#000099'><b>Number of products</td> </td width='50'></td> </td width='50'></td> </tr>"; while ($row = mysql_fetch_array($result)) { extract($row); // remove the following 2 lines and it displays all the categories $countResult = mysql_query("SELECT count(*) AS num FROM products WHERE cat_id=$cat_id",$conn); $num = mysql_result($countResult,0,"num"); $cat_list .= "<tr> <td width='50' height='20'>$cat_id</td> <td width='450'>$cat_name</td> <td width='200' align='center'>$num</td> <td width='50' align='center'> <b>a href=confirm_delete.php?cat_id=$cat_id&catProducts=$num>Delete</a></b> </td> <td width='50' bgcolor='#669900' align='center'> <b><a href=modify_cat.php?cat_id=$cat_id>Edit</a></b> </td> </tr>"; } $cat_list .="</table>"; return $cat_list; } Can anyone help |
|
#2
|
|||
|
|||
|
Hi tonyoevans
I put this together, maybe this will help you understand a little more. I'm sure there is a better way... I also didn't know your database schema, so I added a simple structure here. PHP Code:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Help - trying to return 2 mysql_query commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|