Jump to content


Photo

Cannot Parse Query

mysql php

  • This topic is locked This topic is locked
27 replies to this topic

#21 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,731 posts
  • LocationBonita, FL

Posted 09 February 2013 - 06:13 PM

Change this:
        if(!$rs=mysql_query("SELECT
tblRestaurants.RestName,
tblLocations.CityID,
tblLocations.AreaID,
tblLocations.CuisineID,
tblLocations.RestID,
tblRestaurants.RestPage,
CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street) AS Address,
tblLocations.Phone,
tblLocations.Price,
tblLocations.Rating,
tblDetails.DetailName
FROM
tblRestaurants
INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
INNER JOIN tblLocDet ON tblLocations.LocationID = tblLocDet.LocationID
INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID
WHERE tblLocations.CityID='16'
AND tblLocations.AreaID='131'
AND tblLocations.CuisineID='3'
AND tblDetails.DetailName='$DM'
ORDER BY tblRestaurants.RestName ASC
"))
{
echo "Cannot parse query";
}

To this:
$sql = "SELECT
tblRestaurants.RestName,
tblLocations.CityID,
tblLocations.AreaID,
tblLocations.CuisineID,
tblLocations.RestID,
tblRestaurants.RestPage,
CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street) AS Address,
tblLocations.Phone,
tblLocations.Price,
tblLocations.Rating,
tblDetails.DetailName
FROM
tblRestaurants
INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
INNER JOIN tblLocDet ON tblLocations.LocationID = tblLocDet.LocationID
INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID
WHERE tblLocations.CityID='16'
AND tblLocations.AreaID='131'
AND tblLocations.CuisineID='3'
AND tblDetails.DetailName='$DM'
ORDER BY tblRestaurants.RestName ASC
";
if(!$rs=mysql_query($sql))
{
echo "Cannot parse query.  <p>The error is: ".mysql_error()."</p><p>The query is:<br><pre>{$sql}</pre></p>";
}

Then post back with what it says the error is along with the query text it shows.


Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#22 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,614 posts
  • LocationCheshire, UK

Posted 09 February 2013 - 06:23 PM

All you had to do was

echo "
SELECT tblLocations.CityID, tblDetails.DetailName, tblRestaurants.RestName,
CONCAT(tblLocations.StreetNumber,' ',tblLocations.Street) Address, tblLocations.Phone, tblLocations.Price, tblLocations.Rating, tblRestaurants.RestPage
FROM (tblRestaurants
INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID)
INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID GROUP BY tblLocations.CityID, tblLocations.AreaID, tblLocations.CuisineID, tblDetails.DetailName, tblRestaurants.RestName, tblLocations.Street, tblLocations.Phone, tblLocations.Price, tblLocations.Rating
HAVING tblLocations.CityID='16' AND tblLocations.AreaID='131' AND tblLocations.CuisineID='3'
AND tblDetails.DetailName='( ' . implode(' AND ', $selections) . ' )'
ORDER BY tblRestaurants.RestName ASC";

so the actual query can be seen. Not too much to ask , was it?

Edited by Barand, 09 February 2013 - 06:24 PM.

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#23 DSTR3

DSTR3

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts

Posted 09 February 2013 - 07:11 PM

Barand, Not to much to ask at all, but if one does not know, because one is new, then, well you understand, kicken and Barand. I found the problem. It's this. I am running a condition on a table that can only possibly give me one answer. tblDetails. I have to run it from the tblLocDet that contains all of the records of the details as well as the locations. I am testing it now and will return. Thank you both for your help.

#24 DSTR3

DSTR3

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts

Posted 09 February 2013 - 07:33 PM

OK, Closer but no cigar! I am getting all the options that are being asked for except. It's coming out as an OR not an AND.
Check out this link...
http://www.menuhead....ers/2Expert.php

If I put "Fireplace" and Private Room(s) I should get only the places that have both. And the answer is three, But I am getting five results because it's giving me all of the places that have a "Fireplace" AND/OR Private Room(s).

Here is the current code.

<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
.tblHead {
background-color: #002DD1;
color: white;
text-align: left;
}
</style>
</head>
<body>
<p>
  <?php
if (isset ( $_POST ["btnSearch"] )) {
echo "<br>Selected Options are :<br>";
$checked = $_POST ["criteria"];

$criteria = "";
$separator = ", ";
for($i = 0; $i < count ( $checked ); $i ++) {
  echo " " . $checked [$i] . "<br/>";
 
  if ($i == count ( $checked ) - 1) {
   $separator = "";
  }
 
  $criteria = $criteria . "'" . $checked [$i] . "'" . $separator;
}
echo "<br><br>";

echo $criteria . "<br><br>";
include "config.php";

mysql_select_db ( "MyHead", $con );
//$DM = implode(',',$criteria);
$mysqlQuery = "SELECT tblRestaurants.RestName, tblLocDet.LocationID, tblLocDet.DetailID, tblDetails.DetailName, tblRestaurants.RestName
FROM tblRestaurants INNER JOIN (tblLocations INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID) ON tblRestaurants.RestID = tblLocations.RestID
GROUP BY tblRestaurants.RestName, tblLocDet.LocationID, tblLocDet.DetailID, tblDetails.DetailName
HAVING tblDetails.DetailName IN (" . $criteria . ");";

if (! $rs = mysql_query ( $mysqlQuery )) {
  echo "Cannot parse query";
} elseif (mysql_num_rows ( $rs ) == 0) {
  echo "No records found";
} else {
  echo "<table id=\"myTable\" table width=\"710\" class=\"beautifuldata\" align=\"Left\" cellspacing=\"0\">\n";
  echo "<thead>\n<tr>";
  echo "<th>PLACE</th>";
  echo "<th>ADDRESS</th>";
  echo "<th>PHONE</th>";
  echo "<th>PRICE</th>";
  echo "<th>RATING</th>";
  echo "</tr>\n</thead>\n";
  while ( $row = mysql_fetch_array ( $rs ) ) {
   echo "<tr><td><strong><a href='" . $row [RestPage] . "'>" . $row ['RestName'] . "</a></strong></td>";
   echo "<td>" . $row ['DetailName'] . "</td>";
   echo "<td>" . $row ['Phone'] . "</td>";
   echo "<td>" . $row ['Price'] . "</td>";
   echo "<td>" . $row ['Rating'] . "</td>";
   echo "</tr>";
  }
}
echo "</table><br />\n";

mysql_close ( $con );
}
?>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; </p>
<form method="post" name="Critters" id="Critters">
  <div align="left">
<table width="950" border="0" cellspacing="0" cellpadding="0">
<tbody>
  <tr>
   <th class="tblHead" width="11" scope="col">&nbsp;</th>
   <th class="tblHead" width="19" scope="col">&nbsp;</th>
   <th class="tblHead" width="195" scope="col">FEATURES</th>
   <th class="tblHead" width="206" scope="col">MEAL PERIODS</th>
   <th class="tblHead" width="215" scope="col">SERVICES</th>
   <th class="tblHead" width="268" scope="col">TYPE OF PLACE</th>
   <th class="tblHead" width="51" scope="col">&nbsp;</th>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Buffet"
    value="Buffet"> <label for="Buffet"> Buffet</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Breakfast"
    value="Breakfast"> <label for="Breakfast"> Breakfast</label> </strong>
   </td>
   <td><strong> <input name="criteria[]" type="checkbox" id="BYOB"
    value="BYOB"> <label for="BYOB"> BYOB</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Bar Scene"
    value="Bar Scene"> <label for="Bar Scene"> Bar Scene</label> </strong>
   </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Fireplace"
    value="Fireplace"> <label for="Fireplace"> Fireplace</label> </strong>
   </td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Brunch"
    value="Brunch"> <label for="Brunch"> Brunch</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Catering"
    value="Cateringt"> <label for="Catering"> Catering</label> </strong>
   </td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Business Dining" value="Business Dining"> <label
    for="Business Dining"> Business Dining</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Great Views" value="Great Views"> <label for="Great Views">
   Great Views</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Dinner"
    value="Dinner"> <label for="Dinner"> Dinner</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Credit Cards" value="Credit Cards"> <label for="Credit Cards">
   Credit Cards</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Cheap Eats"
    value="Cheap Eats"> <label for="Cheap Eats"> Cheap Eats</label> </strong>
   </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Outdoor Dining" value="Outdoor Dining"> <label
    for="Outdoor Dining"> Outdoor Dining</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Happy Hour"
    value="Happy Hour"> <label for="Happy Hour"> Happy Hour</label> </strong>
   </td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Delivery"
    value="Delivery"> <label for="Delivery"> Delivery</label> </strong>
   </td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Diner"
    value="Diner"> <label for="Diner"> Diner</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Private Room(s)" value="Private Room(s)"> <label
    for="Private Room(s)"> Private Room(s)</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Late Night"
    value="Late Night"> <label for="Late Night"> Late Night</label> </strong>
   </td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Food Truck / Cart" value="Food Truck / Cart"> <label
    for="Food Truck / Cart"> Food Truck / Cart</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Gastro-Pub"
    value="Gastro-Pub"> <label for="Gastro-Pub"> Gastro-Pub</label> </strong>
   </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Raw Bar"
    value="Raw Bar"> <label for="Raw Bar"> Raw Bar</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Lunch"
    value="Lunch"> <label for="Lunch"> Lunch</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="On-Line Ordering" value="On-Line Ordering"> <label
    for="On-line Ordering"> On-Line Ordering</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Group Dining" value="Group Dining"> <label for="Group Dining">
   Group Dining</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Waterfront"
    value="Waterfront"> <label for="Waterfront"> Waterfront</label> </strong>
   </td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Open 24 Hours" value="Open 24 Hours"> <label for="Open 24 Hours">
   Open 24 Hours</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="On-Line Reservations" value="On-Line Reservations"> <label
    for="On-line Reservations"> On-line Reservations</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Hotel Dining" value="Hotel Dining"> <label for="Hotel Dining">
   Hotel Dining</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Wheelchair Access" value="Wheelchair Access"> <label
    for="Wheelchair Access"> Wheelchair Access</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Pre / Post Theatre" value="Pre / Post Theatre"> <label
    for="Pre / Post Theatre"> Pre / Post Theatre</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Reservations" value="Reservations"> <label for="Reservations">
   Reservations</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Kid Friendly" value="Kid Friendly"> <label for="Kid Friendly">
   Kid Friendly</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Wi-Fi"
    value="Wi-Fi"> <label for="Wi-Fi"> Wi-Fi</label> </strong></td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Take-Out"
    value="Take-Out"> <label for="Take-Out"> Take-Out</label> </strong>
   </td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Live Entertainment" value="Live Entertainment"> <label
    for="Live Entertainment"> Live Entertainment</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Text Ordering" value="Text Ordering"> <label for="Text Ordering">
   Text Ordering</label> </strong></td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="People Watching" value="People Watching"> <label
    for="People Watching"> People Watching</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Romantic"
    value="Romantic"> <label for="Romantic"> Romantic</label> </strong>
   </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Specials"
    value="Specials"> <label for="Specials"> Specials</label> </strong>
   </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Sports Bar"
    value="Sports Bar"> <label for="Sports Bar"> Sports Bar</label> </strong>
   </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox"
    id="Tasting Menu" value="Tasting Menu"> <label for="Tasting Menu">
   Tasting Menu</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Theme"
    value="Theme"> <label for="Theme"> Theme</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td><strong> <input name="criteria[]" type="checkbox" id="Trendy"
    value="Trendy"> <label for="Trendy"> Trendy</label> </strong></td>
   <td>&nbsp;</td>
  </tr>
</tbody>
</table>
</div>
<p><input type="submit" name="btnSearch" id="btnSearch"
value="		  SEARCH		  "></p>
</form>
</body>
</html>


#25 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 09 February 2013 - 07:53 PM

So you need to do it the same way I did in my thread. That's why I linked it. You need to structure your query the same way, because it's the only way to do that. 
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#26 fenway

fenway

    MySQL Si-Fu / PHP Resident Alien

  • Moderators
  • 16,195 posts
  • LocationToronto, ON

Posted 12 February 2013 - 03:16 PM

If you post your entire code one more time, I'm going to lock this thread for good -- just post the relevant code snippet, nothing more. If you feel the urge to include the entire script, use an attachment.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#27 DSTR3

DSTR3

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts

Posted 12 February 2013 - 03:55 PM

fenway. Here is the solution I came up with. First I take all of te records that meet the criteria and insert them into them into a temp table. Then I do a count of how many times the LcationID appears and compare that against the number options that were selected. Then I run the query with those that equal the number of selected options. See what you think.

<form method="post" name="Critters" id="Critters">
    <p align="center">
   <select name>
	  </select>
	    <select name>
	  </select>
	    <select>
	  </select>
  </p>
    <p align="center">
	 
	 
	 
	  <select name="criteria[]" multiple="multiple">
	    <?php
    include("config.php");
    ///////With Numbers/////
    //$sql = "SELECT DISTINCT DetailType AS type, DetailID, DetailName FROM tblDetails
    //ORDER BY DetailType, DetailName";
    //		 $result = mysql_query($sql) or die(mysql_error());
    //   $prev='';
    //   while ($row = mysql_fetch_assoc($result)) {
    //   if ($prev != $row['type']) {
    //    if ($prev) echo "</optgroup>";
    //    echo "<optgroup label='{$row['type']}'>";
    //    $prev = $row['type'];
    //    }
    //    echo "<option value='".$row['DetailID']."'>".$row['DetailName']."</option>";		   //    }
    //    echo "</optgroup>";
    //Without Numbers/////
    //This builds the dropdown based on City, Area, and Cuisiner for the results_city.php file
    $sql = "SELECT DetailType AS type, DetailID, GROUP_CONCAT(DISTINCT DetailName
    ORDER BY DetailName ASC 
    SEPARATOR '|') AS DetailName FROM tblDetails GROUP BY DetailType";
    $result = mysql_query($sql) or die(mysql_error()); 
    while ($row = mysql_fetch_assoc($result)){
	   {
	 var_dump($row);
    }
    echo "<optgroup label='{$row['type']}'>";
	   $DetailNames = explode('|', $row['DetailName']);
    foreach($DetailNames as $DetailName)
    {
		 echo "<option value='".$DetailName."'>".$DetailName."</option>";
    }
	   echo "</optgroup>";
    } 
    ?>
	  </select>
    </p>
  <p align="center"><input type="submit" name="btnSearch" id="btnSearch"
   value="		  SEARCH		  "></p>
  </form>

  <p>
    <?php
  //This is for the button///////////////////////////////////
  if (isset ( $_POST ["btnSearch"] )) {
  echo "<br>Selected Options are :<br>";
  $checked = $_POST ["criteria"];

  $criteria = "";
  $separator = ", ";
  for($i = 0; $i < count ( $checked ); $i ++) {
  echo " " . $checked [$i] . "<br/>";
 
  if ($i == count ( $checked ) - 1) {
   $separator = "";
  }
  $criteria = $criteria . "'" . $checked [$i] . "'" . $separator;
  }
  //This gives a count of the number of options that have been selected////////////////////////
  $nchecked = count($checked);
  echo("<p>$nchecked filter(s) HEROselected:<br>");
  for($i=0; $i < $nchecked; $i++)
  {
  echo($checked[$i] . "<br/>");
  }
  echo("</p>");
  //END COUNT////////////////////////////////////
  echo "<br><br>";
  echo $criteria . "<br><br>";
  include "config.php"; 
  $mysqlQuery = "INSERT into tblTemp (LocationID,DetailID,DetailName)
	 SELECT tblLocDet.LocationID, tblLocDet.DetailID, tblDetails.DetailName
	 FROM tblLocDet
	 INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID
	 WHERE tblDetails.DetailName IN (" . $criteria . ");";
	 mysql_query($mysqlQuery);
	
 
  $mysqlQuery2 = "SELECT tblTemp.LocationID, tblRestaurants.RestName,
   CONCAT(tblLocations.StreetNumber,'  ', tblLocations.Street) AS Address, tblLocations.Phone, 
   tblLocations.Price, tblLocations.Rating
   FROM (tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID)
   INNER JOIN tblTemp ON tblLocations.LocationID = tblTemp.LocationID
   GROUP BY tblTemp.LocationID
   HAVING Count(tblTemp.LocationID) = '$nchecked'
   ORDER BY tblRestaurants.RestName";
  //$mysqlQuery2 = ("SELECT tblTemp.LocationID, Count(tblTemp.LocationID) AS CountOfLocationID
  //  FROM tblTemp
  //   GROUP BY tblTemp.LocationID
  //   HAVING Count(tblTemp.LocationID) = '$nchecked'");
	 mysql_query($mysqlQuery2);  
   
  if (! $rs = mysql_query ( $mysqlQuery2 )) {
   echo "Cannot parse query";
   } elseif (mysql_num_rows ( $rs ) == 0) {
    echo "No records found";
	 } else {
	 echo (mysql_error());
	  echo "<table id=\"myTable\" table width=\"710\" class=\"beautifuldata\" align=\"Left\"
	  cellspacing=\"0\">\n";
	  echo "<thead>\n<tr>";
	  echo "<th>PLACE</th>";
	  echo "<th>ADDRESS</th>";
	  echo "<th>PHONE</th>";
	  echo "<th>PRICE</th>";
	  echo "<th>RATING</th>";
	  echo "</tr>\n</thead>\n";
	  while ( $row = mysql_fetch_array ( $rs ) ) {
	  echo"<tr>
	  <td><strong><a href='$row[RestPage]'>$row[RestName]</a></strong></td>
	  <td>$row[Address]</td>
	  <td>$row[Phone]</td>
	  <td>$row[Price]</td>
	  <td>$row[Rating]</td>
	  </tr>\n";
	  }
	  echo "</table><br />\n";
	  }
   $mysqlQuery3 = "DELETE FROM tblTemp";
   mysql_query($mysqlQuery3);
   mysql_close ();
   }
  ?>
  </p>
</body>


#28 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,614 posts
  • LocationCheshire, UK

Posted 12 February 2013 - 04:13 PM

//This builds the dropdown based on City, Area, and Cuisiner for the results_city.php file
$sql = "SELECT DetailType AS type, DetailID, GROUP_CONCAT(DISTINCT DetailName
ORDER BY DetailName ASC
SEPARATOR '|') AS DetailName FROM tblDetails GROUP BY DetailType";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)){
{
var_dump($row);
}
echo "<optgroup label='{$row['type']}'>";
$DetailNames = explode('|', $row['DetailName']);
foreach($DetailNames as $DetailName)
{
echo "<option value='".$DetailName."'>".$DetailName."</option>";
}
echo "</optgroup>";
}
?>
</select>

You posted that bit of code in the forum as it did not work correctly (no detail id in the options). I gave you an improved version. Now that one is back in there.

Why do I get the distinct feeling that our time is being wasted?

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com