0

I'm trying to populate a select box with rows from a table, but it's not showing up properly. I've looked at the source of the page, and it looks like the option html is not being outputted. Anyone spot what's wrong?

<h1>Upload Picture</h1>
    <form action="gallery.php" method="post">
    <label for="photo">Select file: </label><input type="file" name="photo" />
    <select name="photoGallery">
	<?php
    $sql="SELECT * FROM tblgallery ORDER BY galleryId";
	$result=mysql_query($sql);
	$row=mysql_fetch_array($result);
	while($row = mysql_fetch_array($result))
	{
		print '<option value="'.$row['galleryId'].'">'.$row['name'].'</option>';
    }
	?>
    </select>
    <input type="submit" value="Upload photo"/>
    </form>

Cheers,

2
Contributors
3
Replies
14
Views
7 Years
Discussion Span
Last Post by bsewell
0

Ok it seems to be "sort of" working now, not sure whether it was a cache issue.

My problem now is that the total rows in the table is 4, and the first row is being omitted.

0

Correct me if i'm wrong, but I think it might be because you're trying to print each row as an associative array when the results are returned as mysql_fetch_array.

Try this:

$row=mysql_fetch_assoc($result);
while($row = mysql_fetch_assoc($result))
0

I managed to get it working, I had another query running above that code to retrieve photos so the variables got mixed up.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.