problem with loop not reiterating with item of same name

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

Post Reply
briwal222
Forum Newbie
Posts: 10
Joined: Fri Oct 29, 2004 9:47 am

problem with loop not reiterating with item of same name

Post by briwal222 »

I have a restaurant search engine. The problem I am having is with the following code. When I use the query in mysql, it works fine. When I search for a name of a restaurant that has multiple pages, only one is returned. Can someone help me to correct this?

Code: Select all

<?php 
$sql="SELECT * 
FROM tblRestaurant r, tblRestaurantFeatures f, tblCuisine c, tblType t
WHERE r.restID = f.restID && restName = '$_POST&#1111;restName]' && f.primaryCuisine = c.cuisineID && f.primaryType = t.typeID order by restName";

$result=mysql_query($sql,$conn)or die(mysql_error());
$num=mysql_num_rows($result);
if ($num<1)&#123;
print"We have no records of a restaurant named $_POST&#1111;restName].<br>
Perhaps you would like to search by First Letter Of the Restaurant:
<form name="alpha" method="post" action="results_page.php">  
<select name="alpha">
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
    <option value="D">D</option>
    <option value="E">E</option>
	<option value="F">F</option>
    <option value="G">G</option>
    <option value="H">H</option>
    <option value="I">I</option>
    <option value="J">J</option>
	<option value="K">K</option>
    <option value="L">L</option>
    <option value="M">M</option>
    <option value="N">N</option>
    <option value="O">O</option>
	<option value="P">P</option>
    <option value="Q">Q</option>
    <option value="R">R</option>
    <option value="S">S</option>
    <option value="T">T</option>
	<option value="U">U</option>
    <option value="V">V</option>
    <option value="W">W</option>
    <option value="X">X</option>
    <option value="Y">Y</option>
	<option value="Z">Z</option>
    </select>
	<input type="hidden" name="searchValue" value="searchAlph">
	<input type="submit" name="submit" value="Search By Letter">
	</form>
";&#125; 

else if($num>=1)
    &#123; 
   $row=mysql_fetch_array($result); 
$restID=$row&#1111;'restID'];
$restName=$row&#1111;'restName'];
$restAddress=$row&#1111;'restAddress'];
$restCity=$row&#1111;'restCity'];
$restState=$row&#1111;'restState'];
$restZip=$row&#1111;'restZip'];
$restPhone=$row&#1111;'restPhone'];
$restFax=$row&#1111;'restFax'];
$restURL=$row&#1111;'restURL'];
$restDescription=$row&#1111;'restDescription'];
$deliveryRadius=$row&#1111;'deliveryRadius'];
$deliveryTimeBegin=$row&#1111;'deliveryTimeBegin'];
$deliveryTimeEnd=$row&#1111;'deliveryTimeEnd'];
if ($deliveryTimeBegin!="") &#123;
$delivery="Delivery:$deliveryTimeBegin - $deliveryTimeEnd";&#125;
else &#123;$delivery="";&#125;
$primaryCuisine=$row&#1111;'primaryCuisine'];
$primaryType=$row&#1111;'primaryType'];
$cuisineName=$row&#1111;'cuisineName'];
$typeName=$row&#1111;'typeName'];
if ($restURL!="")&#123;
$link="<a href="$restWeb"><img src="/images/button_website.jpg" width="60" height="19" border="0"></a>";
&#125; else &#123; $link="";&#125;
if ($restFax!="") &#123;
$fax="F: <em>$restFax</em>";
$menulink=urlencode("$restID"); 
          
&#125; else &#123; $fax="";&#125;
print "<table width="460" border="0" cellpadding="0" cellspacing="0">
  <tr bgcolor="ffffff">
    <td colspan="2" height="20"><div align="left"><span class="style2">
	<a name="$restName"></a><b>$restName</b></span></div></td>
	<td height="20" width="140" valign="top"><A HREF="menu_page.php?restID=$restID">See menu</A></td>
  </tr>
  <tr>
    <td width="165" height="15" valign="top"><span class="style2">$restAddress</span></td>
    <td width="155" valign="top"><span class="style2">P:$restPhone</span></td>
    <td width="140" rowspan="4" valign="top"></td>
  </tr>
  <tr>
    <td width="165" height="15"><span class="style2">$restCity $restState $restZip</span></td>
	<td width="155" height="15"><span class="style2">$fax</span></td>
  </tr>
  <tr>
    <td width="165" height="15"><span class="style2">$typeName</span></td>
    <td width="155" height="15" valign="top"><span class="style2">$cuisineName Cuisine</span></td>
  </tr>
  <tr>
    <td width="165" height="15"><span class="style2">$delivery</span></td>
    <td width="155" height="15"valign="top"></td>
    </tr>
	<tr><td height="15" colspan="3" valign="top"><span class="style2">$restHours</span></td></tr>
  
</table>";
?>
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

you only have a

Code: Select all

row = mysql_fetch_array($result);

that will only get the first row from your query results .... you need to have a

Code: Select all

while($row = mysql_fetch_array($result)){...

or other type of loop if you want all the rows.
briwal222
Forum Newbie
Posts: 10
Joined: Fri Oct 29, 2004 9:47 am

Post by briwal222 »

thank you. You know how it is when you keep looking at your own code over and over again!! Works now!!
Post Reply