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

Link to comment
Share on other sites

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

?>
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.