Reputation: 1007
I am trying to display blogs on a certain page here is my code:
<?php
$query = "SELECT * FROM `Blogs` WHERE `Author` = '".$prof->id."' && `id` != '" . mysql_real_escape_string($_GET['id']) . "' && `status` = 'active' LIMIT 6" && "ORDER BY `date` DESC, `time` DESC ";
$request = mysql_query($query,$connection);
while($result = mysql_fetch_array($request)) {
echo "<div class='OldBlogs round_10px'>";
echo "<div class='blogIcon'>";
echo "<a href='http://www.blah.org/BlogProfile.php?id=".$result['id']."'>";
echo "<img src='http://www.blah.org/styles/images/blogIcon.png' border='0'/>";
echo "</a>";
echo "</div>";
echo "<div class='recentBlogTitles'>";
echo "<a href='http://www.blah.org/BlogProfile.php?id=".$result['id']."'>";
echo stripslashes($result['blogTitle']);
echo "</a>";
echo "<br />";
echo "<span class='recentBlogdate'>";
echo "on " . date("M d, Y",strtotime($result['date']));
echo "</span>";
echo "</div>";
echo "</div>";
}
?>
and I am getting this error:
note: line 118 is while($result = mysql_fetch_array($request)) {
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/l/l/0/blah/html/BlogProfile.php on line 118
Upvotes: 0
Views: 77
Reputation: 39356
$query = "SELECT * FROM `Blogs` WHERE `Author` = '".$prof->id."' && `id` != '" . mysql_real_escape_string($_GET['id']) . "' && `status` = 'active' LIMIT 6" && "ORDER BY `date` DESC, `time` DESC ";
Should probably be
$query = "SELECT * FROM `Blogs` WHERE `Author` = '".$prof->id."' && `id` != '" . mysql_real_escape_string($_GET['id']) . "' && `status` = 'active' ORDER BY `date` DESC, `time` DESC LIMIT 6";
Upvotes: 0
Reputation: 12207
The end of your SQL is the problem.
$query = "SELECT * FROM `Blogs` WHERE `Author` = '".$prof->id."' && `id` != '" . mysql_real_escape_string($_GET['id']) . "' && `status` = 'active' LIMIT 6" && "ORDER BY `date` DESC, `time` DESC ";
Should be
$query = "SELECT * FROM `Blogs` WHERE `Author` = '".$prof->id."' && `id` != '" . mysql_real_escape_string($_GET['id']) . "' && `status` = 'active' ORDER BY `date` DESC, `time` DESC LIMIT 6";
Upvotes: 1
Reputation: 2897
Check the result of mysql_query to see if your SQL doesn't contain errors. E.g. you can print the error like this:
// Check result
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
The " && " part of your Query string looks suspicious. enough. Why did you use quotes on it? Now It's not part of your Query string. Check the escaping of your query. Try this:
$query = "SELECT * FROM `Blogs` WHERE `Author` = '".$prof->id."' && `id` != '" . mysql_real_escape_string($_GET['id']) . "' && `status` = 'active' LIMIT 6 && ORDER BY `date` DESC, `time` DESC ";
Upvotes: 1