0

I would like to create a list of actors.

Actors added to database in this way Jhone Jhones, Tom Boras and e.t.c..

All actors in one line in database separated with ","

| And I have result:

Roles: Jhone Jhones, Tom Boras

The idea is to create a separate PHP file with a list of actors which will be used like:

IF Jhone Jhones replace with <img src="roles/JhoneJhones.jpg" >

Thank you.

This is what I have (ONLY IDEA): DO NOT KNOW how to get information from $row['vidRoles'] and insert it to array. This one question.

$array = array("Jhone Jhones","Tom Boras");

Then:

IF index[0] == to Jhone Jhones{
 replace(index[0] to <img src="roles/JhoneJhones.jpg">
}

EDIT:

I have this idea:

  $query = "SELECT vidRoles FROM videoinformation";

    if ($result = mysqli_query($con, $query)) {

        while ($row = mysqli_fetch_row($result)) {
            printf ("<img src=\"roles/%s.jpg\>", $row[0]);
        }

        mysqli_free_result($result);
    }

In one (each)vidRole field in database, I have all together divided with comma Name1,Name2,Name3.

How using this code which I showed before, take each field divided each field like:
From Name1,Name2,Name3 to:
Name1
Name2
Name3
I mean separate variables.

Finally what I need using Name1,Name2,Name3 to:

<img src="roles/Name1.jpg>
<img src="roles/Name2.jpg>
<img src="roles/Name3.jpg>
5
  • What did you try so far? Your question seems to be off-topic because of being to broad as it is Commented Nov 2, 2014 at 22:25
  • I'm not sure how to do it. I have basic knowledge and topics like this: stackoverflow.com/questions/9988542/php-replace-text-with-image. Commented Nov 2, 2014 at 22:27
  • The idea is that the list of actors displays using this statement $row['vidRoles'] from database. Commented Nov 2, 2014 at 22:29
  • So if I have $row['vidRoles'] actors in one line... some how need to separate them and check each one if any of them are exist in roles.php file and if exist.... replace with image code..... this is really confuse me... Commented Nov 2, 2014 at 22:31
  • So... what did you try so far? Post it all in the question. Read this: stackoverflow.com/help/how-to-ask Commented Nov 2, 2014 at 22:35

1 Answer 1

1

Here is some code to get you started:

$vidRole  = 'Name1,Name2,Name3,Name4,Name5';
$strImg = '';
foreach(explode(',', $vidRole) as $name) {
    $strImg .= "<img src='roles/$name'>\n";
}
echo $strImg;

The output is:

<img src='roles/Name1'>
<img src='roles/Name2'>
<img src='roles/Name3'>
<img src='roles/Name4'>
<img src='roles/Name5'>

I hope this is what you need!

Sign up to request clarification or add additional context in comments.

Comments

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.