Hello all,
I am relatively new to PHP so please bear with me. I have a site that I am rewriting from Coldfusion to PHP because I like PHP better and I am tired of using ColdFusion. Anyway, everything is going well except for this stupid select list that is not populating. Here is my code below:
First, I query a table that joins two other tables together. If there is a result (there will be ONLY one result if there is), then I do this:
$q2 = "SELECT resort_id, gift_id FROM resort_gift WHERE gift_id = $id";
$r2 = @mysqli_query($dbc, $q2);
If there is a result of one record (again, there will be either one or no records as this is a one to many relationship:
if (mysqli_num_rows($r2) == 1) {
$q3 = "SELECT Resort_ID, Resort_Name FROM Resorts";
$r3 = @mysqli_query($dbc, $q3);
$row3 = mysqli_fetch_array($r3, MYSQLI_NUM);
}
I then am creating an array to populate the <option> tag like so:
$options="";
while ($row=mysqli_fetch_array($r3)) {
$id=$row3[0];
$rn=$row3[1];
$options="<OPTION VALUE=\\"$id\\">".$rn.'</option>';
}
Then in the form I am doing this:
<?php if (mysqli_num_rows($r3) > 0) {
?> <select name="Resort_ID">
<?=$options?>
<?php } ?> </select><br /><br />
Now here is my question. One of the things that I need to do is, the resort that is tied to the gift certificate that I am editing should be automatically selected, but I still want to see all the resorts since the user could have selected the wrong resort by mistake.
Can someone point out what I am doing wrong?
Thanks,
Bruce