0

I am getting company interested in from my db which is something like this in my table Actor,Chief,Doctor so I used explode to make it as an array I need to put every items on this array in my HTML style to be something like this

enter image description here

as you can see from my image I need to make Actor has 50 point and then Chief has 40 point and so on

this is my PHP and HTML code

<?php
    $getInterested = $db->prepare("SELECT interest_in FROM employer_basic_info WHERE id=?");
    $getInterested->bind_param('i', $company);
    if ($getInterested->execute()) {
        $result = $getInterested->get_result();
        while ($i = $result->fetch_object()) {
            $companyInterested=$i->interest_in;
            $tat= (explode(',', $companyInterested));
            ?>

            <div class="f_left  width_100per">
                <ul class="cbp-ntaccordion f_left width_100per">
                    <li>
                        <h3 class="cbp-nttrigger font20px"><?php echo $i->interest_in ?>
                            <div title="Number of CV's" class="number3 f_left">50</div>
                        </h3>
                        <div class="cbp-ntcontent cbp-ntcontentMahmoud">
                            <ul>
                                <li>
                                    <div class="mainTable2 f_left margin_24pxBm">
                                        <div class="tablehHeader2"><span
                                                class="fieldOne2 width_35per">Employee name</span>
                                            <span class="fieldTWo2 width_20per">English Test</span> <span
                                                class="fieldThree2 width_20per">Soft Skills Test</span> <span
                                                class="fieldFour2 width_20per">IQ Test</span></div>
                                        <ul>
                                            <li>
                                                <div class="fieldOneDes2 width_35per"><a href="#">Mahmoud mamdoh
                                                        mohamed</a>
                                                </div>
                                                <div class="fieldTWoDes2 width_20per"><a href="#" class="browenLink">10/10</a>
                                                </div>
                                                <div class="fieldThreeDes2 width_20per">2/10</div>
                                                <div class="fieldThreeDes2 width_20per">N/A</div>
                                            </li>
                                        </ul>
                                        <ul>
                                            <li>
                                                <div class="fieldOneDes2 width_35per"><a href="#">PHP Web Developer</a>
                                                </div>
                                                <div class="fieldTWoDes2 width_20per"><a href="#" class="browenLink">10/10</a>
                                                </div>
                                                <div class="fieldThreeDes2 width_20per">2/10</div>
                                                <div class="fieldThreeDes2 width_20per">N/A</div>
                                            </li>
                                        </ul>
                                        <ul>
                                            <li>
                                                <div class="fieldOneDes2 width_35per"><a href="#">PHP Web Developer</a>
                                                </div>
                                                <div class="fieldTWoDes2 width_20per"><a href="#" class="browenLink">10/10</a>
                                                </div>
                                                <div class="fieldThreeDes2 width_20per">2/10</div>
                                                <div class="fieldThreeDes2 width_20per">N/A</div>
                                            </li>
                                        </ul>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </li>
                </ul>
            </div>
        <?php
        }
    }
    ?>
</div>

2 Answers 2

1

I think here you can find how to accesss your values

$companyInterested='Actor,Chief,Doctor';

list($Actor,$Chief,$Doctor)= explode(',', $companyInterested); //option 1

 echo $Actor; echo $Chief; echo $Doctor;


$tat= explode(',', $companyInterested);  //option 2

print $tat[0]; print $tat[1]; print $tat[2]; 

if the size of an array is not fixed then you can use option 2 and initialize value like $i befor start while loop as follows

$i=0;
while($value == $variale){
//some codes
$tat= explode(',', $companyInterested);
print "<div> $tat[$i] </div>";
//continue
$i++; }

or you can even loop it.

while($value == $variale){
//some codes
$tat= explode(',', $companyInterested);
forech($tat as $value){
print "<div> $value </div>"; }
//continue
$i++; }
Sign up to request clarification or add additional context in comments.

Comments

0

Try to replace

<?php echo $i->interest_in ?>

with

   <?php echo $tat[0]; ?>

or you can also do a simple formatting for friendly use.

list($actor,$chief,$doctor) = explode(',',$companyInterested);

// If $tat variable is mixed , then you have to search for a value, Actor in your case

use

$actor = array_search('Actor', $tat); // Will search for actor and return key

use it with:

<?php echo $tat[$actor]; ?>

Looping array:

$result = implode('<br/>', explode(',', $companyInterested));

5 Comments

yea I need something like this but what about the rest of the items on the array
what is coming from database is variable maybe it's four items maybe two it's not fixed
use $key = array_search('Actor', $tat); // Will search for actor and return key , then use it with <?php echo $tat[$key]; ?>
yes I need to loop the array can you please edit your answer and show me example
I think I got it thanks for the idea foreach($tat as $key){ echo "$key<br />\n"; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.