4 Replies - 665 Views - Last Post: 25 August 2014 - 09:06 AM Rate Topic: -----

#1 lwithwma   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-May 14

[Comment System] Database row doesn't appear more than 1

Posted 23 August 2014 - 10:15 AM

This is the Code,which i have been trying for more than 2 days
Everything is OK but it doesn't show more than 1 rows

DATABASE TABLE
Comment
c-idpost_idusertext
112AdamHello
212JohnHey

It only show Adam's "Hello" and John's "Hey" doesn't appear
Please :helpsmilie: What's wrong in this code?
Just point out the mistake rest i'll do myself.

<?php
include("connection.php");
$select=mysql_query("select * from comment ORDER BY `comment`.`post_id` DESC LIMIT 0, 6");
while($row=mysql_fetch_array($select));
$select2=mysql_query("select * from post ");
while($row2=mysql_fetch_array($select2))
{
 echo "<div id='nameid'><a href=''>$row[user]</a></div>";
 echo "<div id='msgid'>$row2[text]</div>";
 echo"<div id='msgid'>$row[user]</div>";
 echo"<div id='msgid'>$row[text]</div>";
}
?>


THANK YOU Waiting for responce!

Is This A Good Question/Topic? 0
  • +

Replies To: [Comment System] Database row doesn't appear more than 1

#2 lwithwma   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-May 14

Re: [Comment System] Database row doesn't appear more than 1

Posted 23 August 2014 - 10:23 AM

DATABASE TABLE

COMMENT

c_id post_id user text
1 12 Adam Hello
2 12 John Hey
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • Unprocessable Entity
  • member icon

Reputation: 6594
  • View blog
  • Posts: 26,833
  • Joined: 12-December 12

Re: [Comment System] Database row doesn't appear more than 1

Posted 23 August 2014 - 10:47 AM

There are two tables involved, what's in the 'post' table?

If 'post' only contains a single row then it will only print a single row of output.

(If there are more rows then it will just repeat the posts for each comment.)
Was This Post Helpful? 0
  • +
  • -

#4 chris98   User is offline

  • D.I.C Lover

Reputation: 40
  • View blog
  • Posts: 1,107
  • Joined: 06-July 13

Re: [Comment System] Database row doesn't appear more than 1

Posted 23 August 2014 - 11:25 AM

The 'mistake' is using deprecated, highly insecure MySQL functions instead of MySQLi or PDO which will secure your database queries through prepared statements.
Was This Post Helpful? 0
  • +
  • -

#5 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2091
  • View blog
  • Posts: 6,398
  • Joined: 15-January 14

Re: [Comment System] Database row doesn't appear more than 1

Posted 25 August 2014 - 09:06 AM

The $row variable will only ever contain the last record from the first query, no matter how many records it returns. That's what you're doing on line 4.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1