从 mysql 组织 PHP 数组
你好,我有一个社交网站。
我想要它做的是提取我朋友的状态更新。
基本上它的作用是我有一个 mysql 查询,可以提取我所有的朋友,在 while 循环中,还有另一个 mysql 查询,可以从我的朋友那里提取状态。
我希望它按日期顺序排列,但由于它在另一个 while 循环中,它所做的是从朋友 1 然后 2 然后 3 中提取所有状态,而不是按日期顺序。我什至尝试过按日期订购,但只是在朋友内按日期订购。 我的想法是,我可以将所有内容放入一个数组中,朋友是一回事,值是统计数据。然后只需按值排序这是否有效以及我该如何做到这一点。
朋友和统计数据位于两个不同的表中,
非常感谢
代码:
$friendssql = mysql_query("SELECT * FROM Friends WHERE sender='$id'"); while($row = mysql_fetch_object($friendssql)) { $friendid = $row->;接受者;
$frsql = mysql_query("SELECT * FROM myMembers WHERE id='$friendid'");
while($rowa = mysql_fetch_object($frsql)) {
$ufirstname = $rowa-> firstname;
$ulastname = $rowa-> lastname;
}
$blabsql = mysql_query("SELECT * FROM blabbing WHERE mem_id='$friendid' ORDER BY blab_date DESC");
while($rowb = mysql_fetch_object($blabsql)) {
$blab = $rowb-> the_blab;
$blabd =$rowb-> blab_date;
$ucheck_pic = "members/$friendid/image01.jpg";
$udefault_pic = "members/0/image01.jpg";
if (file_exists($ucheck_pic)) {
$blabber_pic = "<img src=\"$ucheck_pic\" width=\"50px\" border=\"0\" />"; // forces picture to be 100px wide and no more
} else {
$blabber_pic = "<img src=\"$udefault_pic\" width=\"40px\" border=\"0\" />"; // forces default picture to be 100px wide and no more
}
Hi i have a social networking website.
what i want it to do is pull out my friends status updates.
basically what it does is i have a mysql query that pulls out all of my friends and in that while loop there is another mysql query that pulls out the status's from my friends.
i want it to be in order of date but since its one while loop in another what it does is pull out all status's from friend 1 then 2 then 3 and not in order by date. i even tried ORDER BY DATE but that just ordered it by date within the friend..
my thought is that i could putt it all in an array and friends is one thing and the values is the stats. then just sort by values would this work and how could i do it.
the friend and stats are in two differants tables
THANKS SO MUCH
CODE:
$friendssql = mysql_query("SELECT * FROM friends WHERE sender='$id'");
while($row = mysql_fetch_object($friendssql)) {
$friendid = $row-> accepter;
$frsql = mysql_query("SELECT * FROM myMembers WHERE id='$friendid'");
while($rowa = mysql_fetch_object($frsql)) {
$ufirstname = $rowa-> firstname;
$ulastname = $rowa-> lastname;
}
$blabsql = mysql_query("SELECT * FROM blabbing WHERE mem_id='$friendid' ORDER BY blab_date DESC");
while($rowb = mysql_fetch_object($blabsql)) {
$blab = $rowb-> the_blab;
$blabd =$rowb-> blab_date;
$ucheck_pic = "members/$friendid/image01.jpg";
$udefault_pic = "members/0/image01.jpg";
if (file_exists($ucheck_pic)) {
$blabber_pic = "<img src=\"$ucheck_pic\" width=\"50px\" border=\"0\" />"; // forces picture to be 100px wide and no more
} else {
$blabber_pic = "<img src=\"$udefault_pic\" width=\"40px\" border=\"0\" />"; // forces default picture to be 100px wide and no more
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将数据放入数组后,您可以查看 PHP 中的一些各种数组排序函数:http://php.net/manual/en/array.sorting.php
Once you've put your data into the array, you could take a look at some of the various array sorting functions in PHP: http://php.net/manual/en/array.sorting.php
为什么不在一个查询中完成这一切呢?这是伪 sql,因此您必须使用真实的表和关系进行修改。
或类似的东西。
why not do it all in one query? this is psuedo sql, so you'll have to modify with your real tables and relationships.
or something similar.