Jump to content

Error on Simple 2 query page


w424637

Recommended Posts

Help please - I have a simple page which errors with: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

 

If I remove the Second Query and Output section it works

 

also

 

If I remove the First Query and Output section it works

 

However both together and it fails at the line while($row=mysql_fetch_array($new2))

 

 

Why is this - drivign me nuts

 

 

<?php

require_once ('connection.php');
//First Query and Output

$result = mysql_query("CALL C01_Client_Summary_ByAccount(1, '2012-02-27', '2013-03-29');");
 
    while($row=mysql_fetch_array($result))
    {
echo $row['CommisionPercentage'];
     }
//END First Query and Output
   
//Second Query and Output
$new2 = mysql_query("CALL C01_Client_Summary_ByBetType(1, '2012-02-27', '2013-03-29');");

    while($row=mysql_fetch_array($new2))
    {
echo $row['Turnover'];
     }
//END Second Query and Output

?>

 

Link to comment
https://forums.phpfreaks.com/topic/275567-error-on-simple-2-query-page/
Share on other sites

Try:

require_once ('connection.php');
//First Query and Output

$result = mysql_query("CALL C01_Client_Summary_ByAccount(1, '2012-02-27', '2013-03-29');");
 
    while($row=mysql_fetch_array($result))
    {
echo $row['CommisionPercentage'];
     }
//END First Query and Output
   
//Second Query and Output
$new2 = mysql_query("CALL C01_Client_Summary_ByBetType(1, '2012-02-27', '2013-03-29');");

    while($row2=mysql_fetch_array($new2))
    {
echo $row2['Turnover'];
     }
//END Second Query and Output

 

I changed the 2nd query's variable by adding a "2" behind it.

The variable names are the problem since they should be overwritten in those scenarios. Besides, the error given by PHP is . . .

 

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

 

That means the query failed. You are calling a stored procedure twice with the same parameters. not knowing what that stored procedure is it is impossible to know if that is correct or not. but, you can help yourslef out by checking the actual error from mysql

 

<?php

require_once ('connection.php');
//First Query and Output

$query = "CALL C01_Client_Summary_ByAccount(1, '2012-02-27', '2013-03-29');";
$result = mysql_query()
    or die("Query: $query<br>Error: " .mysql_error());
 
while($row=mysql_fetch_array($result))
{
    echo $row['CommisionPercentage'];
}
//END First Query and Output
   
//Second Query and Output
$query = "CALL C01_Client_Summary_ByAccount(1, '2012-02-27', '2013-03-29');";
$result = mysql_query()
    or die("Query: $query<br>Error: " .mysql_error());

while($row=mysql_fetch_array($result))
{
    echo $row['Turnover'];
}
//END Second Query and Output

?>

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.