如何使用PHP从MySQL显示字幕中的多个新闻 [英] how to show multiple news in marquee from mysql using php

查看:57
本文介绍了如何使用PHP从MySQL显示字幕中的多个新闻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从mysql检索数据以显示在选框中时遇到问题,当我转到我的网页时,它仅显示从marquee中的数据库中取一个数据.我的问题是如何检索所有存储的数据.谢谢 下面是代码部分:

i have a problem to retrieve data from mysql to show in marquee,when i go to my webpage it shows only one data from the database in marquee.my question is how to retrieve all the stored data.thank you below is the code section:

$select="SELECT newsid, headlines from news WHERE uploaddate order by uploaddate desc limit 4";
$rsd=mysql_query($select);

while($row = mysql_fetch_array($rsd))
{
    $newsid=$row['newsid'];
    $tittle=$row['headlines'];
    $uploaddate=$rowdata['uploaddate'];
}

推荐答案

仅一个数据"是什么意思?

What do you mean with "only one data" ?

也许问题在这里

while($row = mysql_fetch_array($rsd))
{
    $newsid=$row['newsid'];
    $tittle=$row['headlines'];
    $uploaddate=$rowdata['uploaddate'];
}

这样,您将一遍又一遍地覆盖变量,因此在循环结束时,您将仅获得最后一条记录值.

With this you'll overwrite the variables over and over again, so at the end of the loop, you'll get only last record values.

一种可能的解决方案是制作一个数组(数组)并将数据存储到其中.

A possible solution is to make an array (of array) and store data into it.

所以

$result = array()
while($row = mysql_fetch_array($rsd))
{
    $result[] = array('news_id' => $row['newsid'],
                      'title' => $row['headlines'],
                      'upload_date' => $rowdata['uploaddate']);
}

这篇关于如何使用PHP从MySQL显示字幕中的多个新闻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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