php - SQL query returning only 1 row -
i working on php project users can select make , model of car form , trigger search products apply particular combination. when run query in sql, , there multiple products, multiple rows. when try display results using php 1 row. have idea doing wrong? here's code:
$query1 = "select * partmakes make = '$_post[make]' , model ='$_post[model]'"; $results1 = mysqli_query($cnx, $query1); $row1 = mysqli_fetch_assoc($results1); $query2 = "select * `products` `partno`= '$row1[partmake1]' or (`partno`= '$row1[partmake2]' or `partno`= '$row1[partmake3]' or `partno`= '$row1[partmake4]');"; $results2 = mysqli_query($cnx, $query2); echo "these products car:<br />"; while ($row2 = mysqli_fetch_assoc($results2)){ extract($row2); echo "$row2[partno]<br />"; }
thanks lot help
edit - content op's file http://standtek.com.mx/test/screenshots.docx in comments
so user select drop down make , model of car. first query looks make , model in table:
then use information partmake columns reference second query
here’s example of query in phpmyadmin , shows 4 rows:
my current script displays 1 row reason:
this want displayed in results:
use join
query , return rows -
$query = "select products.* products join partmakes on ( products.partno = partmakes.partmake1 or products.partno = partmakes.partmake2 or products.partno = partmakes.partmake3 or products.partno = partmakes.partmake4) partmakes.make = '$_post[make]' , partmakes.model ='$_post[model]'"; $results = mysqli_query($cnx, $query); echo "these products car:<br />"; echo "<table><tr><th>partno</th><th>title</th><th>price</th></tr>"; while ($row = mysqli_fetch_assoc($results)){ echo "<tr><td>{$row[partno]}</td><td>{$row[title]}</td><td>{$row[price]}</td></tr>"; } echo "</table>";
make sure sanitize $_post
user data.
you can see join
query working in sqlfiddle - http://sqlfiddle.com/#!9/754feb/4
Comments
Post a Comment