cs.punk Posted March 13, 2010 Share Posted March 13, 2010 From the database game_src <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400"> <param name="movie" value="[color=red]$dir[/color]"> <param name="quality" value="high"> <embed src="[color=red]$dir[/color]" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"> </embed> </object> PHP: <?php $sql = "SELECT * FROM games"; $query = mysqli_query($con, $sql) or die; while ($row = mysqli_fetch_assoc($query)) {$dir = $row['path']; $game_src = $row['game_src']; echo "<h2>{$row['title']}</h2> $game_src"; } ?> HTML Source shows: <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400"> <param name="movie" value="$dir"> <param name="quality" value="high"> <embed src="$dir" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"> </embed> </object> Where am i going wrong? Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/ Share on other sites More sharing options...
Rustywolf Posted March 13, 2010 Share Posted March 13, 2010 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400"> <param name="movie" value="[color=red]<?php echo $dir ?>[/color]"> <param name="quality" value="high"> <embed src="[color=red]$dir[/color]" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"> </embed> </object> maybe? Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/#findComment-1025513 Share on other sites More sharing options...
DaiLaughing Posted March 13, 2010 Share Posted March 13, 2010 For a long time (I'm tired) I didn't get the question or the answer! I'm not sure i do now. If the question is to get $ dir to appear as a variable then it's presumably just a quoting problem unless you have sanitised the database content in a way that makes $dir look like plain text. Certainly if i mock up your code just by assigning values manually and then escape the quotes it works fine: <?php $row['title']="fred"; $dir="./fred/"; $game_src="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"550\" height=\"400\"> <param name=\"movie\" value=\"$dir\"> <param name=\"quality\" value=\"high\"> <embed src=\"$dir\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"550\" height=\"400\"> </embed> </object>"; echo "<h2>{$row['title']}</h2> $game_src"; ?> As for the answer it seems to me that what you are suggesting is something like this: echo "stuff to echo <?php echo "more stuff to echo but we're already in an echo"; ?> including php code"; Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/#findComment-1025532 Share on other sites More sharing options...
cs.punk Posted March 14, 2010 Author Share Posted March 14, 2010 Ok I'll try and explain again.. Database entry: "You are $x years old" In the actual database there is for example varible $x. In my php code i set varible $x as 50. I then echo out the database entry. But instead of saying "You are 50 years old"(which is what i want) Instead it prints a literal $x "You are $x years old". Hope i explained myself better... Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/#findComment-1025830 Share on other sites More sharing options...
DaiLaughing Posted March 14, 2010 Share Posted March 14, 2010 Try to narrow this down by commenting out the database bit for now and manually assigning the data to variables before you echo it. If that then works (obviously there will be just one object) you know it is something to do with the data in the database. If it doesn't work then maybe look at the quoting. If you want to attach the whole file I could have a look but the snippet doesn't seem to want to make sense to me for some reason (it's not your code though just my general dumbness!). Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/#findComment-1025838 Share on other sites More sharing options...
cs.punk Posted March 14, 2010 Author Share Posted March 14, 2010 It is the database! Almost as if its escaped... But in the HTML source (in a browser) its shows $dir.. So php isn't really er... whats the word? *word*.. its just echoing the actual entry.. Preg replace perhaps?.. Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/#findComment-1025880 Share on other sites More sharing options...
Instigate Posted March 14, 2010 Share Posted March 14, 2010 Just do this: Try putting Moustaches ( { } ) around your variables inside a variable. Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/#findComment-1025886 Share on other sites More sharing options...
DaiLaughing Posted March 14, 2010 Share Posted March 14, 2010 I've never heard of the curly brace thing so I'd be interested to know if it works. If not try: str_replace('$dir', $dir, $whateveryourdatafromMySQLwascalled); Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/#findComment-1025896 Share on other sites More sharing options...
cs.punk Posted March 16, 2010 Author Share Posted March 16, 2010 I've never heard of the curly brace thing so I'd be interested to know if it works. If not try: str_replace('$dir', $dir, $whateveryourdatafromMySQLwascalled); Yeah it worked and guess thats the only option.. Still see it as a waste of resources but oh well. Oh and the {} never worked so.. Link to comment https://forums.phpfreaks.com/topic/195090-php-not-printing-varible-in-echo-command/#findComment-1026869 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.