Jump to content


Photo

Need help with MySQL Case statements


  • Please log in to reply
3 replies to this topic

#1 urbandsigns.com

urbandsigns.com
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 22 May 2006 - 05:59 PM

Ok new to PHP. I've done this before with MSSQL but having a hard time in php.

select (case when collectionImg = '' then '' else '<img src=' collectionImg '><br>' end) as collectionImg

Basically I want it to check to see if there is a collectionImg. If there is, build the html for me, if not do nothing. Everything works except it doesn't display the collectionImg variable. How do I need to format that part (collectionImg) to get it to work?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 22 May 2006 - 08:08 PM

The posted code is SQL, not PHP. So where does PHP come into the frame?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 urbandsigns.com

urbandsigns.com
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 22 May 2006 - 10:39 PM

Good point. Meant to say new to PHP and MySql. Now how about some help?

#4 willpower

willpower
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationWarrington, Cheshire, UK

Posted 22 May 2006 - 10:55 PM

$image= "my variable from the sql query"

if ($img<>"") {do this }


Thats pretty much it...a simple conditional statement.



Wait...I've got it...Bollocks, it's gone again!

If at first you don't succeed....stop using ASP and get onto PHP




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users