Return an image from a field

focault

Member
OK I need to return an image from a dropdown or join.
I have a list that makes up match reports for sports. The idea is the user selects the home and away teams from a dropdown and then on the list it will display the team names and also the team icons.

Elements are -
Home Team Name (database join element)
Home Icon (calc element)
Home Alt Name (field element)
Away Team Name (database join element)
Away Alt Name (field element)
Away Icon (calc element)
Home Team Score (field element)
Away Team Score (field element)
Match Report (textarea element)

So with the help from cheesegrits on skype we came up with a great solution -
We made a new list called Teams and put the team names in there and made the Home Team and Away Team names databasejoin elements to the Teams list.
It uses the id as the element Team Name from the Teams list.
When the form is filled out the user selects a team from the dropdown and the calc element Home Icon/Away Icon shows the teams icon.
If the team does not exist in the Teams list then the element Alt Name can be filled in by the user and the calc element then returns an image placeholder because no image exists for this team.

This is the code from the calc elements -

$team_raw = '{yourtablename___Home_Team_raw}';
$team = "noteam";
if (!empty($team_raw)) {
$team = '{yourtablename___Home_Team}';
}
return "<img src='http://yourpath/" . $team . ".png' />";

Setting for the calc elements
Only Calc on Save =Yes
Ajax Calc =Yes

You have to make sure that you have the images in "yourpath" named to match up with the Team Name in the Teams list.Also make sure you have an image called noteam.png

When i get some time in the next couple of days I will write a proper wiki on this with screenshots
 
Thanks for documenting this for me.

We'll pick up with the other issues tomorrow, assuming my Spine Dude doesn't decide I need to go straight in to surgery. :/

-- hugh
 
Back
Top