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.
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 ?
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,
1) Fetch all the record and store into a php array
$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
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()
!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.