crimsonmoon Posted March 1, 2007 Share Posted March 1, 2007 I'm printer a url with php in it from a database field and all that's printing is the link and the variable code. The variable is not changing to the actual #. For example this is what I'm using. This in in the DB. http://link.com/home.php?x=$variable I use this print "$DBField"; and this prints. http://link.com/home.php?x=$variable The variable in not changing over to it's value when it = 1 for instance. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/ Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 erm.. not sure what your asking but.. heres a basic get file index.php <?php echo "x = ".$_GET[x]; ?> so index.php?x=10 would display x = 10 Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196535 Share on other sites More sharing options...
crimsonmoon Posted March 1, 2007 Author Share Posted March 1, 2007 I know how variable work. What I'm asking is if I have a database field that hold a link like I posted above with a variable in it. Then I print the link out in a page right now it just print the variable like $variable. It's not converting the variable to it's actual value. How do you get a variable to change it it's value when the variable in within a variable. Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196537 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 So is $variable infact part of the string ? ie "this is some test data $variable in the db" or a field in the database ? i need some examples really! Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196542 Share on other sites More sharing options...
crimsonmoon Posted March 1, 2007 Author Share Posted March 1, 2007 This is the field in the DB (It's a link) : http://site.com/home.php?id=$x Now we're on the php page. at the top of the page $x = 23; We pull the field into $field[dblink]. So $field[dblink] is the link I have above. in the php page I print: print "<a href=$field[dblink]>Click Here</a>"; instead of <a href=http://site.com/home.php?id=23>Click Here</a> I get <a href=http://site.com/home.php?id=$x>Click Here</a> So the $x is not changing over to 23 .....what am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196546 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 try print "<a href=".$field[dblink].">Click Here[/url]"; also is it $field[dblink] or $field['dblink'] Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196551 Share on other sites More sharing options...
crimsonmoon Posted March 1, 2007 Author Share Posted March 1, 2007 Tried that and it's still not working...Still leave the variable like it's a string. I was doing $field[dblink] but I tried the other way as well and still no luck. Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196565 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 can you post the results of this please so i can see what your working with <?php echo "<br />"; var_dump($field); echo "<br />"; print_r($field); ?> as a note i tried this and it worked on my site basically i createds a array (same as i would get a return from a database) and printed it <?php $field = array('dblink' => 10); print "<a href=text2.php?x=$field[dblink]>Click Here</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196573 Share on other sites More sharing options...
crimsonmoon Posted March 1, 2007 Author Share Posted March 1, 2007 string(74) "http://www.toprpgames.com/vote.php?idno=437&field1=$var[id]&field2=$var2" http://www.toprpgames.com/vote.php?idno=437&field1=$var[id]&field2=$var2 when i try doing a $db['field'] i get the error about encapsulated white space [Wed Feb 28 21:54:18 2007] [error] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196580 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 i think you need to check the whats being set in the database, is it setting $x or its value ? Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196583 Share on other sites More sharing options...
kenrbnsn Posted March 1, 2007 Share Posted March 1, 2007 That is different. What the OP has is a string that has the value of 'http://site.com/home.php?id=$x' At some later point after setting the string's value, the OP sets the variable $x to 23. What is needed is to use the eval() function: <?php $str = 'http://site.com/home.php?id=$x'; $x = 23; echo $str; eval("\$str2 = \"$str\";"); echo '<br>'.$str2; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196584 Share on other sites More sharing options...
crimsonmoon Posted March 1, 2007 Author Share Posted March 1, 2007 Thx Ken that worked! Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196766 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 Please mark as solved! Quote Link to comment https://forums.phpfreaks.com/topic/40636-solved-print-php-variable-from-database-field-and-have-it-work/#findComment-196984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.