Jump to content

Echo'ing data from a database

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts
Hi guys,


I'm looking for a way to echo data from a database. Sounds pretty simple, but i really cant work out how.
I want the data to be withdrawn from the table, then posted individually in the code:
echo "<div class=item>$data</div>"
Where $data is a string of data.

I dont just want it to post one line of data though, I want it to post the whole column. So for each string of data it gets from the database in the column, I want it to post that string and so on until all the data in the table is posted onto the page with the same format:

echo "<div class=item>$data</div>"


Can somebody send me on the right tracks, or give me a snippet?

Thanks a bunch guys!


PS. The data will be loaded from a settings file.. Here's what it looks like so far...


<? 

include("settings.php");

THIS IS WHERE I WANT THE NEW CODE.


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
If you are wanting to dump the column you can do something like this:
$res = mysql_query("SELECT <column_name> FROM <table_name>")
while($row = mysql_fetch_assoc($res)) {
     echo "<div class=item>" . $row['id'] . "</div>";
}
This will print N rows of column 'id', you can change that to which column you wish to display.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.