puzzled with echo()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TalonStriker
Forum Newbie
Posts: 8
Joined: Thu May 26, 2005 2:56 pm

puzzled with echo()

Post by TalonStriker »

I am a newbie in php and i am working on my first website made out of php. :)
Just wondering whether anyone could help me with this problem:

In my code one of the echo statements don't seem to be working. Actually only a part of it seem to be working (line 8 ).
PHP code:

Code: Select all

<?php 
//...
		echo "<table width=\"100%\"><tr><td width=\"99%\"><p><strong>" . $name[$min+$count] . " </strong></p></td><td><a href=\"#\" class=\"navimages\"> <img src=\"http://www.playonline.e2u.cc/images/top.gif\" border=\"0\" /></a></td></tr></table>";
		echo "<table width=\"100%\"><tr><td>";
		echo "<a href=\"play.php?id=" . $id[$min+$count] . "\">";
		echo "<img height=\"120\" width=\"160\" src=\"game_images/" . $min+$count+1 . '.jpg" border=0 align="top"></a></td><td width="90%" valign="top"><p>Description: ' . $description[$min+$count] ;
//...
?>
Output source code:
<table width="100%"><tr><td width="99%"><p><strong>Sheepish </strong></p></td><td><a href="#" class="navimages"> <img src="http://www.playonline.e2u.cc/images/top.gif" border="0" /></a></td></tr></table><table width="100%"><tr><td><a href="play.php?id=">1.jpg" border=0 align="top"></a></td>
Screenshot:
Image

I have no idea why its not working ???

THANKS!!
-TS
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

Code: Select all

echo "<img height=\"120\" width=\"160\" src=\"game_images/".($min+$count+1).".jpg\" border=0 align=\"top\"></a></td><td width=\"90%\" valign=\"top\"><p>Description:". $description[$min+$count];
you forgot to use \\for width and valign.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

Actually, HTML will accept values with no quotes if it's only a single word or a number. So, instead of doing this:

Code: Select all

echo "<img height=\"120\" width=\"160\" src=\"game_images/" . $min+$count+1 . ".jpg\" border=0 align=\"top\">";
Do this...

Code: Select all

echo "<img height=120 width=160 src='game_images/" . $min+$count+1 . ".jpg' border=0 align=top>";
Also, treat numbers with '%' as words. Use single quote.

Code: Select all

echo "<table width='100%'><tr><td width='99%'><p><strong>";
Doing so will lessen the parse errors in you code.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

harrisonad wrote:Actually, HTML will accept values with no quotes if it's only a single word or a number. So, instead of doing this:

Code: Select all

echo "<img height="120" width="160" src="game_images/" . $min+$count+1 . ".jpg" border=0 align="top">";
Do this...

Code: Select all

echo "<img height=120 width=160 src='game_images/" . $min+$count+1 . ".jpg' border=0 align=top>";
Also, treat numbers with '%' as words. Use single quote.

Code: Select all

echo "<table width='100%'><tr><td width='99%'><p><strong>";
If he's trying to stick with the standards, quotes are required...

Doing so will lessen the parse errors in you code.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Just make a simple statement:

Code: Select all

echo $id[$min+$count];
and see what you get.

Also, try dumping out the contents of $id to see if it's populated the way you expect:

Code: Select all

echo '<pre>';
print_r($id);
echo '</pre>';
(the <pre></pre> tags make what print_r returns, readable)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply