Jump to content

Archived

This topic is now archived and is closed to further replies.

dcgamers

MYSQL&PHP help, how to?

Recommended Posts

ok so i know how to display the newest data from a table, all the data from a table but i need to know how to display 5 (for instance)! How may I do So?

Share this post


Link to post
Share on other sites
For example ....
[code]$query = "SELECT * from $db_table ORDER by $some_field DESC LIMIT 5";[/code]

Share this post


Link to post
Share on other sites
Thanks, Need help again:
How to I show the number of rows of data in a table (in numbers)?

Share this post


Link to post
Share on other sites
try this :
[code]
$query = "SELECT * from $db_table ORDER by $some_field DESC"; // don't have a LIMIT in it
$select_query = mysql_query($query, $link)
   or die("Couldn't select from $db_table ".mysql_error() );
$num_rows = mysql_num_rows($select_query); // gets number of rows
[/code]

Share this post


Link to post
Share on other sites
Thanks it worked.
Hey I'm a c++ guy not a php guy :).
I have one more question and it is about Mysql_query and displaying in a loop, the contents of a database table. I need to know how to be able to click on a link in the loop (per looped item that is) and make it take me to a page where there will be more data for that specific item. Sorry this may be confusing, I don't know the right term names.

Share this post


Link to post
Share on other sites
[!--quoteo(post=364269:date=Apr 13 2006, 02:39 PM:name=dcgamers)--][div class=\'quotetop\']QUOTE(dcgamers @ Apr 13 2006, 02:39 PM) [snapback]364269[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thanks it worked.
Hey I'm a c++ guy not a php guy :).
I have one more question and it is about Mysql_query and displaying in a loop, the contents of a database table. I need to know how to be able to click on a link in the loop (per looped item that is) and make it take me to a page where there will be more data for that specific item. Sorry this may be confusing, I don't know the right term names.
[/quote]

Just use a one row table and echo the values from your query you want, but before the able put this line of code:

[code]<?php do { ?>[/code]

And after the table put the code:

[code]<?php } while ($row_NAME-OF-QUERY = mysql_fetch_assoc($NAME-OF-QUERY )); ?>[/code]

In the table put a link to another page something like this:

[code]<a href="otherpage.php?ID=<?php echo $row_NAME-OF-QUERY['IDFEILD'];?>">More Info</a>[/code]

On your second page make a query that is filtered by the URL Paramater ID and use the ID feild

Hope that all makes sense, not good at explaining

Share this post


Link to post
Share on other sites

×

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.