Jump to content


Photo

Possible Interpolation *SOLVED*


  • Please log in to reply
2 replies to this topic

#1 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 31 August 2006 - 08:44 PM

I think this is an interpolation question but I'm not sure.

I have the following code, now I know the code's not ideal, but I'm putting it like this so I can learn.

<?php
$fruit = $_GET['fruit'] // The value of 'fruit' is going to be a text string passed from a form of either "$apple" or "$grape"
$apple[]="red";
$apple[]="green";
$grape[] = "purple";
$grape[] = "green";

foreach ($var as $colour){ // how can I make $var whatever the value of $fruit is I guess I need to interpolate the variable
   echo $colour;
}
?>

I hope this made sense.

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 31 August 2006 - 08:57 PM

foreach ($$fruit as $colour){
  echo $colour;
}
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 01 September 2006 - 08:50 AM

Thanks Barand,

Just perfect  ;D

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users