Jump to content


Photo

Only 1 result?


  • Please log in to reply
3 replies to this topic

#1 DBookatay

DBookatay
  • Members
  • PipPipPip
  • Advanced Member
  • 334 posts
  • LocationCT

Posted 23 October 2006 - 02:23 AM

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:

<?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; ?>

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
"select * from blog_Replies where origional_id = '{$_GET['id']}' order by reply_posted DESC"
it will only return 1 result.

Can anyone help?

$result mysql_query("SELECT finger FROM hand WHERE id=3"); 
echo 
$result


#2 DBookatay

DBookatay
  • Members
  • PipPipPip
  • Advanced Member
  • 334 posts
  • LocationCT

Posted 23 October 2006 - 03:46 AM

Anyone?

$result mysql_query("SELECT finger FROM hand WHERE id=3"); 
echo 
$result


#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 23 October 2006 - 05:06 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 DBookatay

DBookatay
  • Members
  • PipPipPip
  • Advanced Member
  • 334 posts
  • LocationCT

Posted 24 October 2006 - 02:50 PM

I apprechiate the advice, but like I said I'm  new to this...
How would I make it work the proper way then?

$result mysql_query("SELECT finger FROM hand WHERE id=3"); 
echo 
$result





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users