从 MySQL 获取多行输出 [英] Fetch multiple row output from MySQL

查看:64
本文介绍了从 MySQL 获取多行输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取多行输出我知道使用 while 循环可以轻松完成,但我的问题是,如果我将使用 while 循环,相应行的标题就会出现.我只是不想改变标题,但想改变内容.这是我想要的简单数据

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

因此,如果我将使用 while 循环,那么该行的标题也会出现,所以我只想继续更改 row['message'] 值.我的简单 MySQL 查询是

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']

如您所见,它可以轻松显示相应行的标题和消息,但我想要一行的标题和 4 行的消息输出怎么办?

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?

推荐答案

使用循环:

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

请不要在新代码中使用mysql_*函数一>.它们不再维护并正式弃用.看到红框?了解准备好的语句,并使用PDOMySQLi> - 这篇文章 将帮助您决定哪个.如果您选择 PDO,这里有一个很好的教程.

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.

这篇关于从 MySQL 获取多行输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆