[Solved] Clean repeated fields in a form list

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
boby
Forum Members
Forum Members
Posts: 94
Joined: Thu Feb 21, 2008 11:31 pm

[Solved] Clean repeated fields in a form list

Post by boby »

I got to know a bit of SQL, PHP and SMARTY in the last few days. My head is going mad.

I have created a tag {search_test} that send a request to the database:

Code: Select all

include "config.php";

if(!($db = @mysql_connect($config['db_hostname'],$config['db_username'],$config['db_password']))) //connect to database
die("couldn't connect to the database.");

if(!@mysql_select_db($config['db_name'],$db)) // Select Database
die("database doesn't exist!");
$sql = "SELECT wc_tipo, wc_pais, wc_start, wc_trabajo FROM wc_test ORDER BY wc_nombre ASC";
// get all the products from the table
$res = mysql_query($sql);
$results = array();
while ($arow = mysql_fetch_array($res)) {
array_push($results, $arow);
}
$smarty->assign('s_tab',$results);
Then the results are inserted into an html form, in a list:

Code: Select all

<form action="get_results.php" method="post">
<p>choose a country: 
<select name="Country">
{section name=idx loop=$s_tab}
 echo "<option value="{$s_tab[idx].wc_pais}"> {$s_tab[idx].wc_pais}</option><br />";
{/if}
{/section}
 </select></p>
I am getting a list of countries but many are repeated. I have tried to clean it with an {if} but I can't make it work.
Any idea?

I looking for something similar to

Code: Select all

{if $s_tab[idx].wc_pais. != $s_tab[idx+1].wc_pais}
Your help is welcome
Last edited by boby on Mon Feb 23, 2009 3:30 pm, edited 1 time in total.
User avatar
CWebguy
Forum Members
Forum Members
Posts: 139
Joined: Thu Jul 24, 2008 3:31 am

Re: Smarty: Clean repeated fields in a form list

Post by CWebguy »

SELECT DISTINCT c1, c2, c3 FROM t1 WHERE c1 = "whatever"
CMSMS Made
boby
Forum Members
Forum Members
Posts: 94
Joined: Thu Feb 21, 2008 11:31 pm

Re: Smarty: Clean repeated fields in a form list

Post by boby »

Thanks!!! Distinct did the job
Post Reply

Return to “Developers Discussion”