/    Sign up×
Community /Pin to ProfileBookmark

How would I make this work? It echos a rating based on what they have done, and each rating has an image..

<? echo “<img src=”images/rank/[rating].jpg”; ?>”

Thanks ?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@flynryan692_aolauthorDec 07.2009 — Forgot to mention, this is how I echo the other things..

<? echo "$alr[fname]"; ?>

so maybe I need $alr
Copy linkTweet thisAlerts:
@SrWebDeveloperDec 07.2009 — Please always use the code or PHP tags when embedding lines of code.

Your question is very hard to follow, so assuming by your second post that you use $alr[fname] for the user's first name, I can only assume you're pulling a field in the same query named "rating" so you'd need:

[code=php]echo "<img src="images/rank/$alr['rating'].jpg" alt="Rating" border="0"";[/code]

Or similar.

If not, please post relevant code (query and processing of result set) thanks.

-jim
Copy linkTweet thisAlerts:
@MindzaiDec 07.2009 — Just a small point but when using string array indexes within double quotes the correct syntax is one of the following:

[code=php]
// no quotes around the key
echo "<img src="images/rank/$alr[rating].jpg" alt="Rating" border="0" />";
// braces around the whole variable
echo "<img src="images/rank/{$alr['rating']}.jpg" alt="Rating" border="0" />";
[/code]


Otherwise you'll get a parse error.
Copy linkTweet thisAlerts:
@SrWebDeveloperDec 07.2009 — Oopsie, good catch.

Funny thing is I've given similar advice numerous times on here to others! Typing too fast, as usual. Thanks, Mindzai! :p
Copy linkTweet thisAlerts:
@FremenDec 08.2009 — As an extension to this;

I've been trying to display images from a while loop.

//Fetch and print all records.
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
echo '<tr><td align="left">' .
$row['products_id'] . '</td><td align="left"> ' . $row['products_model'] . '</td>
<td align="right"> ' . $row['products_price'] . '</td><td align="right"> '"<img src= "{' . $row['products_image'] .'}" alt=""/>" '</td></tr>';

}


i get Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/webtite/public_html/test2.php on line 42

if i don't use the " img src= " the display lists the filenames fine, but i can't get the images to display

Help with the syntax would be appreciated.
Copy linkTweet thisAlerts:
@MindzaiDec 08.2009 — Please always use the code or PHP tags when embedding lines of code.[/quote]

It's not that hard to post with the tags! In fact if you had you might have seen the error.

[code=php]
//Fetch and print all records.
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
echo '<tr><td align="left">' .
$row['products_id'] . '</td><td align="left"> ' . $row['products_model'] . '</td>
<td align="right"> ' . $row['products_price'] . '</td><td align="right"> '"<img src= "{' . $row['products_image'] .'}" alt=""/>" '</td></tr>';
}[/code]


You are missing concatenation operators between the last 3 parts of your string. You also have incorrect quoting towards the end.
Copy linkTweet thisAlerts:
@FremenDec 08.2009 — Thanks Mindzai, got me on the right track.

This got me the desired result in the end:

<td align="right"><img src= /images/' . $row['products_image'] . ' alt="" height="120" width="120" /></td>
Copy linkTweet thisAlerts:
@MindzaiDec 08.2009 — Note that for valid XHTML you need to quote all attributes - at the moment you are missing quotes around the src attribute's. value
×

Success!

Help @flynryan692_aol spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...