Jump to content


Photo

query/php problem


  • Please log in to reply
3 replies to this topic

#1 nisroc

nisroc
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 10 August 2006 - 11:02 PM

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?

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


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 August 2006 - 11:07 PM

$temp = "'q". $counter. "'";
Legend has it that reading the manual never killed anyone.
My site

#3 nisroc

nisroc
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 11 August 2006 - 01:07 AM

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:

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





#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 11 August 2006 - 05:22 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users