[PHP] assigning a part of the name of a variable with another variable before php replaces it with the value

2001-07-26 Thread Matthew DeChant

Specifically,

If I have 3 HTTP_POST_VARS:

HTTP_POST_VARS[client] = test1
HTTP_POST_VARS[directory]= test2
HTTP_POST_VARS[password] =


and I don't know the names of the vars ahead of time, how would I run a
check to see if they exist and then get the specific POST_VARS's value. This
is what I've got so far:


$squery = select * from $db where ;
$qh = fw_query(select * from $db);
$fields = odbc_num_fields($qh);
for ($i=1;$i=$fields;$i++) {
  # assign $fname the possible field names in the database
(client,directory,password)
$fname[$i] = odbc_field_name($qh,$i);
  # assign $postfld the variable name, ie. $HTTP_POST_VARS[client]
$postfld = $HTTP_POST_VARS[($fname[$i])];
  # check that it exists and is not blank
if (isset($postfld) AND ($postfld != )) {
$value[$i] = $postfld;
$squery.= $fname[$i] like $value[$i] AND ;
}
}
# pop last AND
$squery= substr($squery, 0,-5);

so how do you make this work:  $postfld = $HTTP_POST_VARS[($fname[$i])];

thanks,

-m


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] assigning a part of the name of a variable with another variable before php replaces it with the value

2001-07-26 Thread Julian Wood


To answer your question:

$postfld = $HTTP_POST_VARS[$fname[$i]];

should work. BTW, I just use something like:

if ($client) { // or in your case: if (${$fname[$i]})
// code to be evaluated if $client exists and is not 0, not null/void/nil, and is
not an empty string
}

J

Matthew DeChant wrote:

 Specifically,

 If I have 3 HTTP_POST_VARS:

 HTTP_POST_VARS[client] = test1
 HTTP_POST_VARS[directory]= test2
 HTTP_POST_VARS[password] =

 and I don't know the names of the vars ahead of time, how would I run a
 check to see if they exist and then get the specific POST_VARS's value. This
 is what I've got so far:

 $squery = select * from $db where ;
 $qh = fw_query(select * from $db);
 $fields = odbc_num_fields($qh);
 for ($i=1;$i=$fields;$i++) {
   # assign $fname the possible field names in the database
 (client,directory,password)
 $fname[$i] = odbc_field_name($qh,$i);
   # assign $postfld the variable name, ie. $HTTP_POST_VARS[client]
 $postfld = $HTTP_POST_VARS[($fname[$i])];
   # check that it exists and is not blank
 if (isset($postfld) AND ($postfld != )) {
 $value[$i] = $postfld;
 $squery.= $fname[$i] like $value[$i] AND ;
 }
 }
 # pop last AND
 $squery= substr($squery, 0,-5);

 so how do you make this work:  $postfld = $HTTP_POST_VARS[($fname[$i])];

 thanks,

 -m

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]