0

Hi All
I am running an sql query to obtain the data for $CaseStudyTitle[] = $row['CaseStudyTitle']; located in the while loop and passed as parameters to the fucntion below. Currently I am displaying only one case study title at anytime. The partner can have many case studies titles how can I display all case study titles for each partner this in the function.

If you have any question please don't hesitate to reply

Thanks in advance

D

                while($row = mysql_fetch_array($result))
                       {
                            $partners_id[]= $row['web_customised_partners_id'];
                            $image_value[] = $row['image_id'];
                            $image_filename_value[] = $row['image_filename'];
                            $description_value[] = $row['description'];
                            $url_value[] = $row['url'];
                            $case_study_id[] = $row['web_customised_partners_case_study_id'];
                            $CaseStudyTitle[] = $row['CaseStudyTitle'];
                            $active[] = $row['active'];
                            $show_in_banner[]=$row['show_in_banner'];
                       }
                $index=0;
                function partnerDescription($partner, $description, $url, $case_study_id, $CaseStudyTitle)
                {
                    $result  = "<div class='partner_description' id='partner_description_{$partner}'>";
                    $result .= "<p class='about_customised_partner'>{$description}<br /><br />";
                    $result .= "<a href='http://{$url}' target='blank'>{$url} </a><br /><br /><a href='/About_ASDAN/Case_Studies/".$case_study_id."'> {$CaseStudyTitle}</a></p>";
                    $result .= "</div>";
                    return $result;
                }

                    foreach ($image_value AS $index => $image_values)
                        {

                            echo "<div class='partner_image ' id='partner_" .$partners_id[$index]. "'>";
                            echo "<a href='#' class='show_hide' rel='#slidingDiv'><img src ='/media/library/". $image_filename_value[$index]."' ></a>";
                            echo "</div>";
                            $x++;
                            $remainder = $x % 5;
                                if ($remainder ==0 )
                                    {
                                        echo "<div class='clear'><!----></div>";
                                    }
                                if ($x >4 )
                                    {
                                       for ($i=$index-4; $i<=$index; $i++)
                                           {
                                               echo partnerDescription($partners_id[$i], $description_value[$i], $url_value[$i], $case_study_id[$i], $CaseStudyTitle[$i]);

                                           }
                                        echo "<div class='clear'><!----></div>";// clear div after every 5 iterations

                                     $x=0;// reset iteration
                                    }

                            }// end of for loop

                    if($remainder !=0)

                    {
                        for ($i=$index-$x+1; $i<=$index; $i++)
                        {
                            echo partnerDescription($partners_id[$i], $description_value[$i], $url_value[$i],$CaseStudyTitle, $case_study_id[$i], $CaseStudyTitle[$i]);

                        }
                    }
              ?>
            </div>
         </div>
      </div>
    <?php
    }
}
4
Contributors
12
Replies
62
Views
4 Years
Discussion Span
Last Post by davidjennings
0

Currently I am displaying only one case study title at anytime. The partner can have many case studies titles how can I display all case study titles for each partner this in the function

On line 54 why you have 2 $CaseStudyTitle? Shouldn't it be only 1 $CaseStudyTitle?

This line:

echo partnerDescription($partners_id[$i], $description_value[$i], $url_value[$i],$CaseStudyTitle, $case_study_id[$i], $CaseStudyTitle[$i]);

It should be 1 $CaseStudyTitle not 2. Take out $CaseStudyTitle and leave $CaseStudyTitle[$i].

Your code should look like this now:

echo partnerDescription($partners_id[$i], $description_value[$i], $url_value[$i], $case_study_id[$i], $CaseStudyTitle[$i]);

Then run the code again. Then tell us what other errors you got.

Edited by LastMitch

0

HI LastMitch thanks for your reply.

The way it currently works is that on line 40 produces 5 iterations and then delivers a div clear tag <div class='clear'><!----></div> On line 54 this takes care of of total count if less than the 5 iteration.

That said all the functional is working , but how to echo out multiple case studies for each partner based on partner ID

On lin 18 in the function currently that produceses the this value <a href='/About_ASDAN/Case_Studies/".$case_study_id."'> {$CaseStudyTitle}</a> once but needs to read db and collect each case study allocated to each partner. I am not sure if an additional mutliple array is need while creating a single array for $CaseStudyTitle on line 9 to capture all the case studies allocated to each partner and how that can be done

thanks

David

0

Hi,

Please forgive me if I having doubts about these codes (shown below)... maybe this is right and I am definitely wrong. I am not sure though, maybe I was asleep at school when they cover this type of indexer...honestly,

while($row = mysql_fetch_array($result))
    {
    $partners_id[]= $row['web_customised_partners_id'];
    $image_value[] = $row['image_id'];
    $image_filename_value[] = $row['image_filename'];
    $description_value[] = $row['description'];
    $url_value[] = $row['url'];
    $case_study_id[] = $row['web_customised_partners_case_study_id'];
    $CaseStudyTitle[] = $row['CaseStudyTitle'];
    $active[] = $row['active'];
    $show_in_banner[]=$row['show_in_banner'];
    }

Can you test it just this part, and try echoing items in the array?.. For instance, we can test it like

echo  $partners_id;

which is according to your codes it is equivalent to $row['web_customised_partners_id'];

The reason I am asking you test it this way because, I have the assumption (again might be wrong again), it should bring me an **Array to string conversion ** error, unless the error reporting is totally suppressed.

Edited by veedeoo: info added

0

Hi Lastmitch - thanks for the heads up on the additional value on that line.

Hi veedeoo

I have echoed the $partner_id and it reuturned array array array array array as i would expect when creating an array[].

I then used echo $row{'web_customised_partners_id'}; and it displayed the id numbers.

What i need to know is how to create an array when a partner has many case studies should I do a foreach loop on line 18 around the a link for casestudies.<a href='/About_ASDAN/Case_Studies/".$case_study_id."'> {$CaseStudyTitle}</a></p>";

Thanks

D

0

I've only just scanned this, so forgive me if I've got the wrong end of the stick.

You want a maximum of 5 titles per partner? Ensure you order by partner_id

If so you could use a subquery using a LIMIT 5 in your sql. Then in your while loop, you check for the partner_id and if it changes you insert the clear tag:

$id = 0;
$output = '';
while(...){
    $partner_id = $row['partner_id'];
    if($id != $partner_id){
        if($id != 0){
            $output .= "...end div tag...";            
            $output .= "...clear tags...";
        }
        $output .= "...start new div..."
    }
    $output .= "...rest of your tags for each record...";

    $id = $partner_id
}
$output .= "...end div tag...";

Where appropriate:

echo $output;

I realise that you've used functions to create output - fine - you can still use them from within the loop. Code not tested - off top of head.

Edited by diafol

0

Hi Diafol - thank you for your reply. That is exactly what I wish to do, I am a little new to this

Not sure where the code is sitting, is it replacing the current while statement starting on line 1 and I suppose that I am abandoning the function usage or does the code structure replace all the code.

Thanks

D

0

I'm just showing you a way to do everything with the loop. How you decide to populate data within that loop is up to you - you can write it directly into the loop itself or you can place function calls to paste in the html as relevant places.

The SQL will be your biggest issue though. It's not as simple as you may imagine.

SELECT * 
FROM 
(
    select partner_id, ...other fields...,
    @num := if(@partner_id = partner_id, @num + 1, 1) as row_number,
    @partnerid := partner_id as dummy
    from table
    INNER JOIN (SELECT @partner_id:=0)c
    INNER JOIN (SELECT @num:=0)d
    group by partner_id, ...some other fields...

) a
WHERE row_number < 5

Modified from: http://stackoverflow.com/questions/7285901/mysql-limit-rows-per-group-weird-results

Not tested.

0

Hi Diafol thank you for your reply. I have been working with the data you provided an this is the result. The SQL is complaining about a syntax error on the first INNER JOIN (INNER highlighted in red) I have looked at the link you provided and the manual but could not find anything obvious in the code.

If you have any further throughts on this it would be appreciated

Thanks in advance

D

set @num := 0, @partners_id := '';
SELECT 

    web_customised_partners.web_customised_partners_id,
    web_customised_partners.image_id,
    web_customised_partners.partner_name,
    web_customised_partners_case_study_id,
    web_case_study.CaseStudyID,
    web_case_study.CaseStudyTitle,
    description,
    url,
    web_images.image_id,
    web_images.image_filename,
    active,
    show_in_banner,
    @num := if(@partners_id = partners_id, @num +1,1) as row_number,
    @partners_id := partners_id as dummy
FROM

    (
    INNER JOIN   ( SELECT @partners_id : = 0)
    INNER JOIN   ( SELECT @num:=0)



GROUP BY

web_customised_partners.image_id

 )
WHERE row_number < 5;
0

We can also store the output into array for external use.. something like this

$output = array();
while($row = mysql_fetch_array($result)){

    $output[]= $row;

}

Then we can loop through that array ..each item can be matched, sorted against anything that you feel appropriate.

foreach($output as $item){

echo $item['web_customised_partners_id'];

## do the rest as needed


}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.