Searching
Moderator: General Moderators
Searching
I've got a question....I have a database full of news articles, dates they published, category they are under, and author. If someone wanted to search by articles published during 11/25/02 and 11/29/02 under the Communications category, is that real hard to do? Is there anyway to string together SELECT * FROM WHERE clause things using an && operator to get proper results like this?
Something like this might help... or get you started...
articles published during 11/25/02 and 11/29/02 under the Communications
Not too sure about the 'between these dates' thing myself to be honest.
I wouldn't mind findinf that out either
Hope this helps.
articles published during 11/25/02 and 11/29/02 under the Communications
Code: Select all
<?php
mysql_query("SELECT * FROM yourtablename WHERE published='11/25/02' AND category='Communications'");
?>I wouldn't mind findinf that out either
Hope this helps.
Oh.
mmm, well that's interesting! I wish there was a PHP chat I could sit there for days asking questions trying to get my project work.
I'm trying to think of a good solution for my problem....there will be about 6 different ways of searching (for last name, for first name, for paper name, by date, or by headline) but they can do more than one at a time. I guess I will have to somehow check to see which fields were filled in before I can process the search?
I'm trying to think of a good solution for my problem....there will be about 6 different ways of searching (for last name, for first name, for paper name, by date, or by headline) but they can do more than one at a time. I guess I will have to somehow check to see which fields were filled in before I can process the search?
You could do a multiple search by calling more than one mysql query, for example..
..you can do as many of these as you want.
You would then need to do a mysql_num_rows command for each result.
...........if that makes sense.................................................................
Code: Select all
<?php
$SEARCHa=mysql_query(" SELECT * FROM here WHERE a='this' AND b='that' ");
$SEARCHb=mysql_query(" SELECT * FROM there WHERE a='something' AND b='something else' ");
?>You would then need to do a mysql_num_rows command for each result.
...........if that makes sense.................................................................
I would be inclined to build the SQL where clause depending on which fields are be filled out. For instance:
Code: Select all
<?php
if (isset($pubfield) and ($pubfield != "")) {
$pubfieldwhere = "and published = '$pubfield' " ;
}
if (isset($catfield) and ($catfield != "")) {
$catfieldwhere = "and category = '$catfield' " ;
}
// ... check more fields
$sql = "select * from yourtablename where 1 = 1" .
$pubfieldwhere . $catfieldwhere ;
// sql assignment will have one "fieldwhere" for
// each form field you want to include in the query
$SEARCHb=mysql_query($sql) ;
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
On a side note, if you want to search for all records between two criteria you can use the BETWEEN operator:
Mac
Code: Select all
SELECT field1, field2, field3 FROM table WHERE date BETWEEN '2002-11-25' AND '2002-11-29'