Re: NewBie's DB Questions..

From: Date: Tue, 10 Oct 2000 02:05:54 +0000
Subject: Re: NewBie's DB Questions..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19286@lists.php.net to get a copy of this message
On Tue, 10 Oct 2000, Ashwin Kutty wrote: > Hey all, > > I have a search engine of sorts running right now but I would like to > limit the search results to 10, 25 & 50 per page, while giving the user > the choice to pick the number of results per page.. Now, the way it does > it now is that it goes in a for loop and prints out all the result, as > such:- > > for ($i = mysql_num_rows ($result) - 1; $i >=0; $i--) > { > if (!mysql_data_seek ($result, $i)) > { > printf ("Cannot seek to row %d\n", $i); > continue; > } > > if(!($row = mysql_fetch_object ($result))) > continue; > printf ("$a) %s %s, $row->f_name, $row->f_real_name"); > $a = $a + 1; > } > > Can anyone tell me how I would be able to limit the results around this > code... Use the mysql LIMIT to determine how many records you retrieve - see http://px.sklar.com/code.html?code_id=77 for a method of doing it. Delete line 2 and be prepared to spend a while hacking it to meet your needs. > > Also, I would like it so that if there are NO results, the user is given > a message saying that, your search "blah" had 0 results or some stupid > message like that instead of giving me a no data in this document or > something like that.. For this I guess I could use the counter $i, would > that be correct? No. Use mysql_num_rows to determine how many rows were returned. If the number is zero.... > > The other functionality I would like to incorporate is multiple queries > into one.. i.e. You can search using Name, Country, Place or Thing and > then you can search ALL.. Now the way I have it setup is that the HTML > page sends the category to the PHP script for each one and each one of > the them have a different MySQl query attached to it, how would I > incorporate every query and print them out one after the other, saying > for Name these searches were yielded, for Country these results were > yielded etc. etc.. Do multiple queries, one for each category? Or you could build a query that can handle multiple search criteria, eg 'SELECT foo FROM bar WHERE a LIKE x OR b LIKE y OR c LIKE z' > > Or what I could also do is, create sub-categories such as Name, Country, > Place etc. that point to a link that would give them an alphabetical > listing of every entry in the DB in the Name table, Country table etc.. > but for that I would have to go something like:- > http://myurl.com/phpscript.php?field=Country or something such > as that > correct? How would I account for this in the script? In the script that is called by a link like that, the variable $field will contain the value 'Country' so what you might use is something like http://myurl.com/phpscript.php?country=France -- 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.general (#19286) next »