I am working on a php project where users can select a make and model of a car from a form and this will trigger the search for products that apply for that particular combination. When I run the query in SQL, and there are multiple products, I get multiple rows. but when I try to display those results using PHP I only get 1 row. Do you have an idea what I am doing wrong? here's the code:
$query1 = "SELECT * FROM partmakes WHERE MAKE = '$_POST[make]' and MODEL ='$_POST[model]'";
$results1 = mysqli_query($cnx, $query1);
$row1 = mysqli_fetch_assoc($results1);
$query2 = "SELECT * FROM `products` WHERE `PARTNO`= '$row1[PARTMAKE1]' OR (`PARTNO`=
'$row1[PARTMAKE2]' OR `PARTNO`= '$row1[PARTMAKE3]' OR `PARTNO`= '$row1[PARTMAKE4]');";
$results2 = mysqli_query($cnx, $query2);
echo "These are the products for your car:<br />";
while ($row2 = mysqli_fetch_assoc($results2)){
extract($row2);
echo "$row2[PARTNO]<br />";
}
Thanks a lot for your help
edit - content from OP's file http://standtek.com.mx/test/screenshots.docx in the comments
So the user will select from a drop down the make and the model of the car. The first query looks for the make and model in the table:
Then I use the information from the PARTMAKE columns as reference for the second query
Here’s an example of the query in phpmyadmin and it shows 4 rows:
My current script displays only 1 row for some reason:
This is what I want displayed in the results: