Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /web/sites/user/www.someurl.com/stpexport/index.php on line 10 <?php include('./mysql.php'); $no=$_GET["no"]; $sort=$_GET["sort"]; $sql = "SELECT * FROM `stp_videos` WHERE `convert_status`= 'done' ORDER BY `stp_videos`.`id` $sort LIMIT 0,$no"; $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $mins = floor ($row["runtime"] / 60); $secs = $row["runtime"] % 60; echo "http://www.someurl.com/index.php?view=video&v=".$row["cache_id"]."|http://img.someurl.com/videos/".$row["subdir"]."/".$row["id"]."/5.jpg|".$row["title"]."|".$mins."|".$secs."<br/>\n"; } mysql_close($conn); ?> Code (markup): any ideas whats the problem? thanks!
You either made a typo in one of the column names or the "no" and "sort" variables are breaking the query. PS. google "sql injection attacks" and learn something.
Well, I see this: "LIMIT 0" How it supposed to show any records where you limited it to ZERO records? Perhaps this is a mistake. or Well, I'm not good with PHP but you put 2 variables in the query $sort and $no Don't you have to use this syntax when working with strings: "string1"."string2" like in your example below: $sql = "SELECT * FROM `stp_videos` WHERE `convert_status`= 'done' ORDER BY `stp_videos`.`id` ".$sort."LIMIT 0,".$no; Let me know if I'm right cause I'm curious about it.
Print query before execution, if you can not identify a problem visually, pick up query and execute it manually using phpMyAdmin of whatever tool you are using. You will get error message if there is a problem with query. If you are unable to figure out solution for error in query, do let us know the resultant query for further help
Even if that was the problem, it still wouldn't cause an SQL error, it would just return an empty result. Since you obviously don't know basic SQL, I'll give you a quick lesson. The LIMIT attribute can be used in 2 ways: 1. LIMIT 10 which means that the query will return only 10 results 2. LIMIT 10, 20 which means that the query will return a maximum of 20 results while skipping the first 10. In other words, the first number is the offset and the second is the actual limit. In this case LIMIT 0, $no will display the $no results starting with the first. This is equivalent with LIMIT $no.
Thanks for the lesson in MySQL. I'm self-taught Anyway, this rules out my first theory, but what about a second? $sql="....LIMIT 0, $no"; or it's supposed to be $sql="...LIMIT 0, ".$no; as $no is a variable and not part of the query text.
It doesn't look like you taught yourself anything. Right now you're at a level where you'd struggle with a hello world program. Please go away and don't post anything until you actually learn something useful.
Try to understand what others are saying. If $no is empty (I am assuming ASC for $sort), you'll get the following resultant query SELECT * FROM `stp_videos` WHERE `convert_status`= 'done' ORDER BY `stp_videos`.`id` ASC LIMIT 0, Code (markup): If $no has some value lets say 10 then the query will be SELECT * FROM `stp_videos` WHERE `convert_status`= 'done' ORDER BY `stp_videos`.`id` ASC LIMIT 0,10 Code (markup): Now execute both the queries in MySQL and you'll see the difference which one the people are trying to say.