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?

Recommended Answers

All 16 Replies

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

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.

What do you get when you echo $row?

commented: Tahnk you! +1

What do you get when you echo $row?

irish

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

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

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

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

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

Can you post your array and additional code, please?

<?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>";
?>

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.

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

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

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

$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
    ....
)
commented: Thank you! +1

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

I was calling for teamA and my field is TeamA

Thanks for all your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.