View Full Version : how to display all data in my table?

11-12-2012, 05:53 PM
how can i display all data in my table? for example i have a table that has 1 column and i want to display all the data inside that column not just the latest data but all of it how can i do it?

11-13-2012, 04:43 PM
Use a loop along with a fetch function. Most people use a "while" loop, but I prefer a "for" loop.

Assuming you're using MySQL..

//Your query
$sql = "SELECT column1 FROM table1";
// query results
$result = mysql_query($sql);
//Don't forget to check for errors!
if (!result)
die("Query error. Query: $sql<br>Error:".mysql_error());
//loop through the results
$cnt = mysql_num_rows($result);
for ($i = 0; $i < $cnt; $i++)
$row = mysql_fetch_array($result);
//Do whatever you need to with the data now