|
-
May 11th, 2007, 11:03 AM
#1
Thread Starter
Lively Member
Possible Syntax Error
Ok here is my problem!
On this page I am trying to get the 2 teams to have their logo appear, NOT there 3 letter team, NYY, TEX, etc.
I am not sure of the proper syntax code I put in. Here is the php code source!
Code:
<?php
$generate = '';
$result = mysql_query("SELECT * FROM boxscoreaway ORDER BY 'id' ASC");
$away = mysql_fetch_array($result);
$result = mysql_query("SELECT * FROM boxscorehome ORDER BY 'id' ASC");
$home = mysql_fetch_array($result);
// the away team just began
$generate .= '<tr style="background-color:eeeeee">
<td width="254"><table width="100%" border="0">
<tr>
<td id="team" width="20%">' . $away['team'] . '</td>
<td align="left" width="80%">';
// once more, those math classes for logic comes in hand, but this logic is too easy
// if $away team had more runs, then show that the winner was the $away team
if( $away['R'] > $home['R'] ) {
$generate .= '<img src="http://robbyzworld.com/personal/images/sports/nyy/winner.gif" />';
}
$generate .= '</td>
</tr>
</table></td>
<td width="35">' . $away['R'] . '</td>
<td width="35">' . $away['H'] . '</td>
<td width="35">' . $away['E'] . '</td>
</tr>';
// the away team just ended
// the home team just began
$generate .= '<tr style="background-color:eeeeee">
<td width="254"><table width="100%" border="0">
<tr>
<td id="team" width="20%">' . $home['team'] . '</td>
<td align="left" width="80%">';
// but, if the $home team had more runs, then show that the home team won.
if( $away['R'] < $home['R'] ) {
$generate .= '<img src="http://robbyzworld.com/personal/images/sports/nyy/winner.gif" />';
}
$generate .= '</td>
</tr>
</table></td>
<td width="35">' . $home['R'] . '</td>
<td width="35">' . $home['H'] . '</td>
<td width="35">' . $home['E'] . '</td>
</tr>';
// end the home team just ended
echo $generate;
?>
-
May 11th, 2007, 11:21 AM
#2
Re: Possible Syntax Error
For the logo to appear, you have to use an img tag.
PHP Code:
<td id="team" width="20%">' . $away['team'] . '</td>
Instead of concatenating the $away['team'], you have to use an img tag and put the URL in the src property pointing to the team shield.
HTH,
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
May 11th, 2007, 12:07 PM
#3
Thread Starter
Lively Member
Re: Possible Syntax Error
Exactly,
I am learning PHP so I am not familiar with the proper syntax.....
I know the img tag is <img src=""></img>
-
May 11th, 2007, 12:11 PM
#4
Re: Possible Syntax Error
Never never ever use echo to display HTML. It is unnecessarily sloppy and results in unreadable code such as the above (not to mention your wacky indentation). All you need to do is close the PHP tags: ?>.
PHP Code:
<img src="<?php echo $away['R'] ?>" alt="<?php echo 'some appropriate text equivalent' ?>">
<img> does not have a closing tag in HTML.
Last edited by penagate; May 11th, 2007 at 12:15 PM.
Reason: missed the 'not'
-
May 11th, 2007, 12:29 PM
#5
Re: Possible Syntax Error
It's best practice not to echo HTML, only the required portion. You really should do it and enforce it from now on.
I'm going to reply with your current code, as you have it now. When you have this working, I suggest you clean up the code.
PHP Code:
<td id="team" width="20%">' . $away['team'] . '</td>
Should be replaced with:
PHP Code:
<td id="team" width="20%"><img src="' . $away['logoURL'] . '" /></td>
Where logoURL should be the link to the team logo image, in this case, the away team.
HTH,
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
May 11th, 2007, 01:32 PM
#6
Thread Starter
Lively Member
Re: Possible Syntax Error
Once I get it working what is the best way to clean up the code? Any sites. I am not that experienced yet!
Code:
<td id="team" width="20%"><img src="' . $away['http://robbyzworld.com/personal/images/sports/teams/tex.jpg'] . '" /></td>
The above code still doesn't work!
-
May 11th, 2007, 01:38 PM
#7
Re: Possible Syntax Error
that URL should be stored inside a field in the database, since you are fetching it from there.
In the database structure, you have to add a field to store the team logo picture URL. That way, when you fetch the team information, you also have the logo URL.
You have to update your database structure first, and then you will be able to access it with $away['logoURL'] .
Example of clean code:
PHP Code:
<table border="1">
<tr>
<td>Team Name:</td>
<td><?php echo $away['team']; ?></td>
</tr>
</table>
Notice that the HTML is treated as HTML, not as a concatenation on PHP, and when PHP has to display a dynamic value, it echoes only that value in it's specific place.
HTH,
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
May 11th, 2007, 01:45 PM
#8
Thread Starter
Lively Member
Re: Possible Syntax Error
ahh ok yeah, cleaned that up...
now to set the size of the image how does that play in this line of code?
Code:
width="25" height="25"
-
May 11th, 2007, 01:48 PM
#9
Re: Possible Syntax Error
If you want to resize the image, you have to add those properties to the <img> tag.
It should look something like this in the cleaned up way:
PHP Code:
<img width="25" height="25" src="<?php echo $away['logoURL'] ?>" />
HTH,
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
May 11th, 2007, 01:50 PM
#10
Re: Possible Syntax Error
Width and height are presentational attributes and all presentation should be done using CSS and HTML. Give your image an ID attribute and specify width and height in your stylesheet.
-
May 11th, 2007, 02:06 PM
#11
Thread Starter
Lively Member
Re: Possible Syntax Error
ok it works....
now time to clean up.
Seeing how you guys are far more experienced than I am, what ways would you recommend for me learning the best way to clean up my code?
-
May 11th, 2007, 02:14 PM
#12
Addicted Member
Re: Possible Syntax Error
Don't forget the "alt" description within the img tag if you want it to be valid html...
F
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|