Page 1 of 1

how to print 10 records from mysql using php

Posted: Wed Sep 23, 2009 10:06 am
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,

Re: how to print 10 records from mysql using php

Posted: Wed Sep 23, 2009 10:08 am
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.

Re: how to print 10 records from mysql using php

Posted: Wed Sep 23, 2009 12:45 pm
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,

Re: how to print 10 records from mysql using php

Posted: Wed Sep 23, 2009 12:47 pm
by John Cartwright
If you went to any those mysql_fetch_* pages you would see a plethora of examples.