Jump to content


Photo

Passing Variables Help Request.


  • Please log in to reply
3 replies to this topic

#1 Strixy

Strixy
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 July 2006 - 08:44 PM

Let me start by explaining the project a little.

Via a web form, the user selects 2 numbers (drop down) and 2 items (drop down). The numbers selected are to be placed in a table. The two items are selected from a drop down list of 6 choices. The location of those numbers (in the table) is determined by the users selection of item1 and item2. The correlation of item1 and item2 is stored in a mysql database and as described, determined by the users input.

If I put a results table together, such that each cell in the table is a unique $variable, then I can store those variable names as searchable/selectable results in a mysql database. The end result is such that the users choice of items will determine the placement of the two numbers in a table of results.

Example;
<?php
// other stuff eg, web form, mysql_connect, select_db, etc...  leading to
      $number1 = $_POST['number1'];
      $querya = mysql_select("SELECT varname FROM table WHERE $item1 = '$item2');// will reaturn a location variable ...
      $resulta = return($querya, 0);   // ... "location1a" or "location2b" or whatever.
      "$".$resulta = $number1   // This is the part I'm having problems with.
?>

Lets say that the result of the query, for the sake of arguement, is "location2b".

I would like to create a variable name that is determined by the mysql result and then set that variable to whatever $number1 was set to back at the $number1 = $_POST['number1'] so that I can echo the value of $number1 in the appropriate place. For example, a table 6x6 with 36 variables all connectted to the result of the mysql query. The result table looks like... (html removed)

$location1a    $location1b    $location1c    $location1d .... etc ....
$location2a    $location2b    $location2c    $location2d .... etc ....
$location3a    $location3b    $location3c    $location3d  ....etc ....
etc..
etc..

So, for example, if the mysql query returns "location2b" as the result of the query, I would like to be able  to echo the value of $number1 in the proper location.

Any thoughts would be appreciated. Even if its to say it can't be done so I can stop trying to figure this out. Thank you!

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 29 July 2006 - 09:30 PM

You are trying to use variable variables (http://www.php.net/m...es.variable.php)
<?php
// other stuff eg, web form, mysql_connect, select_db, etc...  leading to
      $number1 = $_POST['number1'];
      $querya = "SELECT varname FROM table WHERE $item1 = '$item2'";// will reaturn a location variable ...
      $rw = mysql_query($querya) or die("Problem with the query: $querya<br>" . mysql_error());
      $resulta = $rw['varname'];   // ... "location1a" or "location2b" or whatever.
      $$resulta = $number1   // This is the part I'm having problems with.
?>

Ken


#3 Strixy

Strixy
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 July 2006 - 10:02 PM

Three things.

Thank you for the quick answer.
Thank you for providing a reference (URL).
And thank you for providing some nice code.

So, in summary.

Thank you, thank you, thank you!

#4 Strixy

Strixy
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 July 2006 - 11:55 PM

And yes, it worked!

Thanks again!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users