how to print 10 records from mysql using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

how to print 10 records from mysql using php

Post by gimpact »

Hi,

I have a mysql query like this

select * from org_app where app_beg <= '2009-09-23 00:00:00' order by app_beg desc limit 10

I have no idea, how do I print all the 10 values into a page? Here is what I am doing. I have a index.php page in which, I am including this file which has this database script.

Any help will be appreciated.
Thank you,
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: how to print 10 records from mysql using php

Post by pickle »

You want to execute the query using mysql_query(). That'll give you a result set.
You want to iterate through that result set using mysql_fetch_array(), mysql_fetch_assoc(), or mysql_fetch_object() - pretty much your choice.
In the loop, output everything your mysql_fetch_*() function returned.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

Re: how to print 10 records from mysql using php

Post by gimpact »

Thank you for replying.

Yes, You are right I dont know how to iterate through mysql_fetch_array(). I know this might sound silly but I have not seen an example before, so have no idea.

Can you please show me a tutorial where this is done?

Thank you,
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: how to print 10 records from mysql using php

Post by John Cartwright »

If you went to any those mysql_fetch_* pages you would see a plethora of examples.
Post Reply