Home > Backend Development > PHP Tutorial > How to simplify the query in the while loop?

How to simplify the query in the while loop?

WBOY
Release: 2016-09-14 09:24:01
Original
1084 people have browsed it

I will post the complete syntax here, please identify it with mysql masters

<code>$gettimeline = mysql_query("SELECT * FROM `timeline`
LEFT JOIN `users_profile` USING (id)
ORDER BY `addtime_timeline`  DESC
");
</code>
Copy after login

The above is to find the timeline data table and arrange it by addtime_timeline

<code>while ($row=mysql_fetch_array($gettimeline)){ 
印出timeline的欄位資料
}
</code>
Copy after login

The above is the cycle for printing timeline data

In the loop I will add query as follows

<code>while ($row=mysql_fetch_array($gettimeline)){ 

$GETthumb1 = mysql_query("SELECT * FROM `timeline_thumb`
WHERE `id` = '".$_SESSION['userid']."'
AND `by_timeline_id` = '".$row['timeline_id']."'
AND `thumb_type` = '1'
");

$pub_GETthumb1 = mysql_query("SELECT * FROM `timeline_thumb`
WHERE `by_timeline_id` = '".$row['timeline_id']."'
AND `thumb_type` = '1'
");

$pub_GETinfo = mysql_query("SELECT * FROM `timeline_thumb`
JOIN `users_profile` USING (id)
WHERE  `by_timeline_id` = '".$row['timeline_id']."'
ORDER BY `addtime_thumb` DESC
");

$get_comment = mysql_query("SELECT * FROM `timeline_comment`
JOIN `users_profile` USING (id)
WHERE `re_timeline_id` = '".$row['timeline_id']."' 
ORDER BY `addtime_comment` DESC ");

$get_comment_num = mysql_query("SELECT * FROM `timeline_comment`
WHERE `re_timeline_id` = '".$row['timeline_id']."'
");

}
</code>
Copy after login

GETthumb1 is to find out how many transactions the id (by_timeline_id) matches the timeline (timeline_id) in the timeline_thumb data table (to capture how many transactions the user has).
pub_GETthumb1 shows how many transactions there are in total.
pub_GETinfo is to capture the user's information corresponding to users_profile (id).
get_comment is to capture the number of ids (re_timeline_id) that match timeline (timeline_id) in the timeline_comment data table and capture the user's information corresponding to users_profile (id).
get_comment_num is to get the total number of transactions.

Is there room to simplify mysql queries? ........

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template