ALL cuisines, as opposed to Italian

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

ALL cuisines, as opposed to Italian

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

I too am lazy

Post 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
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

unexpected T_ENCAPSED_AND_WHITESPACE

Post 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">&nbsp;</td>
              <td width="150"><div align="right"></div></td>
            </tr>
                </table>
				
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
        <p>&nbsp;</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,

Code: Select all

works. [/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

lines 4-7 need semicolons, and you don't need the double quotes.
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post 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&#1111;'cuisinemenu'])
Steve
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I never said anything about losing parens..
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post 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">&nbsp;</td>
      <td width="600">&nbsp;</td>
      <td width="150">&nbsp;</td>
    </tr>
  </table>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($Recordset1);
?>

feyd | Please use

Code: Select all

and

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]
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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 ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

additionally, it appears there's a = vs == issue..
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post 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

&lt;?php require_once('../../../Connections/hungry_vt.php'); ?&gt;
&lt;?php

$countyvar_Recordset1 = &quote;1&quote;;
if (isset($_POST&#1111;'countymenu'])) {
  $countyvar_Recordset1 = (get_magic_quotes_gpc()) ? $_POST&#1111;'countymenu'] : addslashes($_POST&#1111;'countymenu']);
}
$cuisinemenu_Recordset1 = &quote;-1&quote;;
if (isset($_POST&#1111;'cuisinemenu'])) {
  $cuisinemenu_Recordset1 = (get_magic_quotes_gpc()) ? $_POST&#1111;'cuisinemenu'] : addslashes($_POST&#1111;'cuisinemenu']);
}
$cityvar_Recordset1 = &quote;2&quote;;
if (isset($_POST&#1111;'cityfield'])) {
  $cityvar_Recordset1 = (get_magic_quotes_gpc()) ? $_POST&#1111;'cityfield'] : addslashes($_POST&#1111;'cityfield']);
}
mysql_select_db($database_hungry_vt, $hungry_vt);
$query_Recordset1 = sprintf(&quote;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')&quote;, $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);
?&gt;
&lt;!DOCTYPE HTML PUBLIC &quote;-//W3C//DTD HTML 4.01 Transitional//EN&quote; &quote;http://www.w3.org/TR/html4/loose.dtd&quote;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quote;Content-Type&quote; content=&quote;text/html; charset=iso-8859-1&quote;&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;?php
	$ALL = &quote;All Cuisines&quote;;
		if ($ALL = ($_POST&#1111;'cuisinemenu']))
		{
		   echo $row_Recordset1&#1111;'restaurant'];
		   echo $row_Recordset1&#1111;'cuisinea'];   
		   echo $row_Recordset1&#1111;'city'];   
		   echo $row_Recordset1&#1111;'loc_county'];  
		     ;
			 }
			 else 
			 { 
			   do   
			   { 
			        echo $row_Recordset1&#1111;'restaurant'];
					echo $row_Recordset1&#1111;'cuisinea'];      
					echo $row_Recordset1&#1111;'city'];      
					echo $row_Recordset1&#1111;'loc_county'];   
				}   
				while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
				?&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
mysql_free_result($Recordset1);
?&gt;
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

and

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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

here's a big hint.. count your braces.
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post by saltriver »

sorry about forgetting the php tags
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post by saltriver »

Code: Select all

}
{/php]

Doh!

Thanks feyd
Post Reply