Jump to content

query/php problem


nisroc

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]
Link to comment
https://forums.phpfreaks.com/topic/17181-queryphp-problem/
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]



Link to comment
https://forums.phpfreaks.com/topic/17181-queryphp-problem/#findComment-72812
Share on other sites

Archived

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

×
×
  • Create New...

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.