How to replace a hard-coded array to a database array?

Talk about Filter (search) Settings

Moderator: alexandrleonenko

chirng
Master
Master
Posts: 148
Joined: Jun 7th, '09, 04:15

How to replace a hard-coded array to a database array?

Postby chirng » Oct 1st, '09, 19:27

simply a sample as I would like to change the hard-coded array in autosuggest_countries.php to a database array as below:-

$aUsers = array(
"Afghanistan",
"Albania",
"Algeria",
.........,
"Zaire",
"Zambia",
"Zimbabwe"
);

I tested fails as below:-

$aUsers = array();
$rsLimited = "SELECT xxxx_no FROM xxxx WHERE balance > 0 ORDER BY xxxx_no";
while($row = mysql_fetch_array($rsLimited))
{
//$aUsers[]=$row;
array_push($aUsers, $row);
}
//sort($aUsers);

Please advise, tq.
Last edited by chirng on Dec 14th, '16, 03:04, edited 1 time in total.

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: How to replace a hard-coded array to a database array?

Postby administrator » Oct 2nd, '09, 08:30

You are right, this file is outstanding file. You need to use here separated connection to database.
It means, you need to write here all needed code to connect with database etc. (mysql_connect.....)
So you can create this array 'on fly' and return it or use already hard-coded if you don't need to change
it every time, like array of countries.

jon22
Newbie
Newbie
Posts: 4
Joined: Feb 2nd, '10, 12:49

Re: How to replace a hard-coded array to a database array?

Postby jon22 » Feb 10th, '10, 09:07

$arrayStructura = array();
$rsGrade = mysql_query("SELECT id_structura,structura FROM nomenclator_structuri") or die(mysql_error());
while($row = mysql_fetch_array($rsGrade,MYSQL_ASSOC))
{
$arrayStructura[$row['id_structura']]=$row['structura'];
}

....
"Structura" =>array("table"=>"nomenclator_structuri", "field"=>"id_structura", "source"=>$arrayStructura, "order"=>"DESC", "operator"=>true, "type"=>"dropdownlist", "case_sensitive"=>false, "comparison_type"=>"binary"),

byman
Newbie
Newbie
Posts: 7
Joined: Dec 6th, '10, 20:41

Re: How to replace a hard-coded array to a database array?

Postby byman » Sep 4th, '15, 17:49

After search and search I find this old post and I think it is what I need.

I would like populate my dropdownlist from a secondary table. The main table has around 100.000 records and the time required for each DISTINCT is too expensive. I have 4 dropdownlist populated from the table.

I tried to fill the "filtering_fields" using as table my secondary table.I can see my dropdownlist populed. Wow I said! But when I try to click on search I get an error in the WHERE because my secondary table is mentioned :-(

Is there today a way to do that or I still have to apply the solution of jon22, I mean creating a separated connection to database.

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: How to replace a hard-coded array to a database array?

Postby administrator » Sep 7th, '15, 14:15

Try create procedure that uses AJAX to fill this list.


Return to “Settings: Filtering (search) / Autocomplete”