Jump to content

DSTR3

Members
  • Posts

    53
  • Joined

  • Last visited

Everything posted by DSTR3

  1. Thank you for your response. I am sorry, but I am new to this, so if you could explain or show me what you mean, I will be happy to do it and get back to you.,
  2. You have everything that I have. I gave you all of the code on my page. I gave you the tables. I don't know what else to give you. The problem is: I am trying to run a query that uses the selected options on a drop down multi-select. The drop down has 42 options. I do not know how many or what will be selected, but I need to run my query based on the selections made in the dropdown. I can get one option working, however: when I select more than one I get bak "No Records found". Here is the code at this point. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="Test"> <select name="p[]" size="10" style="width:170px" multiple="multiple" method="POST"> <?php error_reporting(E_ALL); include("config.php"); $sql = "SELECT tblDetails.DetailType AS type, GROUP_CONCAT(DISTINCT DetailName ORDER BY DetailName ASC SEPARATOR '|') AS DetailName FROM tblLocations INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID GROUP BY tblDetails.DetailType,tblLocations.CityID,tblLocations.AreaID,tblLocations.CuisineID HAVING (((tblLocations.CityID)='16') AND ((tblLocations.AreaID)='131') AND ((tblLocations.CuisineID)='3'))"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo "<optgroup label='{$row['type']}'>"; $DetailNames = explode('|', $row['DetailName']); foreach($DetailNames as $DetailName) { echo "<option value='".$DetailName."'>".$DetailName."</option>"; } echo "</optgroup>"; } ?> </select> <input type="submit" name="unused" value="Post Selections" /> </form> <?php include("config.php"); if (!empty($_POST)) { $selections = ($_POST['p']); foreach ($selections as $key => $value) { $selections[$key] = trim($value); if (empty($selections[$key])) unset($selections[$key]); } if (empty($selections)) die('No Selection'); $where = 'WHERE ( ' . implode(' AND ', $selections) . ' )'; //print_r($where); //var_dump($_POST) ?> <?php if(!isset($selections)) { echo("<p>You didn't select any filters!</p>\n"); } else { $nselections = count($selections); echo("<p>$nselections filter(s) selected:<br>"); for($i=0; $i < $nselections; $i++) { echo($selections[$i] . "<br/>"); } echo("</p>"); $DM = implode(',',$selections); 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"; } 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> <td>$row[Address]</td> <td>$row[Phone]</td> <td>$row[Price]</td> <td>$row[Rating]</td> </tr>\n"; } echo "</table><br />\n"; } } } echo '<pre>'; var_dump($_POST) ?> It should not be this hard to build a WHERE statement based on multiple selections from a list box! Please help. I have been searching for a solution for days now. Thank you.
  3. Really. Why do you bother? If you don't want to help, or can't just say so, or better yet don't even post. Life is so much easier when you help people....but I guess some people don't see it that way.
  4. Barand, Everything is there. The problem is with the multiple variables. Jessica here are the tables involved. tblRestaurants RestID RestName RestPage tblLocations LocationID CityID AreaID CuisineID tblLocDet LocationID DetailID tblDetails DetailID DetailType DetailName The problem is the one line as you say it is. I am aware of that and the message I am getting. I just need to know how to build the last part of the query to accomodate the variables.
  5. OK, So how does one "Make It Right?" I did switch WHERE to HAVING as read in your question. Changed it to this..... AND tblDetails.DetailName = '$DM') Still no results...
  6. Just using the animals as an example! LOL! The listbox has values like "Fireplace", "Buffet", "Waterfront", etc....In any case why am I not getting a result on my query?
  7. OK, I'm going to reduce the code just to get a better handle on this. I have a multiple select list box. I am selecting multiple items in this box and want to run my query and get the results based on the selections in the box. Such as this...if the user selects Cat, Dog and Pig. I want only the records to be returned that have Cat and Dog and Pig. Not those with Cat or Dog or Pig. Of course this is greatly simplified, I have 42 options, so this is why I need the DetailsName part of the query to be built dynamically. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="Test"> <select name="p[]" size="10" style="width:170px" multiple="multiple" method="POST"> <?php error_reporting(E_ALL); include("config.php"); $sql = "SELECT tblDetails.DetailType AS type, GROUP_CONCAT(DISTINCT DetailName ORDER BY DetailName ASC SEPARATOR '|') AS DetailName FROM tblLocations INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID GROUP BY tblDetails.DetailType,tblLocations.CityID,tblLocations.AreaID,tblLocations.CuisineID HAVING (((tblLocations.CityID)='16') AND ((tblLocations.AreaID)='131') AND ((tblLocations.CuisineID)='3'))"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo "<optgroup label='{$row['type']}'>"; $DetailNames = explode('|', $row['DetailName']); foreach($DetailNames as $DetailName) { echo "<option value='".$DetailName."'>".$DetailName."</option>"; } echo "</optgroup>"; } ?> </select> <input type="submit" name="unused" value="Post Selections" /> </form> <?php include("config.php"); if (!empty($_POST)) { $selections = ($_POST['p']); foreach ($selections as $key => $value) { $selections[$key] = trim($value); if (empty($selections[$key])) unset($selections[$key]); } if (empty($selections)) die('No Selection'); $where = 'WHERE ( ' . implode(' AND ', $selections) . ' )'; print_r($where); ?> <?php if(!isset($selections)) { echo("<p>You didn't select any filters!</p>\n"); } else { $nselections = count($selections); echo("<p>$nselections filter(s) selected:<br>"); for($i=0; $i < $nselections; $i++) { echo($selections[$i] . "<br/>"); } echo("</p>"); $DM = implode(',',$selections); if(!$rs=mysql_query("SELECT tblRestaurants.RestName, tblDetails.DetailName, tblLocations.CityID, tblLocations.AreaID, tblLocations.CuisineID, tblLocations.RestID, CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street) Address,tblRestaurants.RestPage, tblLocations.StreetNumber, tblLocations.Street, tblLocations.Phone, tblLocations.Price, tblLocations.Rating FROM tblDetails INNER JOIN tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID INNER JOIN tblLocDet ON tblLocations.LocationID = tblLocDet.LocationID ON tblDetails.DetailID = tblLocDet.DetailID WHERE tblLocations.tblCityID = '16' AND tblLocations.AreaID ='131' AND tblLocations.CuisineID = '3' AND tblDetails.DetailName = '$_POST('$selections') ORDER BY tblRestaurants.RestName;")) { 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> <td>$row[Address]</td> <td>$row[Phone]</td> <td>$row[Price]</td> <td>$row[Rating]</td> </tr>\n"; } echo "</table><br />\n"; } } } ?>
  8. I am running a query that works until I add the variable $selections. This is from a multi-select dropdown box. I am sure my syntax is off on this. I am using MySQL 5.0 Error message is "Cannot Parse Query" 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
  9. Thank you. I did that and now I am getting webpage not found. In storing these pages in the table in the mySQL database, is there a certain way this should be done? Right now its just 28_Degrees.php Is this correct? Its saying this in the address bar... http://www.menuhead.net/Steelers/=RestID
  10. The link shows in the table, but the page doesn't come up. You can see the working (used loosely) example at... http://www.menuhead....eelers/Head.php Then Select City, Boston,Back Bay,American(New) SEARCH Then click on 28 degrees. The link goes nowhere. Here is the mySQL query/php that the table is being built with. <?php include("config.php"); if(!$rs = mysql_query("SELECT tblRestaurants.RestName, tblLocations.CityID, tblLocations.AreaID, tblLocations.CuisineID,tblLocations.RestID, CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street) Address, tblLocations.Phone, tblDetails.Price, tblDetails.Rating FROM tblRestaurants INNER JOIN (tblLocations LEFT JOIN tblDetails ON tblLocations.LocationID = tblDetails.LocationID) ON tblRestaurants.RestID = tblLocations.RestID WHERE tblLocations.CityID='$Doggie' AND tblLocations.AreaID='$Kitty' AND tblLocations.CuisineID='$Pig' ORDER BY tblRestaurants.RestName ASC")) { echo "Cannot parse query"; } elseif(mysql_num_rows($rs) == 0) { echo "No records found"; } else { echo "<table id=\"myTable\" table width=\"720\" class=\"tablesorter\" 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><a href='$row[$RestPage]$RestID=RestID'>$row[RestName]</a></td> <td>$row[Address]</td> <td>$row[Phone]</td> <td>$row[Price]</td> <td>$row[Rating]</td> </tr>\n"; } echo "</table><br />\n"; } ?>
  11. I have a mySQL database. Version 5.0. I have a table that is generated dynaically, this works fine. In the table I have the following fields RestName, Address, Phone, Price, Rating This is the table where the webpage name lies for each restaurant. tblRestaurants RestID 1 RestName Red Place RestPage Red_Place.php I am storing a webpage in the RestPage field. When I click on the RestName field in the table I want the webpage stored in the RestPAge field to come up. Needless to say I need a variable because you never know which restaurant will appear in the table. I have this so far... <td><a href='$row[$RestPage]$RestID=RestID'>$row[RestName]</a></td> but it doesn't seem to be working. I'm new to this so..........I need some direction here. Thank you.
  12. Switched it from load to ready and it populated the listbox. case "Place": $(document).ready(function () { $.ajax({ url: 'place_place.php', success: function (html) { $("#Doggie").html(html); }, error: function () { } }); }); break;
  13. Solved! $(document).ready(function() { $(".Doggie").change(function() { var LocationString ='Rid='+ $(this).val(); $.ajax({ type: "POST", url: "place_city.php", data: LocationString, cache: false, success: function (html) { $(".Kitty").html(html); } }); }); $('.Kitty').live("change",function(){ var Rid = $('#Doggie').val(), // This is the value of the id="Doggie" selected option Cid = $(this).val(); // This is the value of the id="Kitty" selected option //alert("Rid = " + Rid + " Cid = " + Cid); $.ajax({ type: "POST", url: "place_area.php", data: {"Rid":Rid,"Cid":Cid}, cache: false, success: function (html) { //alert('This is what is returned from the php script: ' + html); $(".Pig").html(html); } }); }); });
  14. I'm trying to load a listbox named Doggie with this script. It's in the header of my webpage. Can anyone see what I am doing wrong? Thank you. switch(n){ case "Place": $(".Doggie").load(function() $.ajax({ type: "POST", url: "place_place.php", cache: false, success: function (html) { $(".Doggie").html(html); } }); }); break;
  15. Do you mean like this? var LocationString = 'Lid='+ $(this1).val(); var CityString = 'Cid='+ $(this2).val(); or this? ] var LocationString = 'Lid='+ $(this).val(); var CityString = 'Cid='+ $(this).va2l(); ]
  16. It really doesn't matter what I tried, because nothing worked. How do I assign two different values? Thank you.
  17. Thank you. Yes I tried various things. All met with failure.! These are two different values. How do I do this? Your help is greatly appreciated. Thank you. I need two different values. Lid and Cid.
  18. I have code that is working. $('.Kitty').live("change",function(){ var LocationString = 'Lid='+ $(this).val(); $.ajax({ type: "POST", url: "ajax_area.php", data: LocationString, cache: false, success: function (html) { $(".Pig").html(html); However; I need two values. Lid (LocationString) and Cid (CityString) How would I do this? I tried this and it doesn't work. $('.Kitty').live("change",function(){ var LocationString = 'Lid='+ $(this).val(); var CityString = 'Cid='+ $(this).val(); $.ajax({ type: "POST", url: "ajax_area.php", data: {Lid: LocationString, Cid:CityString}, cache: false, success: function (html) { $(".Pig").html(html); And this is the ajax_area.php file. Its grabbing Lid successfully, how is Cid added to this mix? <?php require('config.php'); if($_POST['Lid']) { $Lid=$_POST['Lid']; $sql=mysql_query("SELECT tblLocations.RestID as Lid, tblAreas.AreaName as name FROM tblLocations INNER JOIN tblAreas ON tblLocations.AreaID = tblAreas.AreaID WHERE tblLocations.RestID = $Lid GROUP BY tblLocations.RestID, tblAreas.AreaName ORDER BY tblAreas.AreaName ASC"); echo '<option selected="selected">--Select Area--</option>'; while($row=mysql_fetch_array($sql)) { echo '<option value="'.$row['Lid'].'">'.$row['name'].'</option>'; } } ?> Help is appreciated! Thank you!
  19. I have a Switch case that is not loading a dropdown list. Any help in finding a solution, I would be grateful. <?php $dbc = mysql_connect('','','') or die('Error connecting to MySQL server.'); mysql_select_db('MyDB'); $list['place'] = mysql_query("select * from tblRestaurants order by RestName ASC"); $list['cuisine'] = mysql_query("select * from tblCuisines order by CuisineName ASC"); foreach($list as $key=>$value){ while ($nt = mysql_fetch_assoc($list[$key])) $list_array[$key] = $nt; } if(isset($_GET["ajax"])) { switch($_GET['case']){ case 'place': echo json_encode($list_array['place']); break; case 'cuisine': echo json_encode($list_array['cuisine']); break; } die(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function displayPlace() { $.getJSON("Saturday.php?ajax=true", function(data) { $.each(data, function(index, objRecord) { var option=document.createElement("option"); option.value=objRecord.RestID; option.text=objRecord.RestName; $("#Doggie").append('<option value="' + objRecord.RestID + '">' + objRecord.RestName + '</option>'); }); }); } function displayCuisine() { $.getJSON("Saturday.php?ajax=true", function(data) { $.each(data, function(index, objRecord) { var option=document.createElement("option"); option.value=objRecord.CuisineID; option.text=objRecord.CuisineName; $("#Doggie").append('<option value="' + objRecord.CuisineID + '">' + objRecord.CuisineName + '</option>'); }); }); } </script> <title>SEARCH</title> </head> <body> <form> <button type="button" onclick="javascript:displayPlace();">Place</button> <button type="button" onclick="javascript:displayCuisine();">Cuisine</button> <button type="button" onclick="javascript:displayCity();" >City</button> <button type="button" onclick="javascript:displayState();">State</button> <button type="button" onclick="javascript:displayZipCode();">Area</button> <br /> <select name="Doggie" id="Doggie"></select> <br /> </form> </body> </html>
  20. I have 5 buttons. When you click on one, it populates the listbox. The first one works, however I am at loss on how to get the other 4 to work. Any help is appreciated. <?php $dbc = mysql_connect('','',') or die('Error connecting to MySQL server.'); mysql_select_db('MyHead'); $place = mysql_query("select * from tblRestaurants order by RestName ASC"); $cuicine = mysql_query("select * from tblCuisines order by CuisineName ASC"); $city = mysql_query("select * from tblCities order by CityName ASC"); $state = mysql_query("select * from tblStates order by StateName ASC"); $zipcode = mysql_query("select * from tblLocations order by ZipCodeName ASC"); while ($nt= mysql_fetch_assoc($place)) $arrData[] = $nt; if(isset($_GET["ajax"])) { echo json_encode($arrData); //die(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function displayPlace() { $.getJSON("index.php?ajax=true", function(data) { $.each(data, function(index, objRecord) { var option=document.createElement("option"); option.value=objRecord.RestID; option.text=objRecord.RestName; $("#Doggie").append('<option value="' + objRecord.RestID + '">' + objRecord.RestName + '</option>'); }); }); } function displayCuisine() { $.getJSON("index.php?ajax=true", function(data) { $.each(data, function(index, objRecord) { var option=document.createElement("option"); option.value=objRecord.CuisineID; option.text=objRecord.CuisineName; $("#Doggie").append('<option value="' + objRecord.CuisineID + '">' + objRecord.CuisineName + '</option>'); }); }); } </script> <title>SEARCH</title> </head> <body> <form> <button type="button" onclick="javascript:displayPlace();">Place</button> <button type="button" onclick="javascript:displayCuisine();">Cuisine</button> <button type="button" onclick="javascript:displayCity();">City</button> <button type="button" onclick="javascript:displayState();">State</button> <button type="button" onclick="javascript:displayZipCode();">Area</button> <br /> <select name="Doggie" id="Doggie"></select> <br /> </form> </body> </html>
  21. Thank you for your reply. But how do I stop my listbox from loading, and how do I add the button? I am new to all of this, so your help by example would be greatly appreciated! Thank you, once again. Also I greatly reduced the code to make this whole thing clearer. <?php $dbc = mysql_connect('', '',') or die('Error connecting to MySQL server.'); mysql_select_db(''); $result = mysql_query("select * from tblRestaurants order by RestName ASC"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MENUHEAD</title> </head> <body> <p><center>SEARCH</CENTER></P> <select name="RestName"> <?php while ($nt= mysql_fetch_assoc($result)) { echo '<option value="' . $nt['RestID'] . '">' . $nt['RestName'] . '</option>'; } ?> </select> <p>Click "SUBMIT" to display the calculation results</p> <input type="submit" name="Submit" value="Submit" /> <br /> </form> </body> </html>
  22. I have a button. When I click on the button I want to populate a listbox in AS order. (I would like the listbox to start out blank. Then when the button is clicked, the listbox populates. I have this so far, but when I open the page the box is already populated and the order is far from ASC. Any help s appreciated. Thank you. <?php try { $objDb = new PDO('mysql:host="";dbname=""', '', [email="'@1973'"]'[/email]); $objDb->exec('SET CHARACTER SET utf8'); $sql = "SELECT * FROM `tblRestaurants` WHERE `RestStatus` = 'YES' ORDER BY 'RestName' ASC"; $statement = $objDb->query($sql); $list = $statement->fetchAll(PDO::FETCH_ASSOC); } catch(PDOException $e) { echo 'There was a problem'; } ?> <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="utf-8" /> <title>First Box</title> <meta name="description" content="First Box" /> <meta name="keywords" content="First Box" /> <link href="/BigStuff/css/core.css" rel="stylesheet" type="text/css" /> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div id="wrapper"> <div align="center"> <form name="form1" method="post" action=""> <div align="left">First Box <input type="submit" name="First Box" id="First Box" value="Submit"> <select name="Place" size="25" id='Place' class="update"> <option value="">Select one</option> <?php if (!empty($list)) { ?> <?php foreach($list as $row) { ?> <option value="<?php echo $row['RestID']; ?>"> <?php echo $row['RestName']; ?> </option> <?php } ?> <?php } ?> </select> </div> <script src="/BigStuff/js/jquery-1.6.4.min.js" type="text/javascript"></script> <script src="/BigStuff/js/core.js" type="text/javascript"></script> </body> </html>
  23. After giving it much thought, the problem is that all of the examples that I am finding either use one table or no tables. My first box has one table. tblRestaurants. The second box has two tables tblLocations and tblCities, joined at the CityID field. The third listbox has once again tblLocations and tblAreas, joined on the AreaID field. I hope this clarifies things a bit!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.