Forum Moderators: coopster

Message Too Old, No Replies

Use variable to point to location in array?

         

hellbus

7:59 pm on Oct 15, 2009 (gmt 0)

10+ Year Member



Hello.

I am writing a PHP function that takes the results of an SQL query, and puts them in either a table, checkbox form, or radio button form.
There are variables that are sent to the function that tell it to make it a form, radio button, etc.

What I am trying to do is send a variable to the function, which represents a location in an array. I am doing this in order to give my checkbox and radio button sections a "value".

What I did was just send a number as the variable, which I want pointing to a location in an array. I am having some trouble pointing to it, though. I am not sure if what I am trying is even possible with PHP.

What I have is this:

while ($row = mssql_fetch_assoc($result))
{
echo"<tr>";

if ($form ==1 && $tabletype =="radio" ¦¦ $form ==1 && $tabletype =="checkbox") //If item is a form, and a checkbox or radio button
{
echo"<td><input type='$tabletype' name='selection' value='";
echo $row[$itemvalue];
echo "'";
}

NOTE: $tabletype is another variable that is sent to determine whether it is a table to checkbox.

I have tried it several different ways. When I just try

$test = $row[$itemvalue];

$test is NULL.

Is what I am trying to do possible? If so, what am I missing?

hellbus

4:34 pm on Oct 16, 2009 (gmt 0)

10+ Year Member



Never mind. I figured it out. It was a silly mistake. When I sent my array through. They key was the name of the column of the SQL query, not 0,1,2, etc.