简体   繁体   English

用户墙PHP和MYSQL

[英]User Wall PHP and MYSQL

I'm working on a big project a social networking site but now I'm stuck and i need your advice. 我正在一个社交网站的大型项目中工作,但现在遇到了麻烦,需要您的建议。

My problem is that I wan't to display everything like posts, videos and statuses into his profile.php under user timeline. 我的问题是我不会在用户时间轴下将诸如帖子,视频和状态之类的所有内容显示到他的profile.php中。

I got more than 40 Tables but let me specify what I wan't, I wan't to get data from these tables and how to display them on the profile.php timeline section ? 我有40多个表,但我要指定我不想要的东西,我不希望从这些表中获取数据以及如何在profile.php时间轴部分显示它们?

Status Table
------------------------------------------
ID   |    sMessage    |    sDate   |  uId
------------------------------------------
1    | Testing status | 2013/07/03 |   1 


Videos Table
-----------------------------------------------------
ID   |      vName     |   vCode  |    vDate   |  uId
-----------------------------------------------------
1    | PHP and MYSQL  |  2MvYwz  | 2013/07/03 |   1 


Users Table
-----------------------------------
ID   |     uName      |  JoinDate   
-----------------------------------
1    |   Tem Henov    | 2013/07/03

And here is what i tried: 这是我尝试过的:

class userTimeline {
    public function loadTimeline(){
     dbConn();
     $query = "SELECT 
                 sMessage, sDate, vName, vDate, vCode 
               FROM status
               INNER JOIN users
                 ON (status.uId = users.uId)
               INNER JOIN videos
                 On (videos.uId = users.uId)
               WHERE users.uId = '1'";

     return $result = mysql_query($query);
    }
}

and its loads the data fine but how to display that data in blocks like if its a status display in a separate block and if its a video display it in another block and how to order by date ?! 并且它可以很好地加载数据,但是如何在块中显示该数据,例如状态显示在单独的块中,视频显示在另一个块中,以及如何按日期排序? any help is appreciated. 任何帮助表示赞赏。

First : To Show data into various <div> first fetch them and show like, 首先:首先将数据显示到各种<div>然后将它们显示为

1) Fetch all the record and store into a php array 1)获取所有记录并存储到php数组中

$rows = array();
while($row = mysql_fetch_array(YOUR_QUERY))
{
    $rows[] = $row;
}

2) Now Using foreach() loop use data fetched from query where ever you want 2)现在,使用foreach()循环可在任何需要的地方使用从查询中获取的数据

if(is_array($rows)) {
    foreach($rows as $row) {
        //do with $row or create some if,switch condition here !
    }
}

For specific limits and tweaks study the result set we get from mysql_fetch_array() ! 对于特定的限制和调整,请研究我们从mysql_fetch_array()获得的结果集!

Second : To short data by date you can use multiple sorting ( click here for tutorial ) but i think you should use MYSQL UNION to merge two or more MySQL query results to get individual sorting result. 第二:要按日期缩短数据,您可以使用多种排序( 请单击此处以获取教程 ),但是我认为您应该使用MYSQL UNION合并两个或多个MySQL查询结果以获得单独的排序结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM