开发者

Insert long code into PHP table td

开发者 https://www.devze.com 2023-03-18 07:31 出处:网络
I\'m creating something similar to the \"wall\" on Facebook where there are comments followed by textareas to insert more comments.I have done this through a PHP generated table taking variables from

I'm creating something similar to the "wall" on Facebook where there are comments followed by textareas to insert more comments. I have done this through a PHP generated table taking variables from a mysql database:

<?php
include 'connect.php';
$get=mysql_query("SELECT * FROM table WHERE $x='comments' ORDER by rank DESC");
echo '<table>';

while ($row=mysql_fetch_assoc($get)){
 echo '<tr>';
echo "<td>开发者_如何学Python;//DIV IN HERE!</td>";
 echo '</tr>';
echo '<tr>';
echo "<td><form> ... </form></td>";
echo '</tr>';

}

echo '</table>';
?>

However, I have a div setup that I would like to place in the cell of the table. This div has sub Divs and echos information and is generally messy. I have tried to include this div into the td but I'm getting lots of errors probably because I had to change all the " to '. Is there a better way I should be approaching this? Any help is much appreciated.


Would you be able to show what your DB table looks like?

Also, I would recommend not using tables in HTML for dividing content (such as posts/comments). What would be better is using a div. So for instance, you'll want something like

<div class="postContainer">
    <div class="postMsg">Hi there</div>
    <div class="postMsgComment">Hi to you, too!</div>
    <div class="postMsgComment">I want to join the fun!!!</div>
</div>

From here, your SQL table would have a foreign key in your comments table, pointing to which "wall" post it was intended for.

tbl.Post

| PostId | UserId | Date | Message | (..)

tbl.Comment

| CommentId | PostId | UserId | Date | Message | (..)


It looks like in this case it'd be much easier to jump out of PHP into HTML markup — this way you won't need to worry about escaping ' or ".

<?php
include 'connect.php';
$get=mysql_query("SELECT * FROM table WHERE $x='comments' ORDER by rank DESC");
echo '<table>';

while ($row=mysql_fetch_assoc($get)){
    ?>
    <tr>
        <td>
            <div>
                <?php echo $something; ?>
                <div id="sub-div"></div>
            </div>
        </td>
    </tr>
    <tr>
        <td><form> ... </form></td>
    </tr>
    <?php
}

echo '</table>';
?>


Seems like a good time to use the HEREDOC string syntax

while ($row=mysql_fetch_assoc($get)){
  echo<<<HTML
  <tr>
    <td>
     <div> {$row['somevalue']} </div>
    </td>
  </tr>
  <tr>
    <td><form> ... </form></td>
  </tr>
HTML;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消