一个很好的MYSQL打印数据的想法

时间:2012-10-28 23:49:42

标签: php mysql

e.g。

id - Name - Surname - Phone - Married
1 - Ann - AnnS - 123 - No
2 - Mary - MarryS - [empty] - Yes
3 - Jane - JaneS - 321 - [empty]

现在我想通过 id 记录并打印出类似的信息(将行名改为SMTH,如果行是空的 - 不要显示行ALL ):

SELECT * FROM `girls` WHERE `id`='1'

The girls name - Ann 
The girls surname - AnnS
The girls number - 123
Is the girl married? - No

/ - /

SELECT * FROM `girls` WHERE `id`='2'

The girls name - Ann
The girls surname - AnnS
Is the girl married? - No

如果不重载服务器(表中大约有130行)怎么办?

1 个答案:

答案 0 :(得分:1)

一次选择它们

$sql = "select * from girls";

然后遍历php

中的结果集
$result = mysql_query($mysql);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "The girls name - ".$row['name'].";
     //....
}