Hello i am getting this database error Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/www/user/domain.com/www/components/com_component/component.php on line 334 Line 334 //echo $database->getQuery(); $result1 = $database->query(); while ($row1=mysql_fetch_object($result1) Is there a error return or if false command i can enter in order to avoid this error ? Thanks in advance
$row_count = mysql_num_rows ($result1); if($row_count <1) { echo "no rows returned"; } something like if($result) won't return what you want.
$result1 = $database->query(); *here looks good* make it an IF() ELSE to encompass the WHILE. while ($row1=mysql_fetch_object($result1)
//echo $database->getQuery(); $result1 = $database->query(); $row_count = mysql_num_rows ($result1); if($row_count <1) { echo "no rows returned"; } while ($row1=mysql_fetch_object($result1)) { I know i messed it up ! Now i get two errors
$result1 = $database->query(); $row_count = mysql_num_rows ($result1); if($row_count <1) { echo "no rows returned"; } else { while ($row1=mysql_fetch_object($result1)) { //put code here to display results } } try that. tried to line up the braces since that was most likely your error.
$result1 = $database->query(); while ($row1=mysql_fetch_object($result1)) if($row_count <1) { echo "no rows returned"; } else { while ($row1=mysql_fetch_object($result1)) { //put code here to display results } } Sorry again, error is still appearing . what do i have to enter here ? //put code here to display results
um no. if that's the code you put, its wrong the 2nd line isn't part of the code I posted: $result1 = $database->query(); if($row_count <1) { echo "no rows returned"; } else { while ($row1=mysql_fetch_object($result1)) { //put code here to display results } } if you use a WHILE statement it has to have the { } the code you want to run goes inside of those. //put code here to display results means to insert the correct PHP to display the results something like extract($row1) ; but then you have to know the names of the fields. (if you have a table with a field of products_id you would access it via $products_id ) I'd highly recommend heading over to w3schools.com or tizag.com for their PHP MySQL tutorials. Most of this is covered (lightly but covered).
Thank you, you re great ! Now everything works like a charm ! Also you helped me understanding how things work and what was causing the problem ! i will give a try to the links you gave me