Hi, I am stuck with a SQL syntax error that I can’t identify:
Couldn't execute the query query
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #7' at line 1.
What is “Resource id #7”?
I only get the error when I run the query in my PHP script.The same query ran in phpMyadmin doesn’t give the error.
Here’s my PHP code;
$date_start_select = $_GET['date_start_select'];
$date_end_select = $_GET['date_end_select'];
$query = mysql_query("
SELECT `id`, `date_start`, `date_end`, `title`, `theme`, `body`
FROM `moca_daysahead`
ORDER BY date_start");
$result = mysql_query($query)
or die ("Couldn't execute the query <i>query</i><br />".mysql_error().".");
echo "Query: ".$query."<br /><br />";
// initialize header and set it to an empty string
$header = '';
// mysql_fetch_assoc will return each row from your result set
// when there are no more results, the while loop ends
while ($row=mysql_fetch_assoc($query))
{
// we only want to print the header if it hasn't been seen in the result yet
if ($header!=$row['date_start'])
{
print "<div class=\\"header\\" style=\\"margin-top:20px\\"><u>".$row['date_start']."</u></div><br />\
";
// means the current header display is for $row['date_start']
$header = $row['date_start'];
}
$row['h_title'] = utf8_decode($row['title']);
$row['h_theme'] = utf8_decode($row['theme']);
print "<div style=\\"margin-bottom:8px\\">";
print "<b><a href=\\"daysahead.php?p=daysahead_edit.php&id=".$row['id']."\\">".$row['h_title']."</a></b><br />";
if ($row['theme'])
{
print " (".$row['h_theme'].")";
}
print "</div>\
";
}
MySQL 5.1.49
PHP 4.4.9
Thanks for any help.