I’m confused, I am running this query on a mysql database using php
SELECT mess.subject, mess.topic_id, mess.message_txt, mess.mess_id, mess.parent_id, mess.created, members.name, mess.display
FROM messages AS mess
INNER JOIN members ON members.id = mess.user_id
WHERE mess.parent_id = 3
OR mess.mess_id = 3
AND mess.display = 1
ORDER BY mess.created
I ran it in phpmyadmin and it seemed to work
heres my php
try {
$stmt = $dbh->prepare('SELECT mess.subject, mess.topic_id, mess.message_txt, mess.mess_id, mess.parent_id, mess.created, members.name, mess.display
FROM messages AS mess
INNER JOIN members
ON members.id = mess.user_id
WHERE mess.parent_id = :id
OR mess.mess_id = :id
AND mess.display = 1
ORDER BY mess.created');
$stmt->execute(array(
':id' => 3
));
while($row = $stmt->fetch()) {
echo "<div class='panel panel-default'><div class='panel-heading'>";
echo "<span class='pull-right'>";
echo "<small>Post by ".$row['name'];
echo " on ".date( 'm/d/y g:i A', strtotime($row['created']))."</small>";
echo "</span>";
echo "<h3 class='panel-title' style='margin-right:175px; font-size:150%'>".$row['subject']."</h3>";
echo "</div>\n";
echo "<div class='panel-body comment more'>".$row['message_txt'];
echo "</div>";
echo "<div class='well'>\n";
echo "<form role='form' method='post' action='reply.php'>\n";
echo "<input type='hidden' value='{$_GET['id']}' name='parent_id'>";
echo "<input type='hidden' value='{$_GET['topic']}' name='topic'>";
echo "<input type='hidden' value='".$row['topic_id']."' name='topic_id'>";
echo "<input type='hidden' value='{$_SESSION['id']}' name='u_id'>";
echo "<div class='form-group'>";
echo "<textarea class='form-control' placeholder='comment' name='comment' rows='5'></textarea>";
echo "</div>\n";
echo "<button type='submit' class='btn btn-default'>Submit</button>";
echo "</form></div>\n";
}
}
This is the result though
<div class='panel panel-default'><div class='panel-heading'><span class='pull-right'><small>Post by tom on 01/02/15 9:48 AM</small></span><h3 class='panel-title' style='margin-right:175px; font-size:150%'>Where is the...?</h3></div>
<div class='panel-body comment more'>blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah</div><div class='well well-sm'>Walk toward the El Camino Pool from the Tennis Courts and take a right<p class='text-right small'>vvv on 01/04/15 9:48 AM</p></div>
<div class='well well-sm'>Walk toward the El Camino Pool from the Tennis Courts and take a left<p class='text-right small'>vvv on 01/08/15 9:48 AM</p></div>
<div class='well'>
<form role='form' method='post' action='reply.php'>
<input type='hidden' value='3' name='parent_id'><input type='hidden' value='Welcome' name='topic'><input type='hidden' value='' name='topic_id'><input type='hidden' value='1' name='u_id'><div class='form-group'><textarea class='form-control' placeholder='comment' name='comment' rows='5'></textarea></div>
<button type='submit' class='btn btn-default'>Submit</button></form>
What confuses me is that the topic_id hidden element has no value, but the $row[‘name’] seems to work…