Remove the values with array_unique

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 23, 2009   (RSS)

Re: [Djulia] Remove the values with array_unique

By ross - April 20, 2009

Hi Djulia

Thanks for posting!

You would need to make several modifications to your code before it would start working so I have a different idea.

First, you'll need to make sure your list is sorted on this particular field. Next, you would try something like:

$lastValue = 0;

<select>

foreach( ... ) {
if ($lastVaue == $listing['currentNumber'] {
<option>$listing['currentNumber']</option>
}
}

</select>


That's the basic idea. Does it make sense? You'll still need to modify that code a bit.

Let me know what you think ;).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Remove the values with array_unique

By Djulia - April 22, 2009 - edited: April 22, 2009

Hi Ross,

Thanks for your answer.
I did not succeed in finding the solution with your proposal.
(I am not very good in programming...)

But, here the solution which I found :

<?php foreach ($myTableRecords as $listing) {
$price = $listing['namevalue'];
$table[] = $price;
}
sort($table);
$result = array_unique($table);
//print_r($result);
//echo implode(", ", $result);
echo '<select>';
foreach ($result as $v) {
echo '<option value="', $v ,'">', $v ,'</option>';
}
echo '</select>';?>

That functions correctly.
But, according to you it is correct ?

Thanks,

Djulia

Re: [Djulia] Remove the values with array_unique

By ross - April 22, 2009

Hi Djulia

There are going to be lots of ways to do what you need here so I think the main thing is making sure it works properly. If the code you found works the way you want, then it's perfect.

So does that code actually work? Let me know.

Keep me up to date with how you are making out :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Remove the values with array_unique

By Djulia - April 23, 2009 - edited: April 23, 2009

Hi Ross,

Thank you for your answer. :)


That functions well.

But, as I am not a programmer, I wonder whether this code will not use much a resource on the server and if it does not present a risk for security of cmsB. ?

For the users of cmsBuilder who could be interested, it is possible to remove a value with unset :

unset($result['0']); // remove index 0
or
unset($result[array_search("xxx", $result)]); // remove "xxx" (a word)

Djulia