Welcome Guest, Not a member yet? Register   Sign In
Quick view question
#11

[eluser]xwero[/eluser]
You made a list out of the values?
#12

[eluser]tim1965[/eluser]
xwero

Please scratch the above re CSS. I thought this had nailed the problem using a content value from CSS, but after a day of playing around i couldnt get it to work properly.
So i have used your example and have got this working properly.
However i still have one problem that has haunted this issue from the beginning. That is applying the comma even if the returned variable is not populated from the database. Sometimes they may all be null or sometimes each will be populated with a value, sometimes only one will be populated.
So i select on 3 fields for example
test1
test2
test3
I have to create an array for all 3 fields as i dont know which will be populated
If only test2 returns a result currently implode will apply the glue to all three elements of the array even though 2 are non populated.
So i get output that looks like
Quote:
, test2, ,
Quote:
When i want
Quote:
test2,
Quote:
So implode is applying to all elements irrespectivee of wheter they are populated or not.
Any help appreciated.
Thanks
#13

[eluser]xwero[/eluser]
have you added the array_filter? from php.net
Code:
<?php

$entry = array(
             0 => 'foo',
             1 => false,
             2 => -1,
             3 => null,
             4 => ''
          );

print_r(array_filter($entry));
?>

Quote:The above example will output:

Array
(
[0] => foo
[2] => -1
)
As you see from the example it filters out false,null and an empty string. So this should work for you.
#14

[eluser]tim1965[/eluser]
No i hadnĀ“t sorry. I couldt use the example as ti stood in a foreach loop. Because of the complexities of the returned data and the fact that i only needed to apply this to certain fields. Funnily enough i had just got to array_filter on another forum.
So my example now looks like
$data=$this->M_model->return_query_details();

$array = array (
$array[0] = $data['test1'],
$array[1] = $data['test2'],
$arrayy[2] = $data['test3'],

);
$data['view'] = implode(", ", $array);
In this example, would it be better to filter $data or filter $array to strip out the null values. As i said above my actual code will run thru this a number of times for each of the field groups i need to apply this formatting to. I have to create $array this way, to take account of the different returned result sets from the query.
I hope this maes sense!
This seems like a lot of effort to put a comma at the end of a word to make it look pretty.
Thanks again for all you r help so far.
#15

[eluser]xwero[/eluser]
i wouldn't use an extra array because all you do is change the array from an associate array to a numbered array. It's not the key that is important.
#16

[eluser]tim1965[/eluser]
Sorry i am missing some thing here, apologies if i am being stupid.
My code now
$data=$this->M_model->return_query_details();

$array = array (
$array[0] = $data['test1'],
$array[1] = $data['test2'],
$arrayy[2] = $data['test3'],

);
$data['view'] = implode(", ", array_filter($array));
Currently output is not having the comma applied using above.
When i was testing yesterday i fould that implode would not apply the glue if only one element was present in the array. My test query currently is only returning a value for test2 and not applying the comma.
#17

[eluser]tim1965[/eluser]
xwero

Implode does not concatonate the element and the glue on one element arrays. So given what i am trying to acheive, i think not adding a comma to the end of one item is going to be ok. So i think my problem is fixed. I want to thank you for your help in resolving this for me.




Theme © iAndrew 2016 - Forum software by © MyBB