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?

2
  • So you want msg and title for the first row and only msg for subsequent rows? Not sure if I fully understand. Commented Feb 25, 2013 at 20:06
  • mysql_* is deprecated , avoid them Commented Mar 22, 2013 at 1:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Why you're using mysql_fetch_array instead of mysql_fetch_assoc?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.