0

I want to fetch multiple rows output I know it can be done easily with while loop but my problem is that if I will use while loop the title of corresponding row will come. I just don't want to change the title but want to change the content. Here is simple data what I want

    tableA

    id                title                            msg

    1                 eeee                              frrffrfrrfrr
    2                 vvfdfd                           ffvfvdfvddd
    3                 vffdcadvg                         fdfvddfgvre
    4                 dfdf                              fvvvf

So if I will use while loop then title of that row will also come so I just want to keep changing the row['message'] value. My simple MySQL query is

   $res = mysql_query("select * from tableA");
   $row = mysql_fetch_array($res);
    $msg=$row['msg']

As you can see it will easily display title and message for corresponding row but I want title of one row and message output of 4 rows how it can be done?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
wayenjoy
  • 71
  • 1
  • 10

1 Answers1

2

Use a loop:

$res = mysql_query("select * from tableA");
while ($row = mysql_fetch_array($res)) {
    echo $row['msg'];
}

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
John Conde
  • 217,595
  • 99
  • 455
  • 496