Jump to content

Archived

This topic is now archived and is closed to further replies.

DBookatay

Only 1 result?

Recommended Posts

I'm trying to create a blog  from scratch, and I will admit that I am a "noobie" to php, so I am having a bit of trouble...
Here is a page I call "blog_view.php" where users view the post, and can add their own comments to the origional post:

[code]<?php
require_once ('include/mysql_connect.php');
$query = "select * from blog_Posts where id = '{$_GET['id']}'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){

$date = substr($row['posted'], 5, 2) . '/ ' . substr($row['posted'], 8, 2) . '/ ' . substr($row['posted'], 2, 2);
$title = $row['title'];
$text = nl2br(stripslashes($row['comments']));
if ($row['reply'] == "off")
{
$replyTitle = "&nbsp;";
$replyBox = "&nbsp;";
}
else
{
$replyTitle = "<div class=\"blgCmntsTitle\"><a name=\"add\">Reader Comments</a></div>";
$replyBox = "
<div style=\"padding: 0 0 0 50\">
<form>
<input type=\"hidden\" name=\"id\" value=\"sendPage\">
<table>
<tr><td>Name:</td></tr>
<tr><td class=\"frmPad\"><input type=\"text\" name=\"name\" class=\"text\" size=\"25\" /></td></tr>
<tr><td>Email:</td></tr>
<tr><td class=\"frmPad\"><input type=\"text\" name=\"email\" class=\"text\" size=\"25\" /></td></tr>
<tr><td>Website:</td></tr>
<tr><td class=\"frmPad\"><input type=\"text\" name=\"url\" class=\"text\" size=\"25\" /></td></tr>
<tr><td>Message:</td></tr>
<tr><td class=\"frmPad\"><textarea name=\"message\" class=\"TextArea\" cols=\"24\" rows=\"5\" wrap=\"physical\" maxlength=\"500\"></textarea></td></tr>
<tr><td class=\"frmBTN\"><input type=\"image\" name=\"submit\" src=\"images/BTN/Submit_off.gif\" srcover=\"images/BTN/Submit_on.gif\" value=\"Send\" name=\"submit\" /></td></tr>
</table>
</form>
</div>";
}
}

$query = "select * from blog_Replies where origional_id = '{$_GET['id']}' order by reply_posted DESC";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){

$reply_text = nl2br(stripslashes($row['reply_comments']));
$reply_date = substr($row['reply_posted'], 5, 2) . '/ ' . substr($row['reply_posted'], 8, 2) . '/ ' . substr($row['reply_posted'], 2, 2);
$reply_name = $row['reply_name'];
$reply_email = $row['reply_email'];
$poster = '<a href="mailto:' . $reply_email . '"><img src="images/icon_blgCmnt.gif" /> ' . $reply_name . '</a>';

$replies = "
<div class=\"blgTopicHldr\">
<table width=\"80%\">
<tr><td class=\"blgReplyText\">$reply_text</td></tr>
<tr>
<td class=\"blgReplyLnkHldr\">
<table width=\"100%\">
<tr>
<td class=\"blgReplyLnks\"><img src=\"images/icon_blgPstd.gif\" /> Posted: $date</td>
<td class=\"blgReplyLnks\">by: $poster</td>
</tr>
</table>
</td>
</tr>
</table>
</div>\n";
$row_count++;
}
if (!$row_count) {$replies = "<div class=\"blgNoPosts\">No users have posted comments yet.</div>"; }
?>

<div class="blgTopicHldr">
<table width="90%">
<tr><td class="blgTitle"><?php echo $title; ?></td></tr>
<tr><td class="blgText"><?php echo $text; ?></td></tr>
<tr><td class="blgLnkHldr">
<table width="100%">
<tr>
<td class="blgLnks"><img src="images/icon_blgPstd.gif" /> <?php echo $date; ?></td>
<td class="blgLnks">by: <a href="contact.php?body=email"><img src="images/icon_blgCmnt.gif" /> Brad Guy</a></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<?php echo $replyTitle; ?>
<?php echo $replies; ?>
<?php echo $replyBox; ?>[/code]

The code is not finished yet, (like the form to add comments doesnt work yet) so I have been adding test examples manually into my DB, but the problem is that for the second query [code]"select * from blog_Replies where origional_id = '{$_GET['id']}' order by reply_posted DESC"[/code] it will only return 1 result.

Can anyone help?

Share this post


Link to post
Share on other sites
you are selecting all your fields (the *) for every row that id equals something specific, like id = 3.  now, most people make the id field a unique field, as in, only one id per row.  is this not how your table is setup?  are you expecting more than one row to have the same id?

and btw, you should NEVER directly insert a $_GET variable into a query like that.  People can inject their own arbitrary sql code into it and do all sorts of nasty stuff to you.

Share this post


Link to post
Share on other sites
I apprechiate the advice, but like I said I'm  new to this...
How would I make it work the proper way then?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.