Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am creating a drop down menu of car "models" using the results from a MYSQL database based on what car "make" someone has previously selected. However as some makes have lots of differnt models and some not many I am struggling to get it so that only the fields with an actual result in are displayed.
Currently as it is below, if there is just 2 "models" of car available it displays these in the drop down menu but also 8 more empty enteries under it which is not what I want.
Can anyone help sort what I need to add as I know it shoudl be relativly simple but can't actually do it myselfCode: Select all
<?php
***database connection stuff***
$limit = 100;
$query_count = "SELECT count(*) FROM cars";
$result_count = mysql_query($query_count);
$row_count =mysql_fetch_row($result_count);
$totalrows =$row_count[0];
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM cars WHERE make='$make' LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("No articles yet! Why not be the first to submit one?!");
}
echo("<table>");
echo('<form method="post" action="">');
echo("<p>");
echo('<select name="model">');
while($row = mysql_fetch_array($result)){
if ($bgcolor == "#FFFFFF"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#FFFFFF";
}
echo("<option>Select Model</option>");
echo('<option value="' . $row["model1"] . '">' . $row["model1"] . '</option>');
echo('<option value="' . $row["model2"] . '">' . $row["model2"] . '</option>');
echo('<option value="' . $row["model3"] . '">' . $row["model3"] . '</option>');
echo('<option value="' . $row["model4"] . '">' . $row["model4"] . '</option>');
echo('<option value="' . $row["model5"] . '">' . $row["model5"] . '</option>');
echo('<option value="' . $row["model6"] . '">' . $row["model6"] . '</option>');
echo('<option value="' . $row["model7"] . '">' . $row["model7"] . '</option>');
echo('<option value="' . $row["model8"] . '">' . $row["model8"] . '</option>');
echo('<option value="' . $row["model9"] . '">' . $row["model9"] . '</option>');
echo('<option value="' . $row["model10"] . '">' . $row["model10"] . '</option>');
echo("</select>");
}
echo("</table>");
?>Wardy
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]