Aaron4osu Posted December 24, 2011 Share Posted December 24, 2011 I'm trying to input the results from a query into html, but I'm just getting the variable names rather than their values. I used single quotes for the echo statement, but I think I must need to switch to double to do that. But then I have problems with the double quotes from the class names (ex. class="SideBoxTitle"). <?php // get user's videos from database $conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error()); $query = "SELECT * FROM haas12_test.videos"; $result = mysqli_query($conn, $query) or die ("Couldn't execute query."); while($row = mysqli_fetch_assoc($result)) { extract($row); echo ' <div id="topBox" class="mainVideoSideBoxes" > <div class="SideBoxTitle" ><h3> $vidtitle </h3> </div><!-- close SideBoxTitle --> <div class="sideBoxVidContainer"> <div class="SideBoxScreenCast" > $vidurl </div><!-- close SideBoxScreenCast --> <div class="SideBoxDesc" ><p> $viddesc </p> </div><!-- close SideBoxDesc --> </div><!-- close sideBoxVidContainer --> </div><!-- close mainVideoSideBoxes --> </div><!-- close mainVideoSideBoxes --> '; // end echo staement } ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 24, 2011 Share Posted December 24, 2011 Variables are only parsed in a string that is defined with double quotes or the heredoc method of defining strings. You can use the double quotes to define your string and single quotes around the html tag parameter values or you can escape the double quotes around the tag parameters. //Use single quotes for html parameters echo "< img src='{$row['image_source']}' />"; //Escape double quotes for html parameters echo "< img src=\"{$row['image_source']}\" />"; Of if you don't want to use single-quotes and you don't want to escape look into the heredoc method: http://www.php.net/manual/en/language.types.string.php Quote Link to comment Share on other sites More sharing options...
Aaron4osu Posted December 24, 2011 Author Share Posted December 24, 2011 Thanks! That fixed that part, but I tried to do the same think here and it isn't working. $query = "SELECT * FROM haas12_test.videos where username = \"$username\""; It works if I substitute $username for an actual username from the database. I read the link you posted on the heredoc method but it didn't understand it. Quote Link to comment Share on other sites More sharing options...
litebearer Posted December 24, 2011 Share Posted December 24, 2011 try... $query = "SELECT * FROM haas12_test.videos where username = '$username'"; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 24, 2011 Share Posted December 24, 2011 Assuming you aren't getting any errors, if the query works when you hard code a value in, but not when you use a variable, then the variable probably doesn't contain the value you think it does. Echo the query string and see. Quote Link to comment 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.