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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.