note 64048 deleted from control-structures.while by philip

From: Date: Thu, 27 Apr 2006 15:50:13 +0000
Subject: note 64048 deleted from control-structures.while by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-109861@lists.php.net to get a copy of this message
Note Submitter: ---- This thing is cool. I use 'while' expressions all the time, to create a dropdown box from a table for instance. Code: <? $username="root"; $password=""; $database="adatabase"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Can't retrieve database."); $query="SELECT * FROM atable"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; echo "<select name=test>"; echo "<option></option>"; //this is for a blank default value while ($i < $num) { $test=mysql_result($result,$i,"naam"); echo "<option>$naam</option>"; $i++; } echo "</select>"; ?> What it can't do however, is when you create fieldnames using <? echo "<input type=text name=field$i>" ?> (this will generate fields named field1, field2, field3 etc obviously) you can't read the related post info using $field=$_POST['field$i']; and add $field's non existing output in a query. The query is inside the loop ofcourse. I'm trying to work this out to add multiple instances of a component with different serial numbers to a database. This is no request.

« previous php.notes (#109861) next »