evilboy1151987 Posted May 13, 2010 Share Posted May 13, 2010 <?php $q=$_GET["q"]; $cname=$_GET["cname"]; $con = mysql_connect('*********', '*********', '**********'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("************", $con); $sql="SELECT car_number FROM cars WHERE car_quantity = '".$q."'"; $sql2="SELECT car_number FROM cars WHERE customer_name = '".$cname."'"; $result = mysql_query($sql); $result2 = mysql_query($sql2); echo "<select name='user'>"; while($row=mysql_fetch_assoc($result2)) { echo "<option value=".$row['car_number'].">". $row['car_number']."</option>"; } echo "</select>"; echo "<select name='user2'>"; while($row=mysql_fetch_assoc($result)) { echo "<option value=".$row['car_number'].">". $row['car_number']."</option>"; } echo "</select>"; mysql_close($con); ?> this form create 2 listbox every box contain some car numbers my question is how to make only one listbox contains same value on this 2 lists . i am trying this $sql="SELECT car_number FROM cars WHERE car_quantity = '".$q."' AND customer_name = '".$cname."' "; but didn't work so i need somthing like compare or join result1 & result2 any help plz ??? Quote Link to comment https://forums.phpfreaks.com/topic/201613-need-to-join-2-array-or-2-query-and-get-only-same-values-in-new-array/ Share on other sites More sharing options...
Muddy_Funster Posted May 13, 2010 Share Posted May 13, 2010 You don't need a join when you are only using 1 table. $sql='SELECT car_number FROM cars WHERE car_quantity = '.$q.' OR customer_name = \''.$cname.'\''; $result = mysql_query($sql) or die (mysql_error()); should do just fine. Quote Link to comment https://forums.phpfreaks.com/topic/201613-need-to-join-2-array-or-2-query-and-get-only-same-values-in-new-array/#findComment-1057663 Share on other sites More sharing options...
evilboy1151987 Posted May 13, 2010 Author Share Posted May 13, 2010 You don't need a join when you are only using 1 table. $sql='SELECT car_number FROM cars WHERE car_quantity = '.$q.' OR customer_name = \''.$cname.'\''; $result = mysql_query($sql) or die (mysql_error()); should do just fine. first thing your code doesn't work and i will explain what i exactly want : my site here > http://mwlobby.0fees.net/test/movement.php plz visit have 2 files ajax.php & movement.php ajax.php <?php $q=$_GET["q"]; $cname=$_GET["cname"]; $con = mysql_connect('****', '****', '****'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("fees0_5265972_test2", $con); $sql="SELECT car_number FROM cars WHERE car_quantity = '".$q."' OR customer_name = '".$cname."' "; $result = mysql_query($sql) or die (mysql_error()); echo "<select name='user'>"; while($row=mysql_fetch_assoc($result)) { echo "<option value=".$row['car_number'].">". $row['car_number']."</option>"; } echo "</select>"; mysql_close($con); ?> ========================= movement.php <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1256" /> <title>test</title> <script type="text/javascript"> function showUser1(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } var urq = 'ajax.php?q='+str ; xmlhttp.open("GET",urq,true); xmlhttp.send(); } // ================================== function showUser2(stc) { if (stc=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } var urc = 'ajax.php?cname='+stc ; xmlhttp.open("GET",urc,true); xmlhttp.send(); } </script> </head> <body> <form> <p> customer name : <input name="cname" type="text" id="cname" onchange="showUser2(this.value)" /> write kimo</p> <p> car quantity : <input name="q" type="text" id="q" onchange="showUser1(this.value)" /> write 33 or 34</p> <p> </p> </form> <div id="txtHint"></div> </body> </html> plz go to here http://mwlobby.0fees.net/test/movement.php and you will find what i need Quote Link to comment https://forums.phpfreaks.com/topic/201613-need-to-join-2-array-or-2-query-and-get-only-same-values-in-new-array/#findComment-1057701 Share on other sites More sharing options...
Muddy_Funster Posted May 13, 2010 Share Posted May 13, 2010 add this at your second line in ajax.php (just after $q = $_GET['q'] : if (empty(trim($q))){ $append = ''; } else{ $append = ' AND car_quantity = '.$q; } and change the query to read : $sql='SELECT car_number FROM cars WHERE customer_name = \''.$cname.'\''.$append; is that more what you are looking for? Quote Link to comment https://forums.phpfreaks.com/topic/201613-need-to-join-2-array-or-2-query-and-get-only-same-values-in-new-array/#findComment-1057766 Share on other sites More sharing options...
evilboy1151987 Posted May 13, 2010 Author Share Posted May 13, 2010 sorry i make the change you said but it's doesn't work too ajax.php <?php $q=$_GET["q"]; if (empty(trim($q))){ $append = ''; } else{ $append = ' AND car_quantity = '.$q; } $cname=$_GET["cname"]; $con = mysql_connect('sql100.0fees.net:3306', 'fees0_5265972', 'kemoaly'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("fees0_5265972_test2", $con); $sql='SELECT car_number FROM cars WHERE customer_name = \''.$cname.'\''.$append; //$sql="SELECT car_number FROM cars WHERE car_quantity = '".$q."' AND customer_name = '".$cname."' //"; $result = mysql_query($sql) or die (mysql_error()); echo "<select name='user'>"; while($row=mysql_fetch_assoc($result)) { echo "<option value=".$row['car_number'].">". $row['car_number']."</option>"; } echo "</select>"; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/201613-need-to-join-2-array-or-2-query-and-get-only-same-values-in-new-array/#findComment-1057781 Share on other sites More sharing options...
Muddy_Funster Posted May 14, 2010 Share Posted May 14, 2010 seems like the if(empty... is wrong, flings up an error when I run the script on my server. change it to if(trim($q) == ''){ also at the verry top of the page add this line of code <?php error_reporting (E_ALL); //... this should help with any other errors in the php. Quote Link to comment https://forums.phpfreaks.com/topic/201613-need-to-join-2-array-or-2-query-and-get-only-same-values-in-new-array/#findComment-1058149 Share on other sites More sharing options...
evilboy1151987 Posted May 14, 2010 Author Share Posted May 14, 2010 thank you alot Muddy_Funster you really help me more than i want :D Quote Link to comment https://forums.phpfreaks.com/topic/201613-need-to-join-2-array-or-2-query-and-get-only-same-values-in-new-array/#findComment-1058195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.