Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

RE: [PHP3] Array Question From: Leonardo Creo (leo <email protected>)
Date: 03/28/99

-

>Hey all, im tired and stuck on this....below is a db call that i loop 14
times. The
>variable $a is already defined and not shown here, its just some text, this
part works
>fine. It loops 14 times showing the 14 different lines of text. But the
2nd one, $row,
>is causing me problems. It should grab the 14 different rows, q1, q2, q3,
q4 etc., but
>obviously im doing it wrong. My question is, how do i get $row[q$i] to do
this: $row[q1]
>$row[q2] and so forth..
>
>$i = 1;
>while ($i <= 14): /* This sets how many questions there are */
>$user = mysql_query("select q$i from table where id = $id ");
>
>$row = mysql_fetch_array($user);
>
>echo("<tr><td bgcolor=\"#D6D5FF\"><b>$a[$i]</b></td><td
>bgcolor=\"#cccccc\">$row[q$i]</td></tr>");
>
>$i++;
>endwhile;
>
>

Hey, I know this solution to your problem.
Put this:
    $i = 1;
    while ($i <= 14): /* This sets how many questions there are */
        $user = mysql_query("select q$i from table where id = $id ");

    $row = mysql_fetch_array($user);

    $tmp="\$var= \$row[q$i]";
    eval($tem);
    // Now $var contain the value of $row[q$i] for each $i value on loop

    echo("<tr><td bgcolor=\"#D6D5FF\"><b>$a[$i]</b></td><td
    bgcolor=\"#cccccc\">$var</td></tr>");

    $i++;
    endwhile;

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3
List administrator:  zeev-list-admin <email protected>