Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/255556-select-help/
Share on other sites

first topic where i may be able to help !! :P

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/255556-select-help/#findComment-1310159
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/255556-select-help/#findComment-1310166
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/255556-select-help/#findComment-1310169
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/255556-select-help/#findComment-1310230
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.