[thelist] php/mysql help

Matthew Mullenweg matt at swcdesign.com
Tue Feb 19 18:08:00 CST 2002


Where is the data coming from? (database, text file...)

Here's an example of parsing data from a mysql database. Like so:

// this assumes a connection to the database using mysql_pconnect
$sql = mysql_query("SELECT * FROM people") or die(mysql_error());
while ($row = mysql_fetch_array($sql)) {
	$first = $row['first']; //assign variables to the fields in the
database which have been broken into an array
	$nick = $row['nickname'];
	$middle = $row['middle'];
	$last = $row['last'];
	// now conc. the formatted data
	$people .= "<p><strong>$first $middle $last</strong><br
/>\n$first's nickname is '$nick'";
}

Then later on in the page you can just echo it out wherever you want it:
<h1>People and their nicknames</h1>
<?php echo $people; ?>

Hope that's at least a little relevant to your question. If not just
fire back some specifics :)

-Matt

> From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]
> On Behalf Of Sarah Heffron
> Sent: Tuesday, February 19, 2002 5:36 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] php/mysql help
>
> I have some data that I would like to display in this fashion:
>
> Feburary 19, 2002
> 9:14am
> blahblahblah
<snip>




More information about the thelist mailing list