views:

40

answers:

1

Hello! I have a problem with emphsizing an advertisement - i need to have to different designs for enhanced and non-enhanced ad's!

My table is like this:

id   int(11) UNIQUE  // the unique id of the row
adresse   text   // the adress of an advertisement
fremhaevninger  int(11)   // the number of emphasizings of the ad
dato   datetime  // when the row was added

I need to have a script, that can return me e.g. a variable like

$enhanced = 1;

if 'fremhaevninger' > 0 - else

$enhanced = 0;

NOTE: 'fremhaevninger' can be anything from 0 to 99.999.999.999

Is that possible ? :)

+1  A: 

Use IF():

SELECT
  otherfields,
  IF(fremhaevninger > 0, 1, 0) AS enhanced
FROM
  ....
Ignacio Vazquez-Abrams
Nice, thanks - didn't even knew something like that existed in SQL :) .. lol
Dennis Lauritzen
Well I actually need something else...In the WHERE-clause I need it to make sure, that the rows with fremhaevninger > 0 is returned BEFORE the rows with fremhaevninger = 0 :)
Dennis Lauritzen
Yeesh. Picky, aren't you... `ORDER BY enhanced DESC`
Ignacio Vazquez-Abrams
I thought you could only use actually fields in the WHERE/ORDER BY-clause :) .. my bad - thanks !
Dennis Lauritzen
Is it possible to write something like this:ORDER BY enhanced rand(), id DESC
Dennis Lauritzen
Commas between the fields, but `id` is likely to override any randomization.
Ignacio Vazquez-Abrams
Yes, but i want it to FIRST of all order by "enhanced" randomly... secondly order by id DESC if enhanced = 0 :)
Dennis Lauritzen