R1der Posted January 23, 2012 Share Posted January 23, 2012 Hi guys, I'm having a issue with a little bit of coding involving SELECT the problem is I want it to select from the database and say limit it to 5 so basicly it prints 5 results from the database but its only printing 1 result Here is the code i'm using $q=mysql_query("SELECT * FROM papercontent LIMIT 5",$c); $content=mysql_result($q,0,0); print " <center><table width = '40%' border = '1'><tr><th> <center><u>Latest Announcements</u></center> $content </tr></td></table> "; Thanks Quote Link to comment Share on other sites More sharing options...
botcha Posted January 23, 2012 Share Posted January 23, 2012 first topic where i may be able to help !! you have 5",$c); should read 5,$c"); your code will return all results after 5, and show $c amount of records LIMIT x will return x amount of records LIMIT x, y will return y records returned, starting at x try that? Quote Link to comment Share on other sites More sharing options...
R1der Posted January 23, 2012 Author Share Posted January 23, 2012 Thanks for your reply but changes what you said and get a error lol.. Warning: mysql_result() expects parameter 1 to be resource, boolean given in /home/crimcity/public_html/login.php on line 144 Quote Link to comment Share on other sites More sharing options...
botcha Posted January 23, 2012 Share Posted January 23, 2012 bugger ! :'( are you meant to have {} curly braces around your result? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2012 Share Posted January 23, 2012 Your query is failing and returning the boolean FALSE. mysql_error should provide the insight needed to figure it out. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 23, 2012 Share Posted January 23, 2012 Your $c variable is likely a mysql connection link resource and is not part of the LIMIT clause in the query. Please use meaningful names for variables or post all the relevant code. Quote Link to comment Share on other sites More sharing options...
mikosiko Posted January 23, 2012 Share Posted January 23, 2012 Hi guys, I'm having a issue with a little bit of coding involving SELECT the problem is I want it to select from the database and say limit it to 5 so basicly it prints 5 results from the database but its only printing 1 result Here is the code i'm using $q=mysql_query("SELECT * FROM papercontent LIMIT 5",$c); $content=mysql_result($q,0,0); print " <center><table width = '40%' border = '1'><tr><th> <center><u>Latest Announcements</u></center> $content </tr></td></table> "; Thanks assuming that $c was your DB link and having in mind that you said that your code was printing only one row (meaning that your query was correct in the way it was) you problem is the way that you are using mysql_result() a read of it definition is in order http://www.php.net/manual/en/function.mysql-result.php also you should read and look the examples of any of the forms of mysql_fetch_***() like mysql_fetch_assoc() per example http://www.php.net/manual/en/function.mysql-fetch-assoc.php Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 23, 2012 Share Posted January 23, 2012 I'm having a issue with a little bit of coding involving SELECT the problem is I want it to select from the database and say limit it to 5 so basicly it prints 5 results from the database but its only printing 1 result It is not an error in the query. You need to loop through the results to get them all. $q=mysql_query("SELECT * FROM papercontent LIMIT 5",$c); //run the query. echo "<center><table width = '40%' border = '1'><tr><th> <center><u>Latest Announcements</u></center>"; //print the first part of the table. while($content=mysql_fetch_row($q)) { //while there are rows left in the database (fetch_row pulls a numeric array, fetch_assoc pulls an associative array) echo "<tr><td>{$content[0]}</td></tr></td>"; //print a new row, with the first column of the database row. } echo '</table>'; //close the table after all rows are finished. Quote Link to comment Share on other sites More sharing options...
R1der Posted January 23, 2012 Author Share Posted January 23, 2012 I'm having a issue with a little bit of coding involving SELECT the problem is I want it to select from the database and say limit it to 5 so basicly it prints 5 results from the database but its only printing 1 result It is not an error in the query. You need to loop through the results to get them all. $q=mysql_query("SELECT * FROM papercontent LIMIT 5",$c); //run the query. echo "<center><table width = '40%' border = '1'><tr><th> <center><u>Latest Announcements</u></center>"; //print the first part of the table. while($content=mysql_fetch_row($q)) { //while there are rows left in the database (fetch_row pulls a numeric array, fetch_assoc pulls an associative array) echo "<tr><td>{$content[0]}</td></tr></td>"; //print a new row, with the first column of the database row. } echo '</table>'; //close the table after all rows are finished. Thanks this worked great Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.