note 64048 added to control-structures.while
| From: | php-general at lists dot php dot net | Date: | Thu, 06 Apr 2006 12:16:53 +0000 |
| Subject: | note 64048 added to control-structures.while | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107416@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 194.109.193.119
Probable Submitter: 80.65.96.52 (proxied: 80.65.121.212)
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/control-structures.while.php
Edit -- http://master.php.net/note/edit/64048
Del: integrated -- http://master.php.net/note/delete/64048/integrated
Del: useless -- http://master.php.net/note/delete/64048/useless
Del: bad code -- http://master.php.net/note/delete/64048/bad+code
Del: spam -- http://master.php.net/note/delete/64048/spam
Del: non-english -- http://master.php.net/note/delete/64048/non-english
Del: in docs -- http://master.php.net/note/delete/64048/in+docs
Del: other reasons-- http://master.php.net/note/delete/64048
Reject -- http://master.php.net/note/reject/64048
Search -- http://master.php.net/manage/user-notes.php