Hello,
I'm using an array to store the old values from a table and when i update any fields they are stored in a new array and then display the updated records on a form.
I'm confused in using with two tables:
For example:
<?
Database connection details
if ($HTTP_POST_VARS){
$cnt = count($HTTP_POST_VARS['id']);
for($cntr=0;$cntr<$cnt;$cntr++) {
$sql = "UPDATE TBL_HANDSET SET ".
"HS_IPUI = '{$HTTP_POST_VARS['ipui'][$cntr]}', ".
"HS_TEI = '{$HTTP_POST_VARS['tei'][$cntr]}' ".
"where HS_ID = {$HTTP_POST_VARS['id'][$cntr]}";
$update_results = ibase_query($sql);
}
}
$select_sql = 'Select HS_ID, HS_IPUI, HS_TEI from TBL_HANDSET';
$result_id = ibase_query($select_sql);
?>
<form name="edit handset" action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="POST">
<table cellpadding="0" cellspacing="0" width="909" class="hsnormal">
<tr style="margin:0; padding:0;" align="left" valign="top" class="hsnormal">
<td width="154">
IPUI
</td>
<td width="154">
TEI
</td>
</tr>
<?php
$counter=0;
$old_values=null;
while ($row = ibase_fetch_object($result_id)) {
$ipui=$row->HS_IPUI;
$tei=$row->HS_TEI;
?>
<tr style="margin:0; padding:0;" align="left" valign="top" class="hsnormal">
<td width="156" height="23">
<input type="text" name="ipui[<?=$counter?>]" value="<?=$ipui?>">
</td>
<td width="154" height="23">
<input type="text" name="tei[<?=$counter?>]" value="<?=$tei?>">
</td>
</tr>
<?php
$old_values.=' <input type="hidden" name="id['.$counter.']" value="'.$row->HS_ID.'">
';
$counter++;
}
?>
</table>
<?=$old_values?>
<input type="submit" name="submit" value="Update">
</form>
THE ABOVE CODE IS ABSOLUTELY WORKING FINE.
Now, i want to insert the following:
$sql_update = "update TBL_STIMTERM SET ".
"STIM_IPADDRESS = '{$HTTP_POST_VARS['ip_address'][$cntr]}', ".
"STIM_PHONENUMBER = '{$HTTP_POST_VARS['phone_number'][$cntr]}' ".
"where STIM_ID = {$HTTP_POST_VARS['id'][$cntr]}";
$result = ibase_query($sql_update);
(The above sql statement will be modified as🙂
$select_sql = 'Select HS_ID, HS_IPUI, HS_TEI, '.
'STIM_ID, STIM_IPADDRESS, '.
'STIM_PHONENUMBER FROM TBL_HANDSET INNER JOIN TBL_STIMTERM ON TBL_HANDSET.HS_ID = TBL_STIMTERM.STIM_ID';
$result_id = ibase_query($select_sql);
-------------My question is concerned with this one now-----------
<?php
$old_values.=' <input type="hidden" name="id['.$counter.']" value="'.$row->HS_ID.'">
';
$counter++;
}
?>
</table>
<?=$old_values?>
HOw can i insert the id field of 2nd table that is STIM_ID?
Hope i expressed my self clearly.
your help would be highly appreciated!
thank you