Jump to content

[SOLVED] right way to read data from a mysql database ?


webmazter

Recommended Posts

$result is just a mysql resource. It holds the data. usually you'll loop through the array and pull out any data. for example:

 

<?php
$sql = "SELECT * FROM table"; // the query
$result = mysql_query($sql) OR DIE (mysql_error()); // run the query to return the data in an array
if (mysql_num_rows($result) > 0) // if we got some data, move on
{
while ($r = mysql_fetch_array($result)) // loop though each element
{
	$name = $r['name']; // pull out a name
	$date = $r['date']; // pull out a date
	echo "<p>Name: {$name}<br />Date: {$date}</p>"; // this gets echoed once for each entry returned
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.