Jump to content

Only 1 result?


DBookatay

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?
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.