Re: PHP and MySQL
| From: | Dobromir Velev | Date: | Fri, 12 Oct 2001 05:43:19 +0000 |
| Subject: | Re: PHP and MySQL | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-13285@lists.php.net to get a copy of this message | ||
Hi,
to get $varx where x is a variable you can use either
${"var".$x} or $newvar="var".$x; $$newwar
your code will look like this
$x = 1;
while ( $rows >= $x ) {
echo "$x is ".${"vun".$x};
$x++;
}
or
$x = 1;
while ( $rows >= $x ) {
$newvar="var".$x;
echo "$x is ".$$newwar
$x++;
}
There is a very good description on working with variable variables in the
PHP Manual
Dobromir Velev
-----Original Message-----
From: Vincent van Os <ej.van.os@wxs.nl>
To: php-db@lists.php.net <php-db@lists.php.net>
Date: Thursday, October 11, 2001 11:54 PM
Subject: [PHP-DB] PHP and MySQL
>hej there
>first i want to tell that im new to php and that im not an native english
>speaking person (dutch, the netherlands) so excuse me for my bad english
>but now the issue :
>
>im trying to fetch info from an database and put it into checkboxes (source
>will follow) that works so far
>but then i want to check some boxes and see the result under it when i
>press the submit button. im doing this with the var $vun<nummer here>
>so check box one wil be $var1 second will be $var2 and so on
>this wil stop untill it finds the last row in the table
>now i want to walk trough al the $vun* vars to see it the check box is on
or
>not and if it is the row from the table must be printed below the
>checkboxes. im doing this with the $rows var ( $rows =
>mysql_num_rows($result); ) and an while loop. i use the $x var to count
>($x++) so i can use the $x and the $vun together so it wil result to $vun1
>($vun[$x] where $x is "1" ) but that wont work
>
>if someone has the solution please let me know
>
>
>Vincent van Os
>
>
>
>
>ps below you wil find an simpel version of the source
>
>----------------------begin source-------------------
>
><?
>$user = "foo";
>$host = "foo";
>$pwd = "foo";
>$database = foo;
>$table = "foo";
>$db = mysql_connect("$host", "$user", "$pwd");
>$result = mysql($database,"select * from $table");
>$fields = mysql_num_fields($result);;
>$rows = mysql_num_rows($result);
>$fields = mysql_list_fields("$database", "$table", $db);
>$columns = mysql_num_fields($fields);
>echo "<BR>";
>for ($i = 0; $i < $columns; $i++) {
> echo mysql_field_name($fields, $i) . "\n";;
>}
>echo "<FORM METHOD=POST ACTION=this_page.php>";
>$var = "1";
>while ($row = mysql_fetch_array($result)) {
>echo "$var";
>echo "<INPUT TYPE=CHECKBOX NAME=vun$i>$row[src_ip] $row[dest_ip]
>$row[drop_ip] $row[reject_ip] $row[allow_ip] ";
>$var++;
>echo "<BR>";
>}
>echo "<INPUT TYPE=SUBMIT VALUE=SUBMIT>";
>echo "</FORM>";
>//
>// problem is here
>//
>$x = 1;
>while ( $rows >= $x ) {
>echo "$x is $vun[$x]".
>$x++;
>}
>mysql_close;
>?>
>
>------------------end source----------------
>
>
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
>For additional commands, e-mail: php-db-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>