Incrementing Array value [SOLVED]
Posted: Sun May 07, 2006 12:16 pm
I am making an accept all feature for comments for blogs. Let's say the user has 2 blogs. Blog 1 has 7 comments and Blog 2 has 3 comments.
I want to get it in an array like this
Blog ID => Number of comments for that blog
Ex:
I have this piece of code here
This code results in the following for $blogids:
When It should be:
So it looks like its not incrementing the array.
I want to get it in an array like this
Blog ID => Number of comments for that blog
Ex:
Code: Select all
Array
(
[1] => 7
[2] => 3
)I have this piece of code here
Code: Select all
// empty arrays
$final = array();
$blogids = array();
// loop through results, and store comment ids into an array ($final);
// and store a count of comments particular to each blog
// BlogID => numComments
while($checka = mysql_fetch_assoc($checkr)){
// make sure they own this comment
if($checka['userid'] == $theperson){
// they do, so add it to array
$final[] = $checka['id'];
// if the blog id is already in the array, increment the comment count for that blog id
if(in_array($checka['bid'],$blogids)){
$blogids[$checka['bid']] = $blogids[$checka['bid']] + 1;
}
// its not in the blog id array, so add it to it
else {
$blogids[$checka['bid']] = 1;
}
}
}Code: Select all
Array
(
[3] => 1
[2] => 1
)Code: Select all
Array
(
[3] => 3
[2] => 1
)