Jump to content

mysql_num_rows


zero_ZX

Recommended Posts

Hi,

I receive the following error(s):

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\intra\VVS\admin2\orders.php on line 294

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\intra\VVS\admin2\orders.php on line 301

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\intra\VVS\admin2\orders.php on line 294

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\intra\VVS\admin2\orders.php on line 301

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\intra\VVS\admin2\orders.php on line 294

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\intra\VVS\admin2\orders.php on line 301

 

This is my code:

 

<?PHP						

$result = mysql_query("SELECT * FROM orders ORDER BY deadline");

while($row = mysql_fetch_array($result))

{

$info = mysql_query("SELECT * FROM clients WHERE id='".$row['requester']."'");
$inforow = mysql_fetch_array( $info );


echo '		

   							<td><a href="client-edit.php?id=' . $row["requester"] .'">    ' . $inforow["company"] . ' </a></td>

				<td>		<a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Telefon: ' . $inforow["phone"] . '">  <span class="ui-icon ui-icon-comment"></span>
						<a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Kontakt: ' . $inforow["contact"] . '"> <span class="ui-icon ui-icon-person"></span>
						<a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Email: ' . $inforow["email"] . '">  <span class="ui-icon ui-icon-mail-closed"></span>
						<a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Adresse: ' . $inforow["address"] . '">  <span class="ui-icon ui-icon-home"></span> </td>




					    <td><a href="order-view.php?id=' . $row["id"] .'">' . $row["title"] . ' </a></td> ';


					    if ($row["approved"] == "0")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne anmodning er ikke godkendt af en formand"><span class="ui-icon ui-icon-closethick"></span></a> </td>	'; 
						}
						else
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne anmodning er godkendt af en formand"><span class="ui-icon ui-icon-check"></span></a> </td>';
						}


					    if ($row["status"] == "0")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne bestilling er ikke behandlet"><span class="ui-icon ui-icon-flag"></span></a> </td>	'; 
						}
						elseif ($row["status"] == "1")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne bestilling er under behandling"><span class="ui-icon ui-icon-transferthick-e-w"></span></a> </td>';
						}
						elseif ($row["status"] == "2")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne bestilling er færdig behandlet"><span class="ui-icon ui-icon-cart"></span></a> </td>';
						}



$info2 = mysql_query("SELECT * FROM clients WHERE id='".$row['requester']."'");
$inforow2 = mysql_fetch_array( $info2 );	

$info4 = mysql_query("SELECT * FROM slaves WHERE id='".$row['slave']."'");
$inforow4 = mysql_fetch_array( $info4 );		


		echo'			<td>' . $inforow2["username"] . '</td> 
						<td>' . $inforow4["name"] . '</td> 
					    <td>' . $row["deadline"] . '</td>';

$info3 = mysql_query("SELECT * FROM invoices WHERE order='".$row['id']."'");
$inforow3 = mysql_fetch_array( $info3 );	

//Yay! We found an invoice

if(mysql_num_rows($info3)>0)
{

 

The problems appears here: (last line)

if(mysql_num_rows($info3)>0)

 

Basically, i want the queries to detect if there's an invoice created for this order already.

So i use this:

$result = mysql_query("SELECT * FROM orders ORDER BY deadline");
while($row = mysql_fetch_array($result))

$info3 = mysql_query("SELECT * FROM invoices WHERE order='".$row['id']."'");
$inforow3 = mysql_fetch_array( $info3 );	

//Yay! We found an invoice

if(mysql_num_rows($info3)>0)

 

Any help is much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/216657-mysql_num_rows/
Share on other sites

If you echo mysql_error(); it will tell you why any query is failing.

 

For one of the queries, you will find that order is a reserved mysql keyword (as in ORDER BY). You should either rename your order column to something else or you must enclose it in back-ticks `` every time you use it in a query.

Link to comment
https://forums.phpfreaks.com/topic/216657-mysql_num_rows/#findComment-1125670
Share on other sites

How can you tell? You have no logic in place to catch/log/report any errors.

 

Remove the query strings from the execution statements, Store them in variables and add error reporting, as below.

 

$query3 = "SELECT * FROM invoices WHERE order='".$row['id']."'";
$info3 = mysql_query($query3) or die( '<br>$query3 string: ' . $query3 . '<br>cratered with error: ' . mysql_error() . '<br>');
$inforow3 = mysql_fetch_array( $info3 );
//Yay! We found an invoice
if(mysql_num_rows($info3)>0)

Link to comment
https://forums.phpfreaks.com/topic/216657-mysql_num_rows/#findComment-1125671
Share on other sites

Okay, i tried both your suggestions:

$result = mysql_query("SELECT * FROM `orders` ORDER BY deadline" );

 

and

 

$query3 = mysql_query("SELECT * FROM invoices WHERE `order`='".$row['id']."'");

$info3 = mysql_query($query3) or die( '<br>$query3 string: ' . $query3 . '<br>cratered with error: ' . mysql_error() . '<br>');

$inforow3 = mysql_fetch_array( $info3 );

 

Returns:

 

$query3 string: Resource id #11

cratered with error:

 

:(

Link to comment
https://forums.phpfreaks.com/topic/216657-mysql_num_rows/#findComment-1125675
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.