在MySQL和PHP中按ID显示特定列

时间:2022-06-18 22:44:51

I have problem (i think for you is simple to solve) with PHP and MySQL. I have database, that call "tekst". There is 3 column:

使用PHP和MySQL,我有问题(我觉得你很容易解决)。我有数据库,称为“tekst”。有3列:

  1. id (autoincrement),
  2. date (timestamp),
  3. tresc (text)

and the site: index.html. I want to paste code like that <?php echo "$id1"; ?> into index.html to display a column "treść" assigned to some "id".

和网站:index.html。我想粘贴代码 进入index.html以显示分配给某个“id”的列“treść”。

Now I do like that:

现在我喜欢这样:

$w = mysql_fetch_array(mysql_query("SELECT * FROM tekst WHERE id=5"));

$ w = mysql_fetch_array(mysql_query(“SELECT * FROM tekst WHERE id = 5”));

echo $w['tresc'];

but when I have many records, it will be troublesome.

但是当我有很多记录时,它会很麻烦。

How to create MySQL Query to display what i want ? In one page i will have many ID's.

如何创建MySQL Query来显示我想要的内容?在一个页面中,我将有许多ID。

Please help Thanks

请帮忙谢谢

3 个解决方案

#1


1  

Try using mysql_fetch_row.

尝试使用mysql_fetch_row。

example

mysql_fetch_row(mysql_query("SELECT * FROM tekst WHERE id=1"));

Official Document

#2


0  

You can do it like the following

您可以像下面这样做

$result = mysql_query("SELECT * FROM tekst");

while ($r = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo $r['tresc'];
}

#3


0  

First of all, you should use PDO or MySQLi as those mysql_ functions are deprecated.

首先,您应该使用PDO或MySQLi,因为这些mysql_函数已被弃用。

And then, to list all the ids, use a different query:SELECT * FROM tekst

然后,要列出所有ID,请使用不同的查询:SELECT * FROM tekst

Which will return an array you should iterate.

这将返回一个你应该迭代的数组。

#1


1  

Try using mysql_fetch_row.

尝试使用mysql_fetch_row。

example

mysql_fetch_row(mysql_query("SELECT * FROM tekst WHERE id=1"));

Official Document

#2


0  

You can do it like the following

您可以像下面这样做

$result = mysql_query("SELECT * FROM tekst");

while ($r = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo $r['tresc'];
}

#3


0  

First of all, you should use PDO or MySQLi as those mysql_ functions are deprecated.

首先,您应该使用PDO或MySQLi,因为这些mysql_函数已被弃用。

And then, to list all the ids, use a different query:SELECT * FROM tekst

然后,要列出所有ID,请使用不同的查询:SELECT * FROM tekst

Which will return an array you should iterate.

这将返回一个你应该迭代的数组。