undertaker333 Posted August 25, 2011 Share Posted August 25, 2011 why it giving me single row data?? what i m missing here ... any help wil b appreciated.. <?php $comments= ""; $result = mysql_query("SELECT * FROM comment"); while($row = mysql_fetch_array($result)) { $serials= $row['serial']; $names= $row['name']; $emails= $row['email']; $msges= $row['msg']; $date_added= $row['date']; $comments= "$names <br /> $msges <br /> $date_added"; } ?> Quote Link to comment Share on other sites More sharing options...
jcbones Posted August 25, 2011 Share Posted August 25, 2011 There is no way to help you with the code provided. We would need a database dump to see what is going on. Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 25, 2011 Share Posted August 25, 2011 Use freaking CODE or PHP tags to post your code! $comments= "";$result = mysql_query("SELECT * FROM comment"); while($row = mysql_fetch_array($result)) { $serials= $row['serial']; $names= $row['name']; $emails= $row['email']; $msges= $row['msg']; $date_added= $row['date']; $comments= "$names <br /> $msges <br /> $date_added"; } Well, you are looping through the results of your query and assigning the values to variables. But, you are not using those variables in the loop, so on each subsequent iteration of the loop it is overwriting the values using the current record. So, you must have some code after that loop that is echoing the $comment. But, since you are doing that AFTER the loop it is only showing you the last value. Quote Link to comment Share on other sites More sharing options...
undertaker333 Posted August 26, 2011 Author Share Posted August 26, 2011 Sir i m not that good in coding, could you please let me know how do that? Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 26, 2011 Share Posted August 26, 2011 Sir i m not that good in coding, could you please let me know how do that? Well, you didn't show the code that outputs the data, so I don't know what to put inside the loop. You simply need to move the code that outputs the data inside the loop. Quote Link to comment Share on other sites More sharing options...
undertaker333 Posted August 26, 2011 Author Share Posted August 26, 2011 it giving below output which is single row data, i want all rows data Undertaker tik sho o ka nah??? SHABA TAKRA SHA WARTHA 2011-08-25 18:09:03 You simply need to move the code that outputs the data inside the loop. the code which output data for me is below and its inside the loop but loop executing it only once.. $comments= "$names <br /> $msges <br /> $date_added"; in html body i just write this code <?php echo $comments; ?> may b it helps u to dig out where the problem lies. thank you for you time Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 26, 2011 Share Posted August 26, 2011 the code which output data for me is below and its inside the loop but loop executing it only once.. $comments= "$names <br /> $msges <br /> $date_added"; No. That line does not output anything. It simply defined a variable called $comments. So, on the first iteration of the loop it sets $contents equal to the variables from the first record. On the second iteration it OVERWRITES the contents fo the first record with the content of the second records. So, when the loop completes it holds the contents of only one record - the last one! So, if you are only using the variables in $comments, why do you have those other variables defined in the loop (e.g. $serials) that are not used? Anyway, you can "concatenate" the output for each record onto the results of the previous record using ".=" when defining the variable. That means to add the text to the end of the current value. $query = "SELECT name, msg, date FROM comment"; $result = mysql_query($query); $comments= ''; while($row = mysql_fetch_assoc($result)) { $comments .= "{$row['name']}<br />{$row['msg']}<br />{$row['date']}<br /><br />\n"; } Quote Link to comment Share on other sites More sharing options...
undertaker333 Posted August 26, 2011 Author Share Posted August 26, 2011 WOWWWWWWWWWWW thats work as charmm.. thanks alot for your time from now its my fav forummm... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.