Bit of PHP/Mysql help needed please
Discussion
I'm building a form to display some data. The form runs through twice, once as the 'original' and once as the duplicate. All is well except when it loops a second time it displays a blank row at the head of the table.
As you can see I've figured out that I need to reset the pointer but I'm sure I should somehow 'call' the row ready for the next time the script loops. Can anyone point me in the right direction?
{{{
<?php
do { ?>
<tr class="data">
<td><?php echo $row_ItemsRecordset['ColA']; ?></td>
<td><?php echo $row_ItemsRecordset['ColB']; ?></td>
<td><?php echo $row_ItemsRecordset['ColC']; ?></td>
<td><?php echo $row_ItemsRecordset['ColD']; ?></td>
<td> </td>
</tr>
<?php
} while ($row_ItemsRecordset = mysql_fetch_assoc($ItemsRecordset));
//============================================================+
//Reset the recordset before reusing it in the repeat region.
//============================================================+
mysql_data_seek($ItemsRecordset,0); ?>
}}}
As you can see I've figured out that I need to reset the pointer but I'm sure I should somehow 'call' the row ready for the next time the script loops. Can anyone point me in the right direction?
{{{
<?php
do { ?>
<tr class="data">
<td><?php echo $row_ItemsRecordset['ColA']; ?></td>
<td><?php echo $row_ItemsRecordset['ColB']; ?></td>
<td><?php echo $row_ItemsRecordset['ColC']; ?></td>
<td><?php echo $row_ItemsRecordset['ColD']; ?></td>
<td> </td>
</tr>
<?php
} while ($row_ItemsRecordset = mysql_fetch_assoc($ItemsRecordset));
//============================================================+
//Reset the recordset before reusing it in the repeat region.
//============================================================+
mysql_data_seek($ItemsRecordset,0); ?>
}}}
BliarOut said:
I'm building a form to display some data. The form runs through twice, once as the 'original' and once as the duplicate. All is well except when it loops a second time it displays a blank row at the head of the table.
As you can see I've figured out that I need to reset the pointer but I'm sure I should somehow 'call' the row ready for the next time the script loops. Can anyone point me in the right direction?
{{{
<?php
do { ?>
<tr class="data">
<td><?php echo $row_ItemsRecordset['ColA']; ?></td>
<td><?php echo $row_ItemsRecordset['ColB']; ?></td>
<td><?php echo $row_ItemsRecordset['ColC']; ?></td>
<td><?php echo $row_ItemsRecordset['ColD']; ?></td>
<td> </td>
</tr>
<?php
} while ($row_ItemsRecordset = mysql_fetch_assoc($ItemsRecordset));
//============================================================+
//Reset the recordset before reusing it in the repeat region.
//============================================================+
mysql_data_seek($ItemsRecordset,0); ?>
}}}
Sticking it into a foreach should solve your problemAs you can see I've figured out that I need to reset the pointer but I'm sure I should somehow 'call' the row ready for the next time the script loops. Can anyone point me in the right direction?
{{{
<?php
do { ?>
<tr class="data">
<td><?php echo $row_ItemsRecordset['ColA']; ?></td>
<td><?php echo $row_ItemsRecordset['ColB']; ?></td>
<td><?php echo $row_ItemsRecordset['ColC']; ?></td>
<td><?php echo $row_ItemsRecordset['ColD']; ?></td>
<td> </td>
</tr>
<?php
} while ($row_ItemsRecordset = mysql_fetch_assoc($ItemsRecordset));
//============================================================+
//Reset the recordset before reusing it in the repeat region.
//============================================================+
mysql_data_seek($ItemsRecordset,0); ?>
}}}
{{{
$query = mysql_query ("SELECT...");
foreach ($row = mysql_fetch_assoc ($query))
{
?>
....
<?php
}
mysql_data_seek ($query, 0);
foreach ($row = mysql_fetch_assoc ($query))
{
?>
....
<?php
}
}}}
ETA: I'd also look at PDO under php5.
Edited by sonic_2k_uk on Thursday 29th July 13:35
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff