Question:
PHP/MySQL: Getting a rows contents from a variable?
Kenny
2009-02-05 17:52:59 UTC
I'm currently working on a PHP script that lists the entries in a database. Since this will be maintained by people unfamiliar with PHP I am trying to allow everything to be configured by a collection of variables and arrays at the top. Here's my dilemma: How can I set a variable at the beginning to reference a row in a MySQL table.

This is what they should be able to configure:
$UniqueID = "NameOfSomeRow";

To allow a check box in the list to receive the appropriate value.
$counter = 0;
while ($row = mysql_fetch_array($QueryResult))
{
extract($row);
$UniqueID = ??? (Where I'm stuck)
echo " \n ";

foreach($AllFieldsARR as $key=>$value) ...

Hoping this is something simple that I haven't thought of yet. Thanks in advance.
Three answers:
CompanionCube
2009-02-05 22:54:02 UTC
I think what you're getting at is a 'variable variable'.



Make $UniqueID = $$UniqueID (note the 2 dollar signs)



That will set the variable UniqueID equal to a new variable named with the text value of the UniqueID defined above.



Could probably also just enter $$UniqueID into the OnClick function which is where I presume this goes?



Good luck though.
ChrisS
2009-02-05 21:56:42 UTC
wow, why are you using extract() first off?



is it that you are trying to make $UniqueID be the value of the auto increment field in the mysql table?



$UniqueID = $row['fieldname'];



whenever you're in doubt as to what is in an array, use print_r($array);
hodnett
2016-11-14 13:32:58 UTC
First, my compliments for the type you word your questions (i spotted the accepted key one, the day gone by, besides); I wish each person in this talk board wrote their questions the type you do: intricate, no longer a homework question (no count if it truly is, then this is obvious you have been attempting to do it your self and you deserve some help), and no obvious spelling or grammar blunders, or typos. thank you for that! i can not see the rationalization why Colanth's answer does no longer artwork (his solutions many times are incredibly sturdy). in the final section you write which you tried putting the preliminary state (a million-5), and you print the impressive consequence. could desire to you attempt taking even smaller steps? Like this (in shorthand): Set the positions in the documents to a million to 5 echo 'preliminary state', PHP_EOL; print the consequence of "elect * FROM photographs" $pict01 = mysql_real_escape_string($_GET['p']); $pict02 = mysql_real_escape_string($_GET['t']); echo 'pict1 = ', $pict01, ' pict2=', $pict02, PHP_EOL; $sq. = "replace photographs SET place = 'holdme' the place place='$pict01'"; echo $sq., PHP_EOL; mysql_query( $sq. ); echo 'After the 1st step', PHP_EOL; print the consequence of "elect * FROM photographs" $sq. = "replace photographs SET place = '$pict01' the place place='$pict02'"; echo $sq., PHP_EOL; mysql_query( $sq. ); echo 'After step 2', PHP_EOL; print the consequence of "elect * FROM photographs" $sq. = "replace photographs SET place = '$pict02' the place place='holdme'"; echo $sq., PHP_EOL; mysql_query( $sq. ); echo 'After step 3', PHP_EOL; print the consequence of "elect * FROM photographs" After this, you would be able to desire to verify if all the stairs do what you assume them to do. If no longer, submit the log right here and we will attempt to help you lower back. i'm certainly intrigued now. :-) sturdy success!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...