phpQuestioner Posted August 19, 2007 Share Posted August 19, 2007 I have a AJAX/PHP Database Search Script, but I cannot get it to send query accurately; I keep getting the code that I have in place to be displayed when nothing is found in the database by MySQL (ie. mysql_num_rows($result) == 0). I am typing in the make of the vehicle; just as I have it in my database; so this is not a typo error. Could some take a look at it and tell me what is wrong with it? HTML & AJAX Code <html> <body> <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your Does Not Support AJAX"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.getElementById('vehicles').innerHTML = ajaxRequest.responseText; } } var age = document.getElementById('make').value; var queryString = "?make=" + make; ajaxRequest.open("GET", "ajax-search-routine.php" + queryString, true); ajaxRequest.send(null); } //--> </script> <form name="myForm"> <input type="text" id="make"> <input type="button" onclick="ajaxFunction()" value="Search"> </form> <br><br> <span id="vehicles"></span> </body> </html> PHP Code <?php print "<table width=700px class=tableContainer cellpadding=2 cellspacing=0 border=0>"; //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","username","password"); //select which database you want to edit mysql_select_db("myVecs"); //select the table $result = mysql_query("select * from vehicles where make='$make' order by year, make asc") or die("Inventory Database Connection Failed - Please Try Again Later"); if(mysql_num_rows($result) == 0){ print "<tr><td rowspan=5 style='color:red;font-family:arial;font-weight:bold;text-align:center'>Vehicle Inventory Out of Stock - Please Visit Us Again Soon - New Inventory Coming.....</td></tr>"; } else { //grab all the content while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $id=$r["id"]; $year=$r["year"]; $link=$r["link"]; $make=$r["make"]; $model=$r["model"]; $series=$r["series"]; $price=$r["price"]; $price2=number_format($price); //display the row print "<tr class=\"norm\" onmouseover=\"this.className='hover'; return true\" onmouseout=\"this.className='norm'; return true\" onclick=\"javascript:document.location='vehicle-description.php?id=$id'\" style=\"cursor:hand\"><td width=23% class=indTD><a href=\"vehicle-description.php?id=$id\" onmouseover=\"javascript:window.status='$year $make $model $series'; return true\" onmouseout=\"javascript:window.status=''; return true\">$make</a></td><td width=23% class=indTD>$model</td><td width=20% class=indTD>$series</td><td align=center width=16% class=indTD style=\"padding-left:0\">$year</td><td width=18% align=center class=vaiav><center><table width=60%><td style=\"text-align:left;width:40%\">$</td><td style=\"text-align:center;width:60%\">$price2</td></table></center></td></tr>"; } } print "</table></center>"; ?> Link to comment https://forums.phpfreaks.com/topic/65647-solved-need-help-with-my-ajaxmysql-query-search-script/ Share on other sites More sharing options...
phpQuestioner Posted August 19, 2007 Author Share Posted August 19, 2007 I found the problem, I have a JavaScript/AJAX variable named the wrong thing. This little piece of code here: I had this: var age = document.getElementById('make').value; When I should of had this: var make = document.getElementById('make').value; Link to comment https://forums.phpfreaks.com/topic/65647-solved-need-help-with-my-ajaxmysql-query-search-script/#findComment-327879 Share on other sites More sharing options...
mathix Posted September 26, 2007 Share Posted September 26, 2007 This search script is cool! Works like a charm! One thing, if i want a "pageing" to this script, how does it work, and how do i create such ? Link to comment https://forums.phpfreaks.com/topic/65647-solved-need-help-with-my-ajaxmysql-query-search-script/#findComment-356014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.