By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,692 Members | 1,670 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,692 IT Pros & Developers. It's quick & easy.

How to display messages from mysql database in rows?

P: 5
Dear friends,
How can i display messages from mysql database in each rows with delete and reply button.
Thanks in advance.
Here is my code.
i have created a page like scrapbook.
and splitted the scrapbook into two,ie my scrapbook and my friends scrapbook.
$toid is active only when i visit others profile.
if $toid is blank then display my scrqapbook otherwise my friend scrapbook.
Expand|Select|Wrap|Line Numbers
  1. <td><table width="100%" height="99" border="1">
  2.              <?php 
  3.                 if($toid=="" or $toid==$id)
  4.                 {
  5.                 $rst = mysql_query("SELECT * FROM messages where toid='$id' ORDER BY id DESC")
  6.                 or die(mysql_error());  
  7.                   $count=mysql_num_rows($rst);
  8.                 while($count>0)
  9.                 {
  10.                 $count--;
  11.                 $row = mysql_fetch_array($rst);
  12.                  $delid=$row['id'];
  13.                  $x=$row['msg'];
  14.                   $from=$row['fromid'];
  15.                   $row7=fromname($from);
  16.                  $fromname=$row7['username'];
  17.                  $row4=userdata($id);
  18.                  ?>
  19.                 <?php 
  20.                   echo "<table width='100%' border='1'>
  21.                   <tr>
  22.                   <td width='10%'><a href='scrapbook.php?toid=$from'>$fromname</a></td> 
  23.                   <td width='75%'>$x<br>
  24.                   <input name='delete' type='submit' id='delete' value='Delete'>
  25.                  <input name='reply' type='submit' id='reply' value='Reply'>
  26.                   </td>
  27.                   </tr>
  28.                   </table>";
  29.                   $delid=$row['id'];
  30.                    $delete_query = "DELETE FROM messages WHERE id = '$delid'";
  31.                     if($delete){
  32.                     mysql_query($delete_query) or die(mysql_error());
  33.                     }
  34.                   $msg="Done";}} 
  35.                 else
  36.                 {
  37.                 $id=$toid;
  38.                 {
  39.                 $rst3 = mysql_query("SELECT * FROM messages where toid='$id' ORDER BY id DESC")
  40.                 or die(mysql_error());  
  41.                   $count2=mysql_num_rows($rst3);
  42.                 while($count2>0)
  43.                 {
  44.                 $count2--;
  45.                 $row3 = mysql_fetch_array($rst3);
  46.                  $delid2=$row['id'];
  47.                  $y=$row3['msg']; 
  48.                  $from=$row3['fromid'];
  49.                  $row6=fromname($from);
  50.                  $fromname=$row6['username'];
  51.                  echo "<table width='100%' height='109' border='1'>
  52.                   <tr valign='bottom'><td width='14%' height='103'>$fromname</td> 
  53.                   <td valign='top' width='86%'>$y</td>
  54.                   </tr></table>";
  55.                   }}}?></table>
  56.       *</td>
  57.  
Apr 30 '10 #1
Share this Question
Share on Google+
1 Reply


dlite922
Expert 100+
P: 1,584
Where are you stuck?
Which line of the code isn't working?

I can't write the entire code for you. I can help yo answer /specific/ questions.

Let us know,





Dan
May 6 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.