nisroc Posted August 10, 2006 Share Posted August 10, 2006 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] Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 10, 2006 Share Posted August 10, 2006 $temp = "'q". $counter. "'"; Quote Link to comment Share on other sites More sharing options...
nisroc Posted August 11, 2006 Author Share Posted August 11, 2006 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] Quote Link to comment Share on other sites More sharing options...
trq Posted August 11, 2006 Share Posted August 11, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.