This topic is locked

Is this even possible

10/28/2007 12:19:43 PM
PHPRunner General questions
O
osluk author


Shows existing database output.
A small number of fields have a figure for the number of cases produced.
Instead of having a test comment appear even if the field value is null is there a way to append " cases" to the figure where a figure is present. Not null or greater than zero etc
this would appear above as 13,000 cases
Cheers Chris

hax0r 10/29/2007

Sure thing man... you need to edit your query. The query is something like
SELECT `field1`, `field2`, `field3`, `cases` FROM `your_table`
Change this to:
SELECT `field1`, `field2`, `field3`, IF(NOT ISNULL(`cases`) AND `cases` > 0, concat(`cases`, ' cases'), 'nothing') FROM `your_table`
Result:

If a row has 4. Result = 4 cases

If a row has 0. Result = nothing

If a row has null. Result = nothing



Shows existing database output.
A small number of fields have a figure for the number of cases produced.
Instead of having a test comment appear even if the field value is null is there a way to append " cases" to the figure where a figure is present. Not null or greater than zero etc
this would appear above as 13,000 cases
Cheers Chris

O
osluk author 10/29/2007

Cool I will try this and let you know.
Thanks Chris
This is what I added - not sure where it went off the rails.
IF(NOT ISNULL(`Number of cases`) AND `Number of cases` > 0, concat(`Number of cases`, ' cases'), 'nothing'),
This seemed to clash with the formatting so I will need to come back and do some experimenation.
Now looks like this:


Without the

$value = number_format($value,0);


With it it is like this


Is this a problem to then sort this field as it is a concatenation of numerical (it that format) and ' cases' concatenated?
Cheers Chris

O
osluk author 10/29/2007

A different field only text needs the following
'First' shown as 'First Wine'

'Second' shown as 'Second Wine'

'Third' shown as 'Third Wine'

'Cuvée' shownas 'Cuvée'
Cuvée remains unchanged
Cheers Chris

hax0r 10/29/2007

Hey Chris.
You are right. Concatenating a string to a numeric will affect the sort order. I think Sergey will have a better solution than I could give.
As for printing out First Wine, Second Wine, etc. Change the sql where it selects the wine field to this
CASE `wine_field`

WHEN 'First' THEN 'First Wine'

WHEN 'Second' THEN 'Second Wine'

WHEN 'Third' THEN 'Third Wine'

ELSE `wine_field` END AS `wine_field`
That should do the trick. Just replace `wine_field` with the name of your field. It appears 3 times in the above sql