Jump to content

Formating multiple row, multiple column mysql query?


salto

Recommended Posts

Good morning,

I am a bit stuck on formating the following query.  The methods I have used in the past for getting results in tables werefor a single record return and don't seem to want to work.  Can anyone suggest the appropriate method or point me in a direction of what functions I should be looking at?

Thanks for any insight!

Cheers.
Spence

[code]
<?php
$link = mysql_connect('server', 'sitam', 'password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// select the environmental database
$dbvariable = 'environmental';
//  use dbvariable in case we need to use other db later.
$db_selected = mysql_select_db($dbvariable, $link);
if (!$db_selected) {
die ('Can\'t connect to $dbvariable : ' . mysql_error());
}
$query = "SELECT * FROM res_v5 WHERE Canton LIKE '$canton_var' AND TIPO like '$landuse_var' AND Inunda LIKE '$proximity_var'";
$result = mysql_query($query); 
if (!$result) {
$message  = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
if (mysql_num_rows($result) == 0) {
echo "No rows found";
exit;
}
$loop_num = 1;
$space_val = "_";
//this works, now testing foreach method
while ($row = mysql_fetch_assoc($result)) {
echo $loop_num;
echo $row["ID"];
echo $row["Canton"];
echo $row["TIPO"];
echo $row["Inunda"];
echo $space_val;
$loop_num = $loop_num + 1;
}
print ('did I make it here');
?>
[/code]

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.