Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2007, 09:58 AM
Authorized User
 
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mark jonas
Default searching a database

hello

ok what i wont to do is search a database which has 3 fields name town and county now i can seach and find things for name without a problem but when it comes to town and county i wont it to return the name of the place in that row i have try loads of ways and havnt had any luck could someone please point me in the right place have tryed searching the web and so on with no joy.

hope this makes sense thanks in advance

mark

 
Old January 18th, 2007, 11:07 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Show me your query.

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile
================================================== =========
 
Old January 18th, 2007, 12:03 PM
Authorized User
 
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mark jonas
Default

     if (empty($nameField) and !empty($townField) and empty($countyField)){
            
             $result = mysql_query("SELECT town FROM hotels");

                        while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {

                                             if (eregi("$townField", $row[0])){
                                            
                                                             $name_query = "SELECT name from hotels WHERE (MATCH(town) AGAINST('*$row[0]*')";
                                                                     $Name = mysql_query($name_query);
                                                                    
                                                             while ($name_field = mysql_fetch_array($Name, MYSQL_BOTH)){
                                                            
                                                                             printf("<a href=\"$target?name=$Name\">$Name</a><br />");
                                                                    
                                                                 }
                                                                    
                                             }
                                            
                        }

                     mysql_free_result($result); exit;
                    
     }
    
     [u]county area</u>
     if (empty($nameField) and empty($townField) and !empty($countyField)){
                        
     }

else{
    
                 echo "There was an error please try again.By using the back button";
    
     }

}

else{

         echo "Please set the required hidden inputs";
        
}


hope this helps like i say i have the search for names working fine just cant get around the other two sorry if this is long winded still new to phpp and mysql but it does what i wont it to so fair
in the town area is the last way i tryed which is proply way out

and there is anything for county as it will be a case of the same as town just searching a different coloum
cheers
mark
 
Old January 18th, 2007, 12:21 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Just an FYI I am not a PHP Programmer so if there is a syntactial error in your PHP code I will not pick up on it; I do understand what your code is trying to do though.

Have you done this:
echo $name_query

Inside your town area block to see what your sql statements are equating to? I would start there as it is likely the values you *think* are being passed in actually are not.

HTH.

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile
================================================== =========
 
Old January 18th, 2007, 12:48 PM
Authorized User
 
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mark jonas
Default

yea that fines i no its not to do with the php coding yea was one type but i have since then corrected and tryed it unless i am handling it wrong after it does the query just wont to make shore i have the query part right first.

ok just did that and it is pass the information into the query for the database so it says

searched for 'ma'
SELECT name from hotels WHERE (MATCH(town) AGAINST('*main*')
SELECT name from hotels WHERE (MATCH(town) AGAINST('*mayfair*')



 
Old January 18th, 2007, 12:52 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok what happens if you execute these queries in MySQL? Does the query bomb, does it return you the results you are looking for?

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile
================================================== =========
 
Old January 18th, 2007, 01:11 PM
Authorized User
 
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mark jonas
Default

it shows the echo statment which is right

SELECT name from hotels WHERE (MATCH(town) AGAINST('*main*')
SELECT name from hotels WHERE (MATCH(town) AGAINST('*mayfair*')

which would make an array of town names that then is used to get the name am i right in saying that


then just a blank screen when i would like it to show a link with the name of the place i put it in the while and fetch the array then print the info

while ($name_field = mysql_fetch_array($Name, MYSQL_BOTH)){
printf("<a href=\"$target?name=$Name\">$Name</a><br />");
}

think thats right
 
Old January 18th, 2007, 01:26 PM
Authorized User
 
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mark jonas
Default

ok just changed my query to

$name_query = "SELECT name from hotels WHERE town='$row[0]'";

which has worked but i am getting this

name1
name2
name3
name4
name1
name2

which is half way there i guess this is more on the php side now then mysql query (please correct me if i am wrong)

and thanks for you time and help if it is more of a php problem now
cheers
mark
 
Old January 18th, 2007, 01:44 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Normally when you are not getting the data you expect from a Database its because of the query, not the language being used to send the query to the database.

Try this:
$name_query = "SELECT DISTINCT name from hotels WHERE town='$row[0]'";

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile
================================================== =========
 
Old January 18th, 2007, 01:54 PM
Authorized User
 
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mark jonas
Default

yea thats passing the right information now it just repeating the first and last row in the database if it meets the search primaiters

so ie

database

name town
name1 may
name2 ash
name3 may
name4 may

so i search may

it returns
name1
name3
name4
name1
name4

which is right just the first and last row of the database is repeated which is wrong

but if i was to search ash it returns

name2

which is right

cheers mark





Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching through a database d5t ASP.NET 1.0 and 1.1 Basics 6 October 27th, 2006 07:10 AM
help with Database searching europhreak Classic ASP Basics 1 February 8th, 2006 07:30 AM
Searching the database...HELP! Zedman BOOK: Beginning ASP 3.0 6 September 30th, 2004 09:52 AM
Searching trough a database toni_montana PHP How-To 2 September 25th, 2004 09:17 AM
searching a database shabazzk Classic ASP Databases 2 March 10th, 2004 06:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.