Re: [PHP-DB] Create Search engine with multiple form fields

2008-06-29 Thread Bastien Koert
On Sun, Jun 29, 2008 at 11:07 AM, Nasreen Laghari <[EMAIL PROTECTED]>
wrote:

> Hi,
>
> I have an HTML form which has more then one fields. User can precise its
> search using one or more input fields E.g GigName,Date, Genre,Venue.
> The data is coming from 3 tables.  Below Query brings one tables record
> with each and every row of other two tables. Could any one please help me
> sort out the query.
>
> select * FROM gig g, venue v, genre ge  WHERE g.gigName LIKE
> '%".$gig_name."%' OR g.gig_date LIKE '%".$sdate."%' OR ge.name LIKE
> '%".$genre."%' OR g.ticket_price LIKE '%".$ticket_price1."%' OR
> g.ticket_price LIKE '%".$ticket_price2."%' OR v.venueName LIKE
> '%".$vname."%'"
>
> If I replace OR with AND I dont get any result.
>
>
> Regards
>
> Nasreen
>
>
>


I would avoid the ORs and build the statement dynamically making for a
cleaner sql





-- 

Bastien

Cat, the other other white meat


Re: [PHP-DB] Create Search engine with multiple form fields

2008-06-29 Thread Roberto Costumero Moreno
Hi Nasreen,

Well, I think the better solution should be a dynamic query depending on
what you have entered in the form. The switch case is not valid in this
particular case because it will only select one of the fields, so the best
solution should be like this:

$query = "select * FROM gig g, venue v, genre ge"; //$query is the
"incremental" string in which we are building the final query.

//check if there will be a "where section"

if ($number_of_fields_filled_in > 0)
{
   $query = $query . " WHERE ";

if (isset($gig_name) && $gig_name != "" && $number_of_fields_filled_in > 0 )
//evaluate whether the variable is set and it is not blank
{
   $query = $query . "g.gigName LIKE '%".$gig_name."%'";
   $number_of_fields_filled_in--;
   if ($number_of_fields_filled_in > 0)
   {
  $query = $query . " AND ";
   }
}
if (isset($sdate) && isvaliddate($sdate) && $number_of_fields_filled_in > 0
) //check if $sdate is a valid date...
{
   $query = $query . "g.gig_date LIKE '%".$sdate."%'";
   $number_of_fields_filled_in--;
   if ($number_of_fields_filled_in > 0)
   {
  $query = $query . " AND ";
   }
}

... Etc.

}

So you make an "if" statement for every input field checking whether the
variable of that field is set (with php function isset( )) and if it follows
the rule you want to - the name is not blank (first case); the date is valid
according to a function isvaliddate ( )... If everything is right, you
concatenate the query you had with the specific "WHERE"-part for that input
field.

Note that we have a $number_of_fields_filled_in to check how many fields
have been filled in. You can make a function so as to check how many fields
are checked. Also note that I've put "if ($number_of_fields_filled_in > 0)"
and it takes inside EVERY check on the field variables. So if there is not a
single one, you don't make a wrong query. You check how many "WHERE" clauses
will be, and in every "if" statement you enter, you check if the number of
fields entered is > 0 and once the query is completed for that variable, you
check if there will be more statements (so as to add the "AND").

Finally, the only thing you have to do is send the query $query for
processing in the database.

I think this is one of the possible ways to do it. Check if you understand
the code above and try implementing.

Of course there should be more ways to do it, but it is one of the
simpliest.

Regards,

Roberto


On Sun, Jun 29, 2008 at 17:54, Nasreen Laghari <[EMAIL PROTECTED]>
wrote:

> Hi Roberto,
>
> You have got my point what I want to do. Do you think I should check and
> see which field's data has been entered and then make a dynamic query
> according to.
>
> Shall I use Switch- Case?? I have 6 fields so which way you think will be
> better to create dynamic query?
>
> Thank you
>
> Nasreen
> - Original Message 
> From: Roberto Costumero Moreno <[EMAIL PROTECTED]>
> To: Nasreen Laghari <[EMAIL PROTECTED]>
> Sent: Sunday, June 29, 2008 4:36:34 PM
> Subject: Re: [PHP-DB] Create Search engine with multiple form fields
>
> Hi,
>
> Let me see if I have understood what you want your application to do.
>
> You have a web form with several input fields, and ONE or SEVERAL can be
> filled in so as to search data, and I suppose you want your script to search
> data matching all filled in the form.
>
> With the actual Query, you are searching every content in the DB which has
> any coincidence with the data filled in the form. No matter which field is
> matching, it shows the complete data.
>
> If you change OR with AND, you are telling the DB to search if there is any
> data on it that matches EVERY field that you've sent. What happens if you
> don't fill any of the fields?
>
> The DB answers that it has no record like that, because comparison between
> the fields in DB and the input field is FALSE.
>
> All you have to do is to retrieve a correct "AND"-query with the parameters
> you've filled in.
>
> As an example imagine you fill only Date and Genre, so your query should
> look like this:
>
> select * FROM gig g, genre ge  WHERE g.gig_date LIKE '%".$sdate."%' AND
> ge.name LIKE '%".$genre."%'"
>
> So the script will search all data that has the Date "$sdate" and the Genre
> "$genre".
>
> Tell me if you've understood or if you need more help.
>
> Regads,
>
> Roberto
>
>
>
> On Sun, Jun 29, 2008 at 17:07, Nasreen Laghari <[EMAIL PROTECTED]>
> wrote:
>
>> Hi,
>>
>> I have an HTML form which has more then one fields. User can precise its
>> search using one or more input fields E.g GigName,Date, Genre,Venue.
>> The data is coming from 3 tables.  Below Query brings one tables record
>> with each and every row of other two tables. Could any one please help me
>> sort out the query.
>>
>> select * FROM gig g, venue v, genre ge  WHERE g.gigName LIKE
>> '%".$gig_name."%' OR g.gig_date LIKE '%".$sdate."%' OR ge.name LIKE
>> '%".$genre."%' OR g.ticket_price LIKE '%".$ticket_price1."%' OR
>> g.ticket_price LIKE '%".$ticket_price2."%' OR v.venueName 

[PHP-DB] Create Search engine with multiple form fields

2008-06-29 Thread Nasreen Laghari
Hi,
 
I have an HTML form which has more then one fields. User can precise its search 
using one or more input fields E.g GigName,Date, Genre,Venue. 
The data is coming from 3 tables.  Below Query brings one tables record with 
each and every row of other two tables. Could any one please help me sort out 
the query.
 
select * FROM gig g, venue v, genre ge  WHERE g.gigName LIKE '%".$gig_name."%' 
OR g.gig_date LIKE '%".$sdate."%' OR ge.name LIKE '%".$genre."%' OR 
g.ticket_price LIKE '%".$ticket_price1."%' OR g.ticket_price LIKE 
'%".$ticket_price2."%' OR v.venueName LIKE '%".$vname."%'"
 
If I replace OR with AND I dont get any result.
 
 
Regards
 
Nasreen


  

Re: [PHP-DB] PHP 5.2.6 integrating MYSQL 5.0.51b on APACHE 2.0.63 + Windows XP SP2)

2008-06-29 Thread simonclur

PHP v5.2.6 requires to the php_mysql.dll (v5.2.6) dll to connect to
MySql. 

It appears the PHP v5.2.6 .msi installation package apparently does not
copy the new php_mysql.dll into the ./ext directory as it is supposed
to.

Download the .zip version of php v5.2.6 and copy the php_mysql.dll file
from the zip archive to your /php/ext folder and make sure the following
line in your php.ini file is uncommented.

extension=php_mysql.dll

If you're having problems with "Unable to initialize module" for
php_mysql.dll then you have copied an incorrect version from a previous
or later release of php.

The php_mysql.dll file properties should show the following version
information for the dll:
File version: 5.2.6
Created: 11 January 2006 18h15


Jeff88 wrote:
> 
> Hi,
> 
> Good Day! I have problem in getting the PHP 5.2.6 to integrate with MYSQL
> 5.0.51b. I had done the following installations and configurations on
> Windows XP (SP2):
> 
> 1. Installed APACHE 2.0.63 - running fine
> 2. Installed PHP 5.2.6 - running fine
> 3. Configured httpd.conf and php.ini - PHP and APACHE is talking. I had
> tested with phpinfo(), both PHP and APACHE info displayed
> 4. Installed MYSQL 5.0.51b - running fine
> 5. I had done the followings try to get PHP5 talking to MYSQL:
>   a. uncommented extension=php_mysql.dll in php.ini
>   b. It does not work, so I copied the libmysql.dll from MYSQL5
> package to override the libmysql.dll in PHP package. It does not work
> either.
>   c. Tested with the phpinfo() but no mysql info displayed
> 
> Can anyone help me on this? Thank you.
> 
> Regards
> Jeff
>   
> 

-- 
View this message in context: 
http://www.nabble.com/PHP-5.2.6-integrating-MYSQL-5.0.51b-on-APACHE-2.0.63-%2B-Windows-XP-SP2%29-tp17201936p18179649.html
Sent from the Php - Database mailing list archive at Nabble.com.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php