Ok I have this code:
//this is the hi.php//
<?php
//highlight items//
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("juliver", $con);
$result = mysql_query("SELECT * FROM hi WHERE pp='2'");
$hi = "";
while($row = mysql_fetch_array($result)) //<--- this is the line 13//
{
$hi .= "<div id='hicontainer'><a id='download_now' class='imgx' href='#?w=700' rel='popup'><img src='".$row['name']."' />";
$hi .= "<p>".$row['title']."</p>";
$hi .= "<a href='#?w=700' id='".$row['id']."' rel='popup' class='imgx'>View full</a> </div>";
}
//Lots of lots of code here I just specified those code which in error.//
mysql_close($con);
?>
and heres where im going to display the output actually.
<td>
<!--highlight items-->
<div id="tbtitle">
<img src="Images/galleryicon.png"/><p>Highlight items</p>
</div>
<div id="tblgal">
<? echo $hi; ?>
</div>
</td>
But i get an error saying: "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\madeinusa\hi.php on line 13."
please, im stuck with this. Thank you in advance.
echo mysql_error()
can help solve most issues. Do so beneath your mysql_query(...)
- MichaelRushton 2012-04-04 05:07
You probably have an error in your query "SELECT * FROM hi WHERE pp='2'"
Try executing that query directly in mysql and see what happens. Make sure you have the table names and columns spelt right.
Also, try quoting the table names and columns in backtick ` characters to avoid accidentally using MySQL reserved words.
$result
has a boolean value - probably because your query failed.
You should validate the result, before trying to use it.
After your query, you could do something like the following to see why your query fails:
if(!$result)
exit(mysql_error());
or, more simply, you can use
$result = mysql_query("SELECT * FROM hi WHERE pp='2'") or die(mysql_error());
check to this:
mysql_connect("localhost","username","password");
First you should use proper exception handling in the code. After the line
$result = mysql_query("SELECT * FROM hi WHERE pp='2'");
you should check whether it returns resource id or any error in the way
if(!$result){
// if you use try-catch, then use
throw new Exception(mysql_error());
// Or you can use
die(mysql_error());
}else{
while($row = mysql_fetch_array($result)) //<--- this is the line 13//
{
$hi .= "<div id='hicontainer'><a id='download_now' class='imgx' href='#?w=700' rel='popup'><img src='".$row['name']."' />";
$hi .= "<p>".$row['title']."</p>";
$hi .= "<a href='#?w=700' id='".$row['id']."' rel='popup' class='imgx'>View full</a> </div>";
}
}
"SELECT * FROM hi WHERE pp='2'" query may return false means there are no records that full fill query.Try echo mysql_num_rows($result); in order to know no of rows return for query.
mysql_query
will return an empty resultset, not false
- deceze 2012-04-04 05:42
false
. mysql_query
only returns a boolean false
if something was wrong with the query and it could not be executed - deceze 2012-04-04 06:51