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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.