Page 1 of 1

[Solved] Clean repeated fields in a form list

Posted: Fri Feb 20, 2009 8:27 pm
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

Re: Smarty: Clean repeated fields in a form list

Posted: Fri Feb 20, 2009 9:26 pm
by CWebguy
SELECT DISTINCT c1, c2, c3 FROM t1 WHERE c1 = "whatever"

Re: Smarty: Clean repeated fields in a form list

Posted: Mon Feb 23, 2009 3:29 pm
by boby
Thanks!!! Distinct did the job