Jump to content


Photo

MYSQL&PHP help, how to?


  • Please log in to reply
6 replies to this topic

#1 dcgamers

dcgamers
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 12 April 2006 - 11:54 PM

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?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 13 April 2006 - 12:27 AM

For example ....
$query = "SELECT * from $db_table ORDER by $some_field DESC LIMIT 5";

Legend has it that reading the manual never killed anyone.
My site

#3 dcgamers

dcgamers
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 13 April 2006 - 01:08 AM

Thanks, Need help again:
How to I show the number of rows of data in a table (in numbers)?

#4 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 13 April 2006 - 01:27 AM

try this :
$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

got a problem? Google helps many of those in need

#5 dcgamers

dcgamers
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 13 April 2006 - 02:39 AM

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.

#6 adamjnz

adamjnz
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 April 2006 - 05:11 AM

[!--quoteo(post=364269:date=Apr 13 2006, 02:39 PM:name=dcgamers)--][div class=\'quotetop\']QUOTE(dcgamers @ Apr 13 2006, 02:39 PM) View Post[/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:

<?php do { ?>

And after the table put the code:

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

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

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

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

#7 dcgamers

dcgamers
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 13 April 2006 - 04:21 PM

can you explain better?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users