Jump to content

Trying to change inline image conditionally in an array...help


Recommended Posts

Currently, I insert a small thumbnail image at the begging of each row in a set of records from a mysql query. But that image is the same image for each record in that array.


Is there a way to conditionally change which image is used, based on a value either in that same table, or a related table.

See attached screenshot... and here's my current code....

$query = "select address from nvc";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
$details.='<li class="menu"><a href=detail.php?address='.(urlencode($row['address'])).'><img src="thumbs/house.png" /><span class="name">'.$row['city'].'</a>';


Thank you for any input.


[attachment deleted by admin]

Link to comment
Share on other sites

Very cool. I have some studying to do. I've never seen some of what you're used here. Thanks. I'll get to work.


np bro, I'll explain it :)


IFNULL simply checks if parameter 1 is null, if it is, return parameter 2, if it isn't null, it returns parameter 1 :)

(to make it make sense! IFNULL(param1,param2) )


LEFT JOIN is an OUTER JOIN, INNER JOIN is self explanatory :)


The difference between outer joins and inner joins, outer joins will not fail the selection if the ON parameter doesn't match, it will simply join a NULL ROW


so basically if there is NO ROW in `icons` for the address 'playground' then it will instead of not pull a row for 'playground' it will pull playground from `nvc` and a null row from `icons`..


so back to IFNULL, because IFNULL tests param1 against NULL, if `icons` doesn't have a row for the current `nvc` row, IFNULL(icons.icon,'defaultPicture.gif') will naturally return parameter2 which is the default picture for rows without a thumbnail :)


I gotta run out :)! Thanks for choosing PHPFreaks for your PHP help <33 *got paid $5 to say that.. cough cough* *not really, I just love this forum!*

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.