Jump to content

[SOLVED] Help with Error Message


doucie

Recommended Posts

Hi All,

 

I ge the error message below from the code further down.  Line 19 is while($debt_history=mysqli_fetch_array($result)){

 

Thanks All.  By the way how do I get code to appear in color like on other posts?

 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\reporting\debt_report.php on line 19

 

<?php

//get debt history and display in table

function get_debt_history()

{

$db=mysqli_connect('localhost','root','','debtnet');

if(mysqli_connect_errno())

{

echo 'Could not connect to the database';

exit;

}

$query="SELECT * FROM history WHERE cdebtref=$debtref";

$result=mysqli_query($db,$query);

while($debt_history=mysqli_fetch_array($result)){

echo "<table><tr><td>{$debt_history['cnotes']}</td></tr>";

echo "<table><tr><td>{$debt_history['cusercode']}</td></tr>";

echo "<table><tr><td>{$debt_history['cactiontype']}</td></tr>";

echo "<table><tr><td>{$debt_history['debalance']}</td></tr>";

echo "<table><tr><td>{$debt_history['ihistoryid']}</td></tr></table>";

}

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/47116-solved-help-with-error-message/
Share on other sites

<?PHP

$result=mysqli_query($db,$query);
if (is_resource($result)) { // Check result first
  echo "<table border="0">"; // We start the table
  while($debt_history=mysqli_fetch_array($result)){
     echo "tr><td>{$debt_history['cnotes']}</td></tr>";
     echo "<tr><td>{$debt_history['cusercode']}</td></tr>";
     echo "<tr><td>{$debt_history['cactiontype']}</td></tr>";
     echo "<tr><td>{$debt_history['debalance']}</td></tr>";
     echo "<tr><td>{$debt_history['ihistoryid']}</td></tr>";
  }
  echo "</table>"; // We close the table
}

?>

 

p.s.: use code tags, you can add them by pressing on the # then paste your code and hit it again to close the code tags!

OK, I thought there might be something wrong with the query so I changed it to the simplest one there is.  The strange thing is that my <div> expands as if filled with lots of data but none of it is visible!!??!!?

 

<?php

//get debt history and display in table

function get_debt_history()

{

  $db=mysqli_connect('localhost','root','','debtnet');

  if(mysqli_connect_errno())

  {

      echo 'Could not connect to the database';

      exit;

  }

  $query="SELECT * FROM history";

  $result=mysqli_query($db,$query);

  echo "<table>";

  while($debt_history=mysqli_fetch_array($result)){

      echo "<tr><td>{$debt_history['cactiontime']}</td></tr>";

      echo "<tr><td>{$debt_history['creference']}</td></tr>";

      echo "<tr><td>{$debt_history['ilocationid']}</td></tr>";

      echo "<tr><td>{$debt_history['cnotes']}</td></tr>";

      echo "<tr><td>{$debt_history['cpaymenttype']}</td></tr>";

      }

echo "</table>";

}

 

?>

Its Highly Recomended That YOu Use mysql Not mysqli

Instaed Of    while($debt_history=mysqli_fetch_array($result)){

      echo "<tr><td>{$debt_history['cactiontime']}</td></tr>";

      echo "<tr><td>{$debt_history['creference']}</td></tr>";

      echo "<tr><td>{$debt_history['ilocationid']}</td></tr>";

      echo "<tr><td>{$debt_history['cnotes']}</td></tr>";

      echo "<tr><td>{$debt_history['cpaymenttype']}</td></tr>";

      }

Try this echo mysql_result($result, 2);

The mysqli extension allows you to access the functionality provided by MySQL 4.1 and above. More information about the MySQL Database server can be found at » http://www.mysql.com/

 

If Your server Doesn't Support that or > that version of MySQl your code wouldn't work

   $result=mysqli_query($db,$query) or DIE(mysqli_error());

 

Try that, chances are it is your query that is bad.

 

If that does not work print out the $query and run that in phpMyAdmin and make sure that the query is doing what it is suppose to do.

 

As you can see the query is very simple, there is tons of data in the table.  I've checked via PHPmyAdmin an via the zend ide i'm working in.  The strange thing is the div expands as if the data is there but it is isn't.  Its doing my bleedin head in now.

 

<?php

//get debt history and display in table

function get_debt_history()

{

  $db=mysqli_connect('localhost','root','','debtnet');

  if(mysqli_connect_errno())

  {

      echo 'Could not connect to the database';

      exit;

  }

  $query="SELECT * FROM history";

  $result=mysqli_query($db,$query) or DIE(mysqli_error());

  echo "<table>";

  while($debt_history=mysqli_fetch_array($result)){

      echo "<tr><td>{$debt_history['cdebtref']}</td></tr>";

      }

echo "</table>";

}

 

?>

Honestly Speaking I've never used mysqli before.

You Can Try this

<?php 
//get debt history and display in table
function get_debt_history()
{
   $db=mysqli_connect('localhost','root','','debtnet');
   if(mysqli_connect_errno())
   {
      echo 'Could not connect to the database';
      exit;
   }
   $query="SELECT * FROM history";
   $result=mysqli_query($db,$query) or die(mysqli_error());
echo "<pre>";
if(!$debt_history = mysqli_fetch_array($result))
{
exit('MySQL Error Occured'.mysql_error());
}
   while($debt_history=mysqli_fetch_array($result)){
      echo $debt_history['cdebtref']."\n";
      }
echo "</pre>";
}

?>

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.