Jump to content

Recommended Posts

Hey guys. I have a folder with 3 images in, first.jpg, second.jpg, third.jpg.

These images are going to be used for 1st 2nd and 3rd place on my site.

 

<table align="center" width="100%"style='border: 1px dotted;'bgcolor="#eeeeee" >
<tr><td><?echo "<a href=\"userprofile.php?user=$user\"><b>$user</b></a>\n";?></td></tr>
<tr><td><?echo "at $final_date on $final_date2\n";?></td></tr>
<tr bgcolor="#ffffff"><td><?echo "$comment\n";?></td></tr>
<tr><td><? echo "$type\n";?></td></tr>
</table><br>

 

So this is the code for the table on my site. The $type variable is what I need the images to be linked to. So when it returns "league1", i need it to show the image "first.jpg", and league 2 , second, league 3 , third.

 

How can I go about doing this?

Link to comment
https://forums.phpfreaks.com/topic/165619-solved-displaying-images/
Share on other sites

if ($type == 'league1')
echo "<img src=\"images/awards/first.jpg\"></img>";
else if ($type == 'league2')
echo "<img src=\"images/awards/second.jpg\"></img>";

 

this works for so far, but how can i add this into a variable or some way where i dont have to write this in every place i want the medal to appear?

but how can i add this into a variable or some way where i dont have to write this in every place i want the medal to appear?

create a function instread.

 

function show_league_image($type)
{
   $images = array ( 'league1' => 'first.jpg',
                     'league2' => 'secound.jpg',
                     'league3' => 'third.jpg'
                   );

    if(array_key_exists($type, $images))
        return '<img src="images/awards/'.$images[$type].'" />';

    return false;
}

 

Now to display the images you call the function

 

<tr><td><? echo show_league_image($type) ?></td></tr>

but how can i add this into a variable or some way where i dont have to write this in every place i want the medal to appear?

create a function instread.

 

function show_league_image($type)
{
   $images = array ( 'league1' => 'first.jpg',
                     'league2' => 'secound.jpg',
                     'league3' => 'third.jpg'
                   );

    if(array_key_exists($type, $images))
        return '<img src="images/awards/'.$images[$type].'" />';

    return false;
}

 

Now to display the images you call the function

 

<tr><td><? echo show_league_image($type) ?></td></tr>

 

Hanging around WordPress to much? ;)

but how can i add this into a variable or some way where i dont have to write this in every place i want the medal to appear?

create a function instread.

 

function show_league_image($type)
{
   $images = array ( 'league1' => 'first.jpg',
                     'league2' => 'secound.jpg',
                     'league3' => 'third.jpg'
                   );

    if(array_key_exists($type, $images))
        return '<img src="images/awards/'.$images[$type].'" />';

    return false;
}

 

Now to display the images you call the function

 

<tr><td><? echo show_league_image($type) ?></td></tr>

 

Hanging around WordPress to much? ;)

??? No, never used it.

but how can i add this into a variable or some way where i dont have to write this in every place i want the medal to appear?

create a function instread.

 

function show_league_image($type)
{
   $images = array ( 'league1' => 'first.jpg',
                     'league2' => 'secound.jpg',
                     'league3' => 'third.jpg'
                   );

    if(array_key_exists($type, $images))
        return '<img src="images/awards/'.$images[$type].'" />';

    return false;
}

 

Now to display the images you call the function

 

<tr><td><? echo show_league_image($type) ?></td></tr>

 

Hanging around WordPress to much? ;)

??? No, never used it.

 

Strange, you then applied the exact same logic WordPress applies to their functions as the way they deploy the functions. You are one kick-ass programmer, then? ;)

$type=$row['awardtype'];
$comment=$row['awardcomment'];
$awarddate=$row['awarddate'];
           
$date=strtotime($awarddate);
$final_date=date("g:i a", $date);  
$final_date2=date("F j Y", $date);

function show_league_image($type)
{
   $images = array ( 'league1' => 'first.jpg',
                     'league2' => 'second.jpg',
                     'league3' => 'third.jpg'
                   );

    if(array_key_exists($type, $images))
        return '<img src="images/awards/'.$images[$type].'" width="20" height="45" />';

    return false;
}

?>


<table align="center" width="100%"style='border: 1px dotted;'bgcolor="#eeeeee" >
<tr><td><?echo "<a href=\"userprofile.php?user=$user\"><b>$user</b></a>\n";?></td></tr>
<tr><td><?echo "at $final_date on $final_date2\n";?></td></tr>
<tr bgcolor="#ffffff"><td><?echo "$comment\n";?></td></tr>
<tr><td><? echo show_league_image($type) ?></td></tr>
</table><br>

Where is this code being used? Is it within a while loop? If it is take this code

function show_league_image($type)
{
   $images = array ( 'league1' => 'first.jpg',
                     'league2' => 'second.jpg',
                     'league3' => 'third.jpg'
                   );

    if(array_key_exists($type, $images))
        return '<img src="images/awards/'.$images[$type].'" width="20" height="45" />';

    return false;
}

Outside of the while loop.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.