I'm having a little trouble understanding something that I've been working on.

I have a table with countries and their associate dailing codes in rows (about 240) and I'm outputting them to the page in a loop to be placed in a drop down list. In my form, I am needing the list 2x so I figured, just copy and paste the same code in the other location. Problem is, the first location renders perfectly, the second doesn't render at all. I wondering if it has to do with the connections that MySQL can have at one time. Here's the code for the loop:

            <td><select name="faxcode" class="normal" id="faxcode" style="width: 196px;">
			  <?php do {  ?>
				<option value="<?php echo $row_Recordset2['dcode']?>"
				  <?php if (!(strcmp($row_Recordset2['dcode'],
			 		$row_Recordset1['dcode']))) ?>>
				  <?php echo $row_Recordset2['country']?>
				</option>
				<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
				</select>

I'm not sure why the first list would show up but the second list is just one blank line.

    Also, I have sessions enabled to write pieces of other information such as Names $ e-mail addresses, however when I used the loop, the session data for that particular area gets erased or never post, cant be sure since the headers don't really specify. Either way they're not there. If I disable the loop section of the code, the sessions work. Now I'm really spoofed.

      As you use mysql_fetch_assoc, it fetches the next row in the database result set for you. That bit's fine. The problem is that it also gets rid of the rows as it goes along, so that you can't use the same result set twice.

      You'll need to refetch the information from the database or make a copy of $Recordset2 before you start fetching rows from it (e.g. $Recordset3 = $Recordset2), and then use mysql_fetch_assoc on $Recordset3 the second time round. Actually, I'm not sure if the code I've suggested will work, but you could give it a try.

      I'm not sure about your problem with sessions, I never really use them (I prefer to set cookies manually, it's an old habit!)

        Ok, I fixed it, just duplicated the recordset3 as recorderset 4, also using session_write_close() fixed the session problem.

          Write a Reply...