wayenjoy
wayenjoy

Reputation: 73

Fetch multiple row output from MySQL

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?

Upvotes: 0

Views: 1629

Answers (1)

John Conde
John Conde

Reputation: 219924

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.

Upvotes: 2

Related Questions