echoing trouble

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
sk8erh4x0r
Forum Commoner
Posts: 43
Joined: Wed May 26, 2004 8:27 pm

echoing trouble

Post by sk8erh4x0r »

I'm having trouble with my user info echo's. This is what i have right now:

echo "<center><h2>$row[username]<h2><center><img width ='70' height='70' src=\"$row[avatar]\"><br \>\n";


I'm trying to have the username and avatar post on the same line, but after the username, its inserting a line break and the avatar is under the username. Any help on how to fix this?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

try $row['username'] and $row['avatar'] instead.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

... actually it seems to me that your variables are fine as $row[username] since you have them inside of double quotes.
You might try getting everything inside of the <center> tags instead of just the h2 tags, or if that doesnt work put it in a table with two table cells:

Code: Select all

<?
echo "<table align='center'>\n";
echo "  <tr>\n";
echo "    <td><h2>$row[username]</h2></td>\n";
echo "    <td><img width='70' height='70' src='$row[avatar] /></td>\n";
echo "  </tr>\n";
echo "</table>\n";
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

andre missed a single quote in there.. although I highly suggest using double quotes for all those attributes..
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

You didn't end your <h2>, you just started a new one.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Code: Select all

echo "<center><h2>$row&#1111;username]<h2><center><img width ='70' height='70' src="$row&#1111;avatar]"><br \>\n";
<h2> is a block format in HTML, if the second <h2> is actually what you are trying to use as you close for the <h2> then it will not work, anything after an </H2> tag will appear on a new line, so either ...

Code: Select all

echo "<center><h2>$row&#1111;'username']<img width ='70' height='70' src="$row&#1111;'avatar']"></h2></center>\n";
or use a different HTML tag like <FONT> and specify the formatting that you want for the text.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

... i'm curious, Feyd, why do you recommend using double quotes around html attributes?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

It's XHTML standard and makes HTML XML-compliant. As is, HTML is simply badly formed XML.
skeetley
Forum Newbie
Posts: 1
Joined: Mon Jun 07, 2004 4:08 pm

Post by skeetley »

Well said patrikG :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

patrik hit it on the nose, exactly.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

...hmm... when I validate my code in which i use mostly single quotes for attributes' values, it validates without any problems.
Are you sure that single quotes are not allowed on xhtml for attributes values?
sk8erh4x0r
Forum Commoner
Posts: 43
Joined: Wed May 26, 2004 8:27 pm

Post by sk8erh4x0r »

Well, that code works where the avatar is put inside the h and center tags but, now the avatar makes the username post at the bottom instead of the top of the avatar. Any help on how to align the username to the top of the avatar?
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

can you post the updated code that you're using?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

try this:

Code: Select all

echo "<center><h2>{$row['username']}<h2><center><img width ='70' height='70' src="{$row['avatar']}"><br \>\n";
Post Reply