-1

So, here is the deal. I searched everywhere for the answer, but didn't find antyhing concrete ehough for my case, maybe i'm googling something wrong. Btw, i wanted phpmyadmin to be NOT in english, but it automatically changes back to cro... so... :/ hope you will understand enough to help me with solution...

Link to my table

TIP: I know how to get a solution through mysql, so you don't have to write those answers.

Here is the deal. This table is made by joining 2 other tables, because that was the only way to get all required data(that i must display) from one query (and that is relevant because later i will have to implement sort, which won't work otherwise).

I managed to pull out data which doesn't repeat itself with function, so this is what my solution looks by now:

1 tema1 opis1 sastanak.jpeg 2012-11-26 16:29:58 2012-11-26 17:30:00

2 tema2 opis2 sastanak.jpeg 2012-11-27 16:29:58 2012-11-29 18:30:00

3 tema3 opis3 sastanak.jpeg 2012-11-28 16:29:58 2012-11-28 17:05:00

4 tema4 opis4 sastanak.jpeg 2012-11-29 16:29:58 2013-11-29 21:42:00

and so on...

That's ok, but that is not all I need. I'm still 2 steps away.

  1. I need to count all id's, where current id is equal to previous. That means that solution would be: 5 (id_sastanka=1 appears 5 times in table) 5 (id_sastanka=2 appears 5 times), 6 (id_sastanka=3 appears 6 times), 6 (id_sastanka=4 appears 6 times) and so on.

I tried various combinations, but all give everything BUT correct result, so please help. I know the solution is in something simple, but I just can't seem to reach it. So this actually represents number of users who were invited to a meeting, by meeting's id.

  1. I need to count all id's where status=1. I know how to do all of this with mysql, so that is not the question, I need the answer in php...
    Solutions to this should be: 4 (four "1" in "status" where "id_sastanka"=1), 4 (four "1" in "status" where "id_sastanka"=2), 5 (five "1" in "status" where "id_sastanka"=3), 3 (three "1" in "status" where "id_sastanka"=4).... this represents number of users who attended those meetings.

I'm a beginner, and I really need help with this, so I hope you won't bear a grudge.

4

1 回答 1

0

我猜,您的数据的每一行都表示为数组。因此,我将为以下数据结构编写代码:

$rows = array(
    0 => array(
        'id_sastanka' => 1,
        'naziv' => 'tema1',
        'opis' => 'opis1',
        'slika' => 'sastanak.jpeg',
        'posetak' => '<...>',
        'zavrsetak' => '<...>',
        'dnevny_red' => '<...>',
        'id_korisnika' => '<...>',
        'status' => '1'
    ),
    1 => array(...),
    2 => array(...),
    ...
);

$prev_id = null;
$prev_id_counter = array();

$ids_status_counter = array();

foreach($rows as $row) {
    if ($prev_id == $row['id_sastanka']) {
        $prev_id_counter[$row['id_sastanka']] = (isset($prev_id_counter[$row['id_sastanka']])) ? ++$prev_id_counter[$row['id_sastanka']] : 1;
    }
    $prev_id = $row['id_sastanka'];

    if ($row['status'] == 1) {
         $ids_status_counter[$row['id_sastanka']] = (isset($ids_status_counter[$row['id_sastanka']])) ? ++$ids_status_counetr[$row['id_sastanka']] : 1;
    }
}

因此,在数组 $prev_id_counter 中存储第一种情况的结果和 $ids_status_counter 存储第二种情况的结果。数组的格式为 ['id_sastanka'] => 案例计数器

于 2013-10-26T15:22:47.880 回答