Re: filling in form with for loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rob, this solved my problem. I had not read about this technique before, but
it works great. Thanks!

On Dec 6, 2007 3:34 AM, Atkinson, Robert <ratkinson@xxxxxxxxxxxxx> wrote:

>   I think you're missing a loop, and also need an associative array :-
>
> while ($row=mysql_fetch_assoc($List)) { // loop round each row in the
> dataset
>
> for($i=1;$i<=12;$i++){
>
> echo "<td align='center'>";
> if($row['room']!=$i){
> echo"$i</td>";
> echo"<td align='center'><input type='text' name='lname'></td>";
> echo"<td align='center'><input type='text' name='fname'></td>";
> }
> else {
>
> echo "$row[room]</td>";
> echo "<td align='center'><a href = 'Edit.php?ID=$ID'>"
> .ucfirst($row[lname])." </a></td>";
> echo "<td align='center'><a
> href='Edit.php?ID=$ID'>".ucfirst($row[fname])."</a> </td>";
> }
> }
>
> Having said that, you will end up with a 12 x 12 grid, because you're
> looping
> round all 12 rooms for every room booked.
>
> Personally, I would turn the dataset into an associative array, based on
> the
> room number, so you can access the data directly :-
>
> $rooms = array();
>
> while ($row=mysql_fetch_assoc($List)) {
> $rooms["{$row['room']}"] = array('lname' => $row['lname'],
> 'fname' => $row['fname'])
> }
>
> Now you can loop round each of the 12 rooms and simply do
> isset($rooms["$i"])
> to see if there's any information in the room or not.
>
> There may be a simpler way to get to this end result, but at least you can
> see exactly what's going on here.
>
> Rob.
>
>
> -----Original Message-----
> From: php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com> [mailto:
> php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com>] On
> Behalf Of perfectsolution1
> Sent: 05 December 2007 04:31
> To: php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com>
> Subject:  filling in form with for loop
>
> Can anyone help me work this out? I have an array with a room number
> associated with fname, lname, etc. I know the number of rooms, and
> want to fill in the form with textbox where the room is empty, and
> with the persons name in the room associated with the specific room.
> This is my code I have come up with that only gives me the table once
> with the first person, and text boxes in the other rooms.
>
> $row=mysql_fetch_array($List);
> for($i=1;$i<=12;$i++){
>
> echo "<td align='center'>";
> if($row['room']!=$i){
> echo"$i</td>";
> echo"<td align='center'><input type='text' name='lname'></td>";
> echo"<td align='center'><input type='text' name='fname'></td>";
> }
> else {
>
> echo "$row[room]</td>";
> echo "<td align='center'><a href = 'Edit.php?ID=$ID'>"
> .ucfirst($row[lname])." </a></td>";
> echo "<td align='center'><a
> href='Edit.php?ID=$ID'>".ucfirst($row[fname])."</a> </td>";
> }
>
>
> ***********************************************************************************
> Any opinions expressed in email are those of the individual and not
> necessarily those of the company. This email and any files transmitted with
> it are confidential and solely for the use of the intended recipient
> or entity to whom they are addressed. It may contain material protected by
> attorney-client privilege. If you are not the intended recipient, or a
> person responsible for delivering to the intended recipient, be advised that
> you have received this email in error and that any use is strictly
> prohibited.
>
> Random House Group + 44 (0) 20 7840 8400
> http://www.randomhouse.co.uk
> http://www.booksattransworld.co.uk
> http://www.kidsatrandomhouse.co.uk
> Generic email address - enquiries@xxxxxxxxxxxxxxxxx<enquiries%40randomhouse.co.uk>
>
> Name & Registered Office:
> THE RANDOM HOUSE GROUP LIMITED
> 20 VAUXHALL BRIDGE ROAD
> LONDON
> SW1V 2SA
> Random House Group Ltd is registered in the United Kingdom with company
> No. 00954009, VAT number 102838980
>
> ***********************************************************************************
>
>  
>


[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux