开发者

PHP while loop issue with associative array

I have two while loops populating associative arrays -- I can run one at a time (ie commenting the other out) however, when I run both at the same t开发者_如何学Cime I receive a server error. Despite the queries not querying the same set of data I've still tried adding a pointer reset with no luck. Here are the two loops:

$thecurrent = array();
$getusers = "SELECT score, uid, like_id FROM wetique_scores GROUP BY like_id;";
$gotusers = mysql_query($getusers,$con);


while ($row = mysql_fetch_array($gotusers))
{
    $score = $row['score'];
    $userid = $row['uid'];
    $likeid = $row['like_id'];
    $comboid = $userid.$likeid;
    $thecurrent[$comboid] = $score;
}

// 2. calculate new score from db and create array $new

$new = array();
$getusers2 = "SELECT like_id, sum(friend_rating), uid from likes l, friendships f WHERE l.friend_id = f.friend_id GROUP BY l.like_id;";
$gotusers2 = mysql_query($getusers2,$con);
while ($rowb = mysql_fetch_array($gotusers2))
{
    $scoreb = $rowb['sum(friend_rating)'];
    $useridb = $rowb['uid'];
    $likeidb = $rowb['like_id'];
    $comboidb = $useridb.$likeidb;
    $new[$comboidb] = $scoreb;   
}


1) There is no 'l_id' in selected fields of your queries, so $rowb['l_id'] or $row['l_id'] will generate Notice.

2) from l, fips f this is typo i hope?

3) Your GROUP BY l_id isn't clear. All rows with same l_id has same score, uid, like_id? Very strange.

4) Use mysql_free_result after each cycle http://ru2.php.net/manual/en/function.mysql-free-result.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜