Re: search query

From: Date: Tue, 22 Feb 2000 05:58:49 +0000
Subject: Re: search query
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-10626@lists.php.net to get a copy of this message
On 21 Feb, AbsM wrote: > Hi, > > could you please assist with this query? > > Using Mysql there is a table with various columns containing information, > each with unique ID. > One of the columns was uploaded with image filenames and the corresponding > image copied to the server. > > How can i have the pages dynamically generated through a php3 interface to > the database content, when a search is done?? > There exists images, descriptions, Etc.. > > Need to control the layout. > > E.g Photos displayed to the left of the screen with an extract of the > description next to each photo, Trimmed to maybe 15 words. > Allow a maximum of 10 such records per screen. > Provide as many screens as necessary to display all records. > > E.g. 100 records. > This should display 10 records per screen for a total of 10 screens. > > Currently the html front end is as follows: > <input type="checkbox" name="foto_name" value="" checked> > > Search queries are as below: > > $result = mysql_query ("SELECT * FROM test WHERE > country_residence like '%' > AND country_residence like '$country_residence' > AND gender like '$gender' > AND (to_days(now())-to_days(dob))/365 >'$min_age' > AND (to_days(now())-to_days(dob))/365 <'$max_age' > AND current_date - period < '$past_ads' > AND height >'$min_height' AND height <'$max_height' > AND weight >'$min_weight' AND weight <'$max_weight' > AND foto_name like '%' > "); Well, if you have the PHP3 source, you might check in the /examples/album directory where there is a little application whose source should give you some ideas. Firstly, you need to design your layout in HTML; then you can use php to produce that particular HTML and embed in it the values you get back from your various queries. Secondly, you'll probably need to refine your query a bit - as it stands you will probably get unexpected results. For example, the sample you show will select all country_residence because of the %, notwithstanding that the next line attempts to restrict by value of country_residence. To trim the description, you could limit the string length you output; although you are likely to truncate words that way, it's a simple method. Alternatively, you could use explode() to stick all the words in the description into an array and select as many elements of that array to print as you wish. And there are several other ways of doing it. To handle the n records at a time, you need to take advantage of MySQL's LIMIT() argument to SELECT. If you go to the PX code exchange http://px.sklar.com/ and look in the database section for MySQL Next/Previos records, you'll find some code I wrote to do this. It won't work 'out of the box' - you'll have to do a fair bit of mucking around with it to encapsulate your particular input forms and query structure, but the basic code to handle moving around in the 'selected set' is all there. Oh, you can delete the second(?) line require("mysqlcheck"); you don't need it. Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.version4 (#10626) next »