Jump to content

Archived

This topic is now archived and is closed to further replies.

nisroc

query/php problem

Recommended Posts

Im trying to get this small script below to return the values from a mysql db where the firld in the table are named q1, q2, q3, etc. I have had luck up to this point but all it is returning is q1 q2 q3 q4. I have also tried echo $row_testresults["$temp"]; but had same results. there is connection to the database becuase i have tried <?php echo $row_testresults['q1']; ?> alone and got a return. What am i doing wrong here?

[code]
<?php
$counter = 1;
while ( $counter <= 4 ) {
$temp = "q $counter";
$temp = str_replace(" ","", $temp);
echo $row_testresults[ $temp ];
echo "<br />";
$counter = $counter + 1;
}
?>
[/code]

Share this post


Link to post
Share on other sites
Thank for  replying I tried what you said and it does work but when i use in to call the fields from the table i get nothing returned. If i echo it i get:

'q1'
'q2'
'q3'
'q4'

It just does not appear to be returning the data fromn the db.

Here is the refreshed code:

[code]
<?php
$counter = 1;
while ( $counter <= 4 ) {
$temp = "'q". $counter. "'";
echo $row_testresults[ $temp ];  // this line hates me
echo "<br />";
$counter = $counter + 1;
}
?>
[/code]



Share this post


Link to post
Share on other sites
Where is the rest of it? Can we see where you actually create $row_results? This seems a very about face method of looping through results.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.