Loading list from Database.

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
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Loading list from Database.

Post by theda »

I was curious as to how I would populate a list from a database.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what kind of list?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

I tend to do something along the lines of:

Code: Select all

$list = array();
$sql = "select name from table";
$result = mysql_query($sql,$databaseConnection);
while ($record = mysql_fetch_object($result)) {
    $list[] = $record->name;
}
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

Well the list is mainly for me to make a database driven website. Basically I want the script to search a certain database, find the contents (which will be the pages of my website), and then list them out. (Later on, I'll be asking how do I make the list able to be clicked as a link and open the corresponding data...)

Edit: For clarification, if you want, visit my website... http://dumbass.ionichost.com [Beware the advertisement popup... damn free host.]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

onion2k's example is along those lines, I believe.
Post Reply