Andrew Wilson Andrew Wilson - 1 month ago 6
MySQL Question

PHP and MySQL only returning first row

I have the code shown below to display deals from a database, although it is only showing the first row. The getDeals function simply just says:

return mysql_query("SELECT * FROM `deals`");


Here's the code that displays it to a select. My assumption is that the issue is more of an HTML error since when I var_dump the results array it looks like it's gathering the right data and I have used that same while loop before, but I am quite beginner and probably just skipped over something stupid by accident.

<select name="deal">
<option>No deal</option
<?php
$array = getDeals();

while($arrays = mysql_fetch_array($array, MYSQL_ASSOC)){
echo "<option>" . $arrays["name"] . "</option>";
}
?>
<option <?php if($dd != ""){ echo "selected"; } ?>><?php echo $dd; ?></option>
</select><br>


Any help would be appreciated. Thank you.

Answer
<select name="deal">
<option>No deal</option>
<?php
$array = getDeals();

while($arrays = mysql_fetch_array($array, MYSQL_ASSOC)){
echo "<option>" . $arrays["name"] . "</option>";
}
?>
<option <?php if($dd != ""){ echo "selected"; } ?><?php echo $dd; ?></option>
</select><br>

Check this.