Page 1 of 2
ALL cuisines, as opposed to Italian
Posted: Mon Mar 07, 2005 2:00 am
by saltriver
Hi all,
Long time no type. I've got what the Brits call "a bit of a sticky wicket". I have a search menu for restaurants where you can choose by cuisine AND location. I want to be able to have an "All Cuisines" option for any given location, but I can't seem to figure out how to do it. I'm hoping its a matter of plugging the right value into the list/menu on the search page. I tried "*" and "%s" hoping the wildcard would return all of the possible choices. Nope. I'm thinking, (floudering really) that if I declare a variable on the results page, giving it a value that will return all cuisines, I can plug that into the value of the list menu.
Have I had too much Mt. Dew?
Posted: Mon Mar 07, 2005 2:21 am
by feyd
just do a special processing on the value you pass to the script. Give the all cuisines value "all" or something. If you recieve "all" for cuisines, use a seperate query that just searches by location.
Posted: Mon Mar 07, 2005 4:22 am
by onion2k
The way I usually do "all" options is to have a conditional statement in the sql builder..
Code: Select all
$sql = "select restaurant.* from restaurant where restaurant.location = '".$location."'";
$sql .= ($cuisine != "all") ? " and restaurant.cuisine = '".$cuisine."'" : "";
So if $cuisine is anything other than "all" it'll put a bit in the SQL to select the right type.. Theres probably tidier ways of doing it, but I'm tremendously lazy.
I too am lazy
Posted: Tue Mar 08, 2005 12:16 am
by saltriver
I like the idea. Assume its all, unless you hear otherwise. I'm gonna noodle with that. Thanks for the fresh viewpoint.
Steve
unexpected T_ENCAPSED_AND_WHITESPACE
Posted: Wed Mar 09, 2005 1:03 am
by saltriver
unexpected T_ENCAPSED_AND_WHITESPACE
I think I'm a right track. I'm trying to use if/else, but I think my syntax sucks. I declare $ALL to be true when 'cuisinemenu' = "All Cuisines" as a variable.
IF - that's the case echo this unformatted stuff.
ELSE - echo the stuff I have formatted in the table.
Code: Select all
<?php
$ALL = "All Cuisines";
if ($ALL = ($_POST['cuisinemenu']))
{echo "$row_Recordset1['restaurant']"
echo "$row_Recordset1['cuisinea']"
echo "$row_Recordset1['city']"
echo "$row_Recordset1['loc_county']"
;
} else {
<?php do { ?>
<table width="500" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="350" class="medwhite"><?php echo $row_Recordset1['restaurant']; ?></td>
<td width="150" class="smallwhite"><div align="right"><?php echo $row_Recordset1['cuisinea']; ?></div></td>
</tr>
<tr>
<td width="350" class="smallwhite"><?php echo $row_Recordset1['city']; ?></td>
<td width="150" class="smallwhite"><div align="right"><?php echo $row_Recordset1['loc_county']; ?></div></td>
</tr>
<tr>
<td width="350"> </td>
<td width="150"><div align="right"></div></td>
</tr>
</table>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<p> </p>
}
?>
Sure its sloppy, but is it salvageable?
Looking at the preview, I'm thinking I need to clean up my ELSE. Those extra php tags might be getting in the way even though the error message is telling me its coming from the line after the IF line.
Steve
feyd | hey look at that,
Posted: Wed Mar 09, 2005 1:07 am
by feyd
lines 4-7 need semicolons, and you don't need the double quotes.
Posted: Wed Mar 09, 2005 2:18 am
by saltriver
unexpected T_VARIABLE, expecting '('
I got that after going to single () and adding the ;'s
Heres the new line:
Code: Select all
if $ALL = ($_POSTї'cuisinemenu'])
Steve
Posted: Wed Mar 09, 2005 2:23 am
by feyd
I never said anything about losing parens..
Posted: Sat Mar 12, 2005 12:50 am
by saltriver
Sorry. My bad. Here's my most recent attempt. Right now I'm getting a Parse error: unexpected $ on line 196. Line 196 is the last line of the page and does not have a $ in it. Could this be caused by declaring a variable in the body of the page. Doea it need to be declared above the html?
Code: Select all
<?php
$ALL = "All Cuisines";
if ($ALL = ($_POST['cuisinemenu'])) {
echo $row_Recordset1['restaurant'];
echo $row_Recordset1['cuisinea'];
echo $row_Recordset1['city'];
echo $row_Recordset1['loc_county'];
;
} else {
do {
echo $row_Recordset1['restaurant'];
echo $row_Recordset1['cuisinea'];
echo $row_Recordset1['city'];
echo $row_Recordset1['loc_county'];
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
<!-- InstanceEndEditable --></div></td>
<td width="150" align="center" valign="top"><p align="left" class="medwhite">Popular Destinations </p>
<p align="left"><a href="../city/burlington.php" class="hblinks01">Burlington </a><br>
<a href="../city/st_albans.php" class="hblinks01">St. Albans</a><br>
<a href="../city/stowe.php" class="hblinks01">Stowe</a></p>
</td>
</tr>
<tr>
<td width="150"> </td>
<td width="600"> </td>
<td width="150"> </td>
</tr>
</table>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($Recordset1);
?>
feyd | Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Sat Mar 12, 2005 1:01 am
by infolock
your answer lies within this block of code... look it over carefully
Code: Select all
<?php
$ALL = "All Cuisines";
if ($ALL = ($_POST['cuisinemenu']))
{
echo $row_Recordset1['restaurant'];
echo $row_Recordset1['cuisinea'];
echo $row_Recordset1['city'];
echo $row_Recordset1['loc_county'];
;
}
else
{
do
{
echo $row_Recordset1['restaurant'];
echo $row_Recordset1['cuisinea'];
echo $row_Recordset1['city'];
echo $row_Recordset1['loc_county'];
}
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
remember, proper indention and code structure goes along way... especially when having to debug

Posted: Sat Mar 12, 2005 2:28 am
by feyd
additionally, it appears there's a = vs == issue..
Posted: Sat Mar 12, 2005 2:46 am
by saltriver
I copied and pasted, and still got the error (unexpected $ although it says its on line 59. there's only 58 lines). I made an ultra simplified page.
Code: Select all
<?php require_once('../../../Connections/hungry_vt.php'); ?>
<?php
$countyvar_Recordset1 = "e;1"e;;
if (isset($_POSTї'countymenu'])) {
$countyvar_Recordset1 = (get_magic_quotes_gpc()) ? $_POSTї'countymenu'] : addslashes($_POSTї'countymenu']);
}
$cuisinemenu_Recordset1 = "e;-1"e;;
if (isset($_POSTї'cuisinemenu'])) {
$cuisinemenu_Recordset1 = (get_magic_quotes_gpc()) ? $_POSTї'cuisinemenu'] : addslashes($_POSTї'cuisinemenu']);
}
$cityvar_Recordset1 = "e;2"e;;
if (isset($_POSTї'cityfield'])) {
$cityvar_Recordset1 = (get_magic_quotes_gpc()) ? $_POSTї'cityfield'] : addslashes($_POSTї'cityfield']);
}
mysql_select_db($database_hungry_vt, $hungry_vt);
$query_Recordset1 = sprintf("e;SELECT *
FROM locations inner join vt_restaurants on vt_restaurants.city = locations.loc_city
WHERE cuisinea='%s' AND (loc_county='%s' OR loc_city='%s')"e;, $cuisinemenu_Recordset1,$countyvar_Recordset1,$cityvar_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $hungry_vt) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE HTML PUBLIC "e;-//W3C//DTD HTML 4.01 Transitional//EN"e; "e;http://www.w3.org/TR/html4/loose.dtd"e;>
<html>
<head>
<meta http-equiv="e;Content-Type"e; content="e;text/html; charset=iso-8859-1"e;>
<title>Untitled Document</title>
</head>
<body>
<?php
$ALL = "e;All Cuisines"e;;
if ($ALL = ($_POSTї'cuisinemenu']))
{
echo $row_Recordset1ї'restaurant'];
echo $row_Recordset1ї'cuisinea'];
echo $row_Recordset1ї'city'];
echo $row_Recordset1ї'loc_county'];
;
}
else
{
do
{
echo $row_Recordset1ї'restaurant'];
echo $row_Recordset1ї'cuisinea'];
echo $row_Recordset1ї'city'];
echo $row_Recordset1ї'loc_county'];
}
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
To be honest I couldn't see any difference, except the indentation and line breaks. I know that php can be picky about line breaks, but isn't indentation just for humans?
feyd | Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Sat Mar 12, 2005 2:50 am
by feyd
here's a big hint.. count your braces.
Posted: Sat Mar 12, 2005 2:58 am
by saltriver
sorry about forgetting the php tags
Posted: Sat Mar 12, 2005 3:14 am
by saltriver