0

Here is what I have

echo "<img src='/images/bar_".$row['teamA'].".jpg'>";

in this example teamA = irish

What I want to output is

<img src='/images/bar_irish.jpg'>

I think it is a simple syntax. What am I missing?

4
Contributors
16
Replies
17
Views
7 Years
Discussion Span
Last Post by ceeandcee
Featured Replies
  • What do you get when you echo $row['teamA']? Read More

  • [CODE=php] $row = mysql_fetch_array( $result ); [/CODE] after that line, add: [CODE=php] print_r($row); [/CODE] this will probably make a mess out of the table layout, but paste the output from that function here. That should indicate whether the problem is in the row array or not. Output should be something … Read More

0

That echo statement works for me without any issue. Can you post what you are getting errors and/or output when you run it?

0

I get the red x as it is not finding the image. I know the image is there because when I hard code it, i get the image. It seems not to be populate the word "irish' where I need it.

0

Try this?( no guarantee) echo "<img src='/images/bar_".{$row['teamA']}.".jpg'>";

Sorry..no luck. Get this msg

Parse error: syntax error, unexpected '{' in D:\Inetpub\vhosts\cornwallfantasyhockey.com\httpdocs\cfhl\trades\index.php on line 37

0

Have you looked at the source code to see what it displays?

Yes...this is what I get....
<img src='/images/bar_.jpg'>

0
<?php
$result = mysql_query("SELECT * FROM trades1011 order by date DESC")
or die(mysql_error());  

echo "<table width='500' border='1' bordercolor='cccccc' cellspacing='0' cellpadding='2' bgcolor='ffffff'>";

// keeps getting the next row until there are no more to get


$row = mysql_fetch_array( $result );
	// Print out the contents of each row into a table
	echo "<tr><td width='15' bgcolor='000000' align='left'><font face='arial' size='1' color='FFFFFF'>"; 
	echo $row['tradeID'];
	echo "</td><td colspan='2' width='470' bgcolor='000000' align='left'><font face='arial' size='3' color='FF0000'><b>"; 
	echo $row['Date'];
	echo "</td><td width='15' bgcolor='cccccc' align='left'><font face='arial' size='2' color='000000'>"; 
	echo $row['tradeID'];
	echo "</b></td></tr>";
	

	echo "<tr><td colspan='2'width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo "<img src='/images/bar_".$row['teamA'].".jpg'>";
	echo "</td><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo "<img src='/images/bar_".$row['teamB'].".jpg'>";
	echo "</td></tr>";

	echo "<tr><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['A1'];
	echo "<td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['B1'];

	echo "</td><tr><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['A2'];
	echo "<td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['B2'];

	echo "</td><tr><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['A3'];
	echo "<td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['B3'];

	echo "</td><tr><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['A4'];
	echo "<td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['B4'];

	echo "</td><tr><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['A5'];
	echo "<td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['B5'];

	echo "</td><tr><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['A6'];
	echo "<td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['B6'];

	echo "</td><tr><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['A7'];
	echo "<td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['B7'];

	echo "</td><tr><td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['A8'];
	echo "<td colspan='2' width='250' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
	echo $row['B8'];

	echo "</td></tr>";

echo "</table>";
?>
0

Your echo statement is correct.

<?php
$row['teamA'] = 'irish';
echo "<img src='/images/bar_".$row['teamA'].".jpg'>";

yields

<img src='/images/bar_irish.jpg'>

Is it failing to display for all iterations of your loop or is it only on particular ones? I assume you've omitted the loop to simplify the code posted.

0

I tried to keep the post simple....but in every instance, it doesnt work

0

Can you do a print_r($row) and post the output from 1 iteration of the loop?

I'm sorry, i dont understand what you are asking me to do

1
$row = mysql_fetch_array( $result );

after that line, add:

print_r($row);

this will probably make a mess out of the table layout, but paste the output from that function here. That should indicate whether the problem is in the row array or not.

Output should be something like:

Array
(
    [tradeID] => xxxx
    [Date] => xxxxx
    [teamA] => xxxx
    ....
)
Votes + Comments
Thank you!
0

Thanks everyone...I saw my error! What a dummy!

I was calling for teamA and my field is TeamA

Thanks for all your help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.