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

Link to comment
Share on other sites

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>";

}

 

?>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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>";

}

 

?>

Link to comment
Share on other sites

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>";
}

?>

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.