hello and plz help

Reply

Join Date: Jul 2005
Posts: 5
Reputation: stangfl is an unknown quantity at this point 
Solved Threads: 0
stangfl stangfl is offline Offline
Newbie Poster

hello and plz help

 
0
  #1
Jul 6th, 2005
I am fairly new to PHP and MYSQL and was having a few problems getting a database search script to work. The data is input through an HTML form with an input field and drop down box to narrow results. This code will work for searching one table but as soon as I try and search multiple tables it returns 0 results. When using the drop down box PHP or MYSQL seems to only look at the table fields where the data is rather then the table as a whole. Those fields are name, address, website, telephone, location. Below the fields for the drop down are setup to how I would want them to work, as they are the table names : soda, chocolate, wine, cigars etc...If you can please help I'd appreciate it.... Heres the code

// HTML

...

<select name="metode" class="category_select">
<option value="name">Beer</option>
<option value="chocolate">Chocolate</option>
<option value="cigars">Cigars</option>
<option value="glass">Glass</option>
<option value="wine">Wine</option>
</select><br><br>

...

// PHP stuff

<? $hostname = "localhost"; // The Thinkhost DB server.
$username = "**"; // The username you created for this database.
$password = "**"; // The password you created for the username.
$usertable = "soda"; // The name of the table you made.
$dbName = "**"; // This is the name of the database you made.

MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
//error message (not found message)begins
$XX = "No Record Found, to search again please close this window";
//query details table begins
$query = mysql_query("SELECT name, website FROM $usertable WHERE $metode LIKE '%$search%' "); // problem AREA
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["soda"];
$variable2=$row["chocolate"];
$variable3=$row["cigars"];
$variable4=$row["glass"];
$variable5=$row["wine"];
//table layout for results


echo "&nbsp; <b>", $variable1.": <b> <br>";
echo "&nbsp; ", $variable2.": <b> <br>";
echo "&nbsp; ", $variable3.": <b> <br>";
echo "&nbsp; ", $variable4.": <b> <br>";
echo "&nbsp; ", $variable5.": <b> <br>";

}
//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: hello and plz help

 
0
  #2
Jul 6th, 2005
I'm quite confused both by what you say you want to do and by your code. Are you able to re-phrase this to make it clearer?

For example, is the <SELECT> dropdown supposed to be table names or column names?

How does the value of $search get populated?
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: stangfl is an unknown quantity at this point 
Solved Threads: 0
stangfl stangfl is offline Offline
Newbie Poster

Re: hello and plz help

 
0
  #3
Jul 6th, 2005
Originally Posted by Troy
I'm quite confused both by what you say you want to do and by your code. Are you able to re-phrase this to make it clearer?

For example, is the <SELECT> dropdown supposed to be table names or column names?

How does the value of $search get populated?
Orginally the <SELECT> had the column names, I am going to need it to be the table names. The $search is populated from the <input> tag on the form.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: hello and plz help

 
0
  #4
Jul 6th, 2005
You haven't cleared up overall what you want, though. Please try to explain the concept of what you want again. Sorry.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: stangfl is an unknown quantity at this point 
Solved Threads: 0
stangfl stangfl is offline Offline
Newbie Poster

Re: hello and plz help

 
0
  #5
Jul 6th, 2005
Originally Posted by Troy
You haven't cleared up overall what you want, though. Please try to explain the concept of what you want again. Sorry.
Overall I am looking to have a form that when submitted will search multiple tables in a database, in this case the tables are the soda, chocolate, cigars, glass, and wine. On the search page there is a <input> area as traditional on any search page to search all the database tables as well as a drop down box to refine the choice of searches to a particular table like soda or chocolate ... etc. The original one I made worked but with only column names in the drop down area and selecting one table to search from. When I tried to modify it to search multiple tables and changed the input of the columns to the tables no results could be found.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: hello and plz help

 
0
  #6
Jul 6th, 2005
To my knowledge, you'll have to query each table individually.

  1. SELECT name, website FROM beer WHERE name LIKE '%$search%' or website LIKE '%$search%'
  2. // Collect results here.
  3.  
  4. SELECT name, website FROM wine WHERE name LIKE '%$search%' or website LIKE '%$search%'
  5. // Collect results here.
  6.  
  7. SELECT name, website FROM cigars WHERE name LIKE '%$search%' or website LIKE '%$search%'
  8. // Collect results here.

You may also decide to setup fulltext indexes on your tables and use the match() function. http://dev.mysql.com/doc/mysql/en/fulltext-search.html
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: stangfl is an unknown quantity at this point 
Solved Threads: 0
stangfl stangfl is offline Offline
Newbie Poster

Re: hello and plz help

 
0
  #7
Jul 6th, 2005
Originally Posted by Troy
To my knowledge, you'll have to query each table individually.

  1. SELECT name, website FROM beer WHERE name LIKE '%$search%' or website LIKE '%$search%'
  2. // Collect results here.
  3.  
  4. SELECT name, website FROM wine WHERE name LIKE '%$search%' or website LIKE '%$search%'
  5. // Collect results here.
  6.  
  7. SELECT name, website FROM cigars WHERE name LIKE '%$search%' or website LIKE '%$search%'
  8. // Collect results here.

You may also decide to setup fulltext indexes on your tables and use the match() function. http://dev.mysql.com/doc/mysql/en/fulltext-search.html
Am I placing the table names in the drop down box for the form?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: stangfl is an unknown quantity at this point 
Solved Threads: 0
stangfl stangfl is offline Offline
Newbie Poster

Re: hello and plz help

 
0
  #8
Jul 6th, 2005
Originally Posted by Troy
To my knowledge, you'll have to query each table individually.

  1. SELECT name, website FROM beer WHERE name LIKE '%$search%' or website LIKE '%$search%'
  2. // Collect results here.
  3.  
  4. SELECT name, website FROM wine WHERE name LIKE '%$search%' or website LIKE '%$search%'
  5. // Collect results here.
  6.  
  7. SELECT name, website FROM cigars WHERE name LIKE '%$search%' or website LIKE '%$search%'
  8. // Collect results here.

You may also decide to setup fulltext indexes on your tables and use the match() function. http://dev.mysql.com/doc/mysql/en/fulltext-search.html
Also was just curious where the drop down box values are used to SELECT information in the above code.
Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: hello and plz help

 
0
  #9
Jul 6th, 2005
I'm not providing complete code for you, although I do provide paid programming consultation if you need a complete solution. Instead, I am trying to show you the concept to solve your problem. You already have code (apparently) to build the form and receive the form data. Your question is how to build queries to find the matches. My posts above are an attempt to answer that for you or at least help you find the answer.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC