Re: suggestions

From: Date: Wed, 29 Aug 2001 13:16:52 +0000
Subject: Re: suggestions
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-65013@lists.php.net to get a copy of this message
On Tue, 28 Aug 2001 19:41:51 -0400, idesign@tampabay.rr.com (Glyndower) wrote: >I have a medium sized db... with about 300 feilds and 15k rows. > >I need to create a search that will submit user input to seach the db from >about 30 different feilds with some of those wildcards. > >i.e bedrooms, bathrooms, price, pool, city, etc.... > >Would using an array for the results page be the best way to approach this >in PHP? depends on how much and what post-processing you might want to do to the data before printing it out. in the most common case, you don't need to do any. for example, you already did the sorting in the SQL query, so the database already did the sorting. and usually you just need to display the data as it is received, no need for special post-processing/massaging. then there's no need to use arrays at all, just read the rows from the resultset, and display the fields you want to display, e.g., $res=sql_exec($query); /* $res is the result set, use for stepping over the rows found */ $fldsToDisplay="fullname addr1 addr2 city state zip "; /* add other fields to display in the order you want them displayed */ $fldstoDisplay=explode(" ",$fldsToDisplay); /* i'm lazy. array(...) works too but i like this more because the list is easier to type as a string (fewer quotes) and you can load the list of flds to display from somewhere else (e.g., a config file or something) */ print("<TABLE>\n"); /* for each row in the resultset, get associative array of the row */ while($row=sql_fetch_array($res)) { print("\t<TR>\n"); /* for each field to be displayed, get the next fieldname, and get the corresponding data from the associative array and print it in a table cell */ for($ctr=0;$ctr<count($fldsToDisplay);$ctr++) { $fldname=$fldsToDisplay[$ctr]; $data=$row[$fldname]; print("\t\t<TD>$data</TD>\n"); } print("\t</TR>\n"); } print("</TABLE>\n"); PS. replace sql_* functions with the relevant functions for your database or with whatever DB abstraction package you use. PPS. sometimes you have to do post-processing. but most such data massaging involves only other fields in the same row or global data. the above common case system will need to be modified if your data massaging involves data from other, far-off rows in the same selection. usually, though, even that can be solved by sub-selects and other SQL tricks.

« previous php.general (#65013) next »