You are here: Re: Form inside loop, need to wait till submit is activated. « PHP Programming Language « IT news, forums, messages
Re: Form inside loop, need to wait till submit is activated.

Posted by Sandman on 11/21/01 11:26

In article <1126534438.501131.5840@g44g2000cwa.googlegroups.com>,
rjames.clarke@gmail.com wrote:

> I have the following.
>
> $result=mysql_query($sql);
> $nrows=mysql_num_rows($result);
> for ($i=0;$i<$nrows;$i++)
> {
> $row_array=mysql_fetch_row($result);
> echo "<form name='testform' action='ins_op.php' method='post'>";
>
> lots of form stuff
>
> echo "<td><input type='submit' value='Save'>";
>
> echo "</form>";
> }
>
> I'd like to have the loop wait until the form submit is pressed before
> it continues and grabs the next record from $row_array.
>
> Right now the code displays all the records with their submit buttons.
>
> Doing it in this form permits one query to the database to get all the
> open records.
>
> Alternative code structures would be entertained.
>
> thanks


I am guessing that you have a table of values and you want to be able to edit
those values one by one until every row has been edited? Consider something
like this:

<?
$q = mysql_query("select id, field from table where
status = 'new' order by id desc limit 1");
while ($r = mysql_fetch_array($q)){
print "<form action='$_SERVER[PHP_SELF]'>";
print "<input type='text' name='field' value='$r[field]' />";
print "<input type='hidden' name='id' value='$r[id]' />";
print "<input type='submit' value='Save value' />";
print "</form>";
}
?>

This will present a form to edit the last entry in the database. You could of
course edit multiple fields at the same time:

<form action='<?=$_SERVER[PHP_SELF] ?>'>
<?
$q = mysql_query("select id, field from table where
status = 'new' order by id desc");
while ($r = mysql_fetch_array($q)){
print "<input type='text' name='field[{$r[id]}]' value='$r[field]' />";
}
?>
<input type='submit' value='Save value' />
</form>

And then handle $_GET["field"] which is an array.


--
Sandman[.net]

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация