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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.