It retrieves info successfully however I wanted it in a table so I placed it between <<<_END tags. Now it gives me this error. Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\htdocs\clphp03\new_post09.php on line 118 line 118 is <td><?php echo $row['title'];?></td> Is there something I am missing? Thanks. $db = dbConnect('query'); $sql = "SELECT * FROM mammals05 WHERE postid = '$postid'"; $result = $db->query($sql)or die ($db->error); while ($row = $result->fetch_assoc()) { echo <<<_END <table> <tr> <td><?php echo $row['title'];?></td> <td><?php echo $row['email'];?></td> </tr> </table> _END; } PHP:
In the name of the kind Allah Hello, you should write like this: <td>$row['title']</td> <td>$row['email']</td> Code (markup): you do not need to open php tags again in it, its open and you can put Variables without using php tags again,
Replace while with this code. while ($row = $result->fetch_assoc()) { echo " <table> <tr> <td>" . $row['title'] . "</td> <td>". $row['email'] . "</td> </tr> </table>"; } PHP: Hope this helps.
Thanks. That removed the error and the info is displayed properly. Is this how it's normally done or is this a work around to a problem with my code? It seams a little complicated. I googled and found this, but I am still to new to fully understand it. http://www.gidforums.com/t-965.html
the problem seems solved here... but for futute reference, when you use heredocs... it is just like using "" for enclosing the string, except that we dont have to escape the " with \" so your code would look like $db = dbConnect('query'); $sql = "SELECT * FROM mammals05 WHERE postid = '$postid'"; $result = $db->query($sql)or die ($db->error); while ($row = $result->fetch_assoc()) { echo <<<_END <table> <tr> <td>[COLOR="Red"]{[COLOR="Gray"]$row['title'][/COLOR]}[/COLOR]</td> <td>[COLOR="Red"]{[COLOR="Gray"]$row['email'][/COLOR]}[/COLOR]</td> </tr> </table> _END; } Code (markup): check out for the {} used to enclose the variables. refer http://www.php.net/manual/en/language.types.string.php alternately, you can use printf command instead of echo. refer http://php.net/manual/en/function.printf.php
Thanks. Your suggestion works and it seems simpler to use. This is going to help me a lot. I will read about it in the link you provided.