gpt4 book ai didi

php - 按循环查询值对mysql结果进行排序

转载 作者:行者123 更新时间:2023-11-29 09:13:26 24 4
gpt4 key购买 nike

我正在做以下事情

$def = $_GET['def']; if (!$def == 0) {$offset = 'OFFSET '.$def.'';}
$data1 = mysql_query(
"SELECT *, DATE(post_modified) as nicedate
FROM (`wp_postmeta`)
LEFT JOIN (`wp_posts`) ON wp_postmeta.post_id = wp_posts.ID
LEFT JOIN (`wp_top_ten`) ON wp_posts.ID = wp_top_ten.postnumber
WHERE meta_value='the_value'
ORDER BY nicedate DESC LIMIT 16 ".$offset.""
) or die(mysql_error());
while($info = mysql_fetch_array( $data1 ))

{
$id = $info['ID'];
echo "some stuff";
$data2 = mysql_query("
SELECT SUM(vote) as total_vote, COUNT(*) as total_count
FROM (`wp_gdsr_votes_log`)
WHERE id='".$id."' AND vote_type='article'
") or die(mysql_error());
while($info = mysql_fetch_array( $data2 ))
{$vote = number_format(
($info['total_vote']/$info['total_count'])
, 2, '.', ' ');}
echo $vote."/5"; echo "some more stuff";
}

如何对 $data1 中的结果进行排序,其中“nicedate”将是 $vote 值?

最佳答案

您可以创建要在每轮循环后填充的数组。类似于(在获取 $data1 的结果之后):

在 $data1 之前定义一个空数组。

$newarray = array();

比,在第二个循环中:

$nicedate = info['nicedate'];

$newarray[$nicedate] = $vote;

您最终会得到一个 array('date'=>'vote', 'date2' => 'vote2',..),您可以随意对其进行排序。

关于php - 按循环查询值对mysql结果进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4837200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com