Query Isn't Working like others
I for the life of me cannot figure out why this is not outputting a 0 when i try to echo it. It works on the previous query but not for the last one.
// This one works and if there are no movies above 0 then it outpus 0 fine
$tag_movies_result = mysql_query("SELECT * FROM tags WHERE tagname='$n' AND movie > 0");
$total_times_used_movies = mysql_num_rows($tag_movies_result);
// Where as this query returns an error
$tag_shows_result = mysql_query("SELECT * FROM tags WHERE tagname='$n' AND show > 0"); <-- `show`
$total_times_used_shows = mysql_num_rows($tag_shows_result); <-- Line 12
// the error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a5410474/public_html/tags/tag.php on line 12
this is what i use to call it
<li><a href="#shows" rel="shows">Shows (<?php echo $total_times_used_shows; ?>)</a></li>
demo: http://mydb.host56.com/tags.php?n=the
the column name SHOWS needed to be enclosed in `.开发者_高级运维 Topic Closed.
SHOW is reserved keyword wrap tilde (`) around show, like below:
`show`
Reference
If there is an error in a query, the value returned from mysql_query will be FALSE rather than a resource. Try this:
if(!$tag_show_result) {
echo mysql_error();
}
This should help you to identify the error in the query
Actually, I see what the problem might be. You should still add echo mysql_error();
to the line right after the query that is failing, however there is an error in your query. the word show
is a mysql reserved word. Show is used to display information about the database. You can wrap it in backticks like this:
`show`
There's clearly an error in your query; find that, and you will resolve the problem.
More to the point, you should be checking the result of your mysql_query for FALSE to make sure that the query was successful, and if it wasn't, output the error using mysql_error().
精彩评论