Forum Moderators: coopster

Message Too Old, No Replies

MySQL Query Quandry

         

bumpaw

9:44 pm on Oct 28, 2004 (gmt 0)

10+ Year Member



I have a simple need to go into a 4 column table and based on the content of the first 3 print the content of the 4th. In other words if column1 = a, column2 = b, and column3 = c then print "dog" from column4. This will be the action for a short form that allows the user to make 3 choices that will determine a link. I have this from another script that I'm trying to modify:

 mysql_select_db('search_links');
$query = "select * from links ";
$result = mysql_query($query);

$num_results = mysql_num_rows($result);

echo '<p>Number of books found: '.$num_results.'</p>';

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['type_prop']));
echo '</strong><br />Author: ';
echo stripslashes($row['area_code']);
echo '<br />ISBN: ';
echo stripslashes($row['price_range']);
echo '<br />Price: ';
echo stripslashes($row['saved_link']);
echo '</p>';
}

The above query prints the entire table and I would like a query that limits to the form choices indicated above. I should have come here and ask hours ago but pride got in my way.:)

bumpaw

4:09 am on Oct 29, 2004 (gmt 0)

10+ Year Member



I finaly cracked it.

mysql_select_db('search_links');
$query = '
SELECT *
FROM links
WHERE '.$type_prop.' = \''.$select_type.'\'
AND '.$area_code.' = \''.$select_area.'\'
AND '.$price_range.' = \''.$select_price.'\'
';
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo '<p>Number of books found: '.$num_results.'</p>';
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_row($result);
echo '<p><strong> Property Type: ';
echo (stripslashes($row['0']));
echo '</strong><br />Area Code: ';
echo stripslashes($row['1']);
echo '<br />Price Range: ';
echo stripslashes($row['2']);
echo '<br />Link: ';
echo stripslashes($row['3']);
echo '</p>';
}