MySQL查询拉一行并显示结果的第一个字母 [英] MySQL query pulling one row and displaying first letter of result
本文介绍了MySQL查询拉一行并显示结果的第一个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为我需要基本的PHP/MYSQL刷新,因为没有任何工作适用于我.
I think I need a basic PHP / MYSQL refresh, because nothing is working for me.
我的MYSQL表有两行信息.
My MYSQL Table has two rows of information.
$results = mysql_query("SELECT Name, Description FROM products");
$results = mysql_fetch_assoc($results);
print_r($results);
打印此文件时,我得到的只是一个结果. Array ( [Name] => Banana [Description] => It's a lovely banana )
.该表中肯定有两个结果.为什么会这样?
When printing this, all I get is one result. Array ( [Name] => Banana [Description] => It's a lovely banana )
. There are definitely two results in the table. Why is this happening?
第二,此循环仅返回每个结果的首字母,我不知道为什么!
Secondly, this loop only returns the first letter of each result, and I don't know why!
foreach($results as $res) {
?>
Name : <?php echo $res['Name']; ?><br />
Description : <?php echo $res['Description']; ?><br />
<?php } ?>
今天我的大脑严重混乱:(
My brain is seriously scrambled today :(
推荐答案
while($res = mysql_fetch_assoc($results)){
?>
Name : <?php echo $res['Name']; ?><br />
Description : <?php echo $res['Description']; ?><br />
<?php } ?>
这篇关于MySQL查询拉一行并显示结果的第一个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文