georgee.b Posted February 12, 2009 Share Posted February 12, 2009 hi i have this problem i have data coming in from the database and i am fetching it into an array then i am trying to use one of its values as a div name and it does not put double quotes around it while ($row = mysql_fetch_array($result)) { echo "<div id=" .\"$row['arena']\" ">"; echo .$row['date']; echo "</div>"; } can someone tell me why am i escaping it wrong and how should it be escaped so that the div would print normally <div id="arena">date</div> thank you Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/ Share on other sites More sharing options...
samshel Posted February 12, 2009 Share Posted February 12, 2009 echo "<div id= "\".$row['arena']."\">"; works? Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/#findComment-760805 Share on other sites More sharing options...
premiso Posted February 12, 2009 Share Posted February 12, 2009 echo "<div id=\"{$row['arena']}\">"; Should take care of you. Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/#findComment-760814 Share on other sites More sharing options...
georgee.b Posted February 21, 2009 Author Share Posted February 21, 2009 thank you i have tried this, but it still does not seem to be working any other thoughts.... thanks Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/#findComment-767919 Share on other sites More sharing options...
Cal Posted February 21, 2009 Share Posted February 21, 2009 echo "<div id='".$row['arena']."'>"; I'm pretty sure that'll work. Also, this line echo .$row['date']; needs no dot before the veriable, so use: echo $row['date']; Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/#findComment-767920 Share on other sites More sharing options...
Philip Posted February 21, 2009 Share Posted February 21, 2009 My preferred way when coding: echo '<div id="',$row['arena'],'">'; Tweak on samshel's (the 1st escaping slash was in wrong spot): echo "<div id= \"".$row['arena']."\">"; And premiso's should take care of you too echo "<div id=\"{$row['arena']}\">"; Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/#findComment-767926 Share on other sites More sharing options...
Cal Posted February 21, 2009 Share Posted February 21, 2009 echo '<div id="',$row['arena'],'">';/ What diference do the commas have? Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/#findComment-767930 Share on other sites More sharing options...
Philip Posted February 21, 2009 Share Posted February 21, 2009 It passes the variables/strings as parameters instead of by concatenation into one string. I also changed the type of quotes - personally I think it's easier to read it that way (just my opinion) Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/#findComment-767932 Share on other sites More sharing options...
jackpf Posted February 21, 2009 Share Posted February 21, 2009 Wow, I didn't actually know you could use commas, I always use full stops- echo '<div style='.$row['style'].'"> etc... Link to comment https://forums.phpfreaks.com/topic/144993-cannot-insert-a-div-name-double-quotes/#findComment-768007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.