Taher Posted December 15, 2006 Share Posted December 15, 2006 Hello I am a newbie who unfortunatl bought a crappy book so there's no help for me there, I hope somone here has the time to spare..here is a snippet of my code:$result = mysql_query("SELECT * FROM taher_artikel");while($row = mysql_fetch_array($result)) { echo $row['titel'] . " " . $row['text']; echo "<br />"; echo " <div class=\"post\"> <h1> $row['titel'] </h1> <div class=\"box\">$row['text'] </div> </div> <div class=\"stripe\"> datum xxxxxx tid xxxx </div> "; }I know that the above code is wrong in <h1> $row['titel'] </h1> <div class=\"box\">$row['text'] </div>I have altered it in all ways I thought possible but can't figure it out. Help would be very apreciated! Link to comment Share on other sites More sharing options...
jesh Posted December 16, 2006 Share Posted December 16, 2006 Are you sure there is a column in your database entitled "titel"? Or should it be "title"? Link to comment Share on other sites More sharing options...
Taher Posted December 16, 2006 Author Share Posted December 16, 2006 Are you sure there is a column in your database entitled "titel"? Or should it be "title"?Yea, the code is written in swedish..this code:{ echo $row['titel'] . " " . $row['text']; echo "<br />";}displays the correct thing. As far as I understand it's only when I try to place the within the <h1> tagthat it stops working.. I think it has something to do with me missplacing . or " somewhere.. but I think I have tried all (or most) of the possible ways to place them, that makes sence to me anyways..hehe, guess I shouldn't say that the code is in swedish as most of the code is in english.. but the database is in swedish..and thank you for your very fast reply!this code:$result = mysql_query("SELECT * FROM taher_artikel");while($row = mysql_fetch_array($result)) { echo $row['titel'] . " " . $row['text']; echo "<br />"; echo " <div class=\"post\"> <h1> " $row['titel'] . " </h1> <div class=\"box\">text </div> </div> <div class=\"stripe\"> datum xxxxxx tid xxxx </div> "; }gives me this error:Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/virtual/taher.se/public_html/visa.php on line 50where line 50 is the <h1>... lineI can't believe it!! I solved, kind of.. I don't think this is the riht way to do it but it works.. I wouldn't mind if someone who knows 'corrects' it for me.. but here is my solution to anyanone who as the same problem..$result = mysql_query("SELECT * FROM taher_artikel");while($row = mysql_fetch_array($result)) { echo $row['titel'] . " " . $row['text']; echo "<br />"; echo " <div class=\"post\"> <h1> "; echo $row['titel'] . " </h1> <div class=\"box\">text </div> </div> <div class=\"stripe\"> datum xxxxxx tid xxxx </div> "; } Link to comment Share on other sites More sharing options...
liuyang Posted December 17, 2006 Share Posted December 17, 2006 <?php$result = mysql_query("SELECT * FROM taher_artikel");while($row = mysql_fetch_array($result)){echo <<<EOF{$row['titel'] }. " " . {$row['text']}<br /><div class=\"post\"><h1> {$row['titel']}</h1><div class=\"box\">{$row['text']}</div></div><div class=\"stripe\">datum xxxxxx tid xxxx</div>EOF;}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted December 18, 2006 Share Posted December 18, 2006 That's almost right, but you're mixing the different string syntaxes. Heredoc syntax doesn't need escaped quotes or string concatenation.Here is what you originally had, with some brackets added for clarity: echo "<div class=\"post\"><h1> {$row['titel']}</h1><div class=\"box\">{$row['text']}</div></div><div class=\"stripe\">datum xxxxxx tid xxxx</div>"; That should print what you expect. When you have arrays inside a string, you need to surround them with the curly brackets. And here is the heredoc syntax to print the same thing: echo <<<EOF{$row['titel']} {$row['text']}<br /><div class="post"><h1> {$row['titel']}</h1><div class="box">{$row['text']}</div></div><div class="stripe">datum xxxxxx tid xxxx</div>EOF; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now