HighDots Forums  

Need Help with IMG+PHP Database+Selective Display

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss Need Help with IMG+PHP Database+Selective Display in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bih Wang
 
Posts: n/a

Default Need Help with IMG+PHP Database+Selective Display - 04-02-2009 , 12:08 AM






The problem is really a lot simpler than I made it sounds to be, though I fear
the answer might be vice versa.

I need to have pictures appear when they exist. That's all.

-------------------------------------
Here is where I am at:

I have created a php database for a news announcement page. In that database,
I have a column named "img" whose default value is "null"

Whenever I actually have a picture corrosponding to a particular news, the
"img" column will change to the file name of that image, which I will then
extract.

So basically... if news A, img = null... no picture. news B img = b... then
yes picture. very simple concept for database.

Here's what I can't do.

When I read the database from DW, how can I make it so that when it reads a
"null" it won't insert a picture and vice versa? I figure it definitely has to
do with the "if" statement (duh...)

I know how to make text do that effect...
<? if $row_data['text'] != null
echo("i have data");
?>

but how do i do it with an image? I tried putting the image tag to replace
the entire "echo" line, but that's apparently not how you do it. I tried
putting it inside "echo", but that doesn't seem to be it either.

also, as a premise, all pictures are associated with only 1 particular news.
which i wrote something similar to this:
<img src="<?php echo $row_data['img']; ?>.jpg" width="200" height="200" />


Um, basically... I need THAT to fit into the IF statement. So thanks in
advance.




Reply With Quote
  #2  
Old   
Cosmo Kramer
 
Posts: n/a

Default Re: Need Help with IMG+PHP Database+Selective Display - 04-02-2009 , 08:19 AM






This should work for you:

if (!is_null($row_data['img']))
{
echo '<img src="',$row_data['img'],'.jpg" width="200" height="200" />';
}



Reply With Quote
  #3  
Old   
Bih Wang
 
Posts: n/a

Default Re: Need Help with IMG+PHP Database+Selective Display - 04-02-2009 , 09:33 PM



thanks so much!

is how i interpret the code correct?

if (!is_null($row_data['img'])) ---> if img is false
echo <--- maybe i been using this without understanding it correctly... echo
means to display on screen but not limited to text right?

and the rest is where you lost me... i don't get the punctuations

bracket double quote (" is for text right?
so single quote ' means to accept a php function or html code?

so can i do this?
'<div bob>blah'
and have div bob appear only when the conditions are met?

and external data is define by comma?
such as... if i pre-define value "x"
so i can do img src=',x,'.jpg?

thanks again! is there a tutorial i can read for these?



Reply With Quote
  #4  
Old   
Cosmo Kramer
 
Posts: n/a

Default Re: Need Help with IMG+PHP Database+Selective Display - 04-03-2009 , 08:17 AM



if (!is_null($row_data['img']))
{
echo '<img src="',$row_data['img'],'.jpg" width="200" height="200" />';
}


Let's break that down into the following:
echo '<img src="' ;
echo $row_data['img'] ;
echo '.jpg" width="200" height="200" />' ;

When you string multiple echoes together use a comma between them,. so now
we have:
echo '<img src="',$row_data['img'],'.jpg" width="200" height="200" />';
(You may also use a period, but my understanding is the period is less
efficient.)

I only have single quotes in my PHP statements. The double quotes you see
are part of what will be the rendered HTML.

You may generally use the single quote or double quote interchangeably with
few exceptions such as having double quotes as part of the text or vice
versa among others. You can probably escape the characters too, but lets
keep this simple for now.

If I misspoke I am sure Micha will be sure to correct me.

IMO The best thing to do is learn by trial and error, and your best resource
on the net for PHP is probably the php website. www.php.net








"Bih Wang" <webforumsuser (AT) macromedia (DOT) com> wrote

Quote:
thanks so much!

is how i interpret the code correct?

if (!is_null($row_data['img'])) ---> if img is false
echo <--- maybe i been using this without understanding it correctly...
echo
means to display on screen but not limited to text right?

and the rest is where you lost me... i don't get the punctuations

bracket double quote (" is for text right?
so single quote ' means to accept a php function or html code?

so can i do this?
'<div bob>blah'
and have div bob appear only when the conditions are met?

and external data is define by comma?
such as... if i pre-define value "x"
so i can do img src=',x,'.jpg?

thanks again! is there a tutorial i can read for these?





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.