| | |
hello and plz help
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
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 " <b>", $variable1.": <b> <br>";
echo " ", $variable2.": <b> <br>";
echo " ", $variable3.": <b> <br>";
echo " ", $variable4.": <b> <br>";
echo " ", $variable5.": <b> <br>";
}
//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
?>
// 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 " <b>", $variable1.": <b> <br>";
echo " ", $variable2.": <b> <br>";
echo " ", $variable3.": <b> <br>";
echo " ", $variable4.": <b> <br>";
echo " ", $variable5.": <b> <br>";
}
//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
?>
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?
For example, is the <SELECT> dropdown supposed to be table names or column names?
How does the value of $search get populated?
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
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?
Thanks
You haven't cleared up overall what you want, though. Please try to explain the concept of what you want again. Sorry.
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
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.
Thanks
To my knowledge, you'll have to query each table individually.
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
PHP Syntax (Toggle Plain Text)
SELECT name, website FROM beer WHERE name LIKE '%$search%' or website LIKE '%$search%' // Collect results here. SELECT name, website FROM wine WHERE name LIKE '%$search%' or website LIKE '%$search%' // Collect results here. SELECT name, website FROM cigars WHERE name LIKE '%$search%' or website LIKE '%$search%' // 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
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Troy
To my knowledge, you'll have to query each table individually.
PHP Syntax (Toggle Plain Text)
SELECT name, website FROM beer WHERE name LIKE '%$search%' or website LIKE '%$search%' // Collect results here. SELECT name, website FROM wine WHERE name LIKE '%$search%' or website LIKE '%$search%' // Collect results here. SELECT name, website FROM cigars WHERE name LIKE '%$search%' or website LIKE '%$search%' // 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
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Troy
To my knowledge, you'll have to query each table individually.
PHP Syntax (Toggle Plain Text)
SELECT name, website FROM beer WHERE name LIKE '%$search%' or website LIKE '%$search%' // Collect results here. SELECT name, website FROM wine WHERE name LIKE '%$search%' or website LIKE '%$search%' // Collect results here. SELECT name, website FROM cigars WHERE name LIKE '%$search%' or website LIKE '%$search%' // 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
Thanks
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.
![]() |
Similar Threads
- can someone plz help me with this? (Visual Basic 4 / 5 / 6)
- I NEED SUPPORT **"IMPORTANT"** PLZ HELP (Windows NT / 2000 / XP)
- Windows media player (Windows NT / 2000 / XP)
- Bridge.dll...Make it go away, Plz (Viruses, Spyware and other Nasties)
- can sum1 look @ dis plz (Viruses, Spyware and other Nasties)
- Hijackthis log file - plz help (Viruses, Spyware and other Nasties)
- IE not working...PLZ help :cry: (Web Browsers)
- PLZ help it's urgent! (Web Browsers)
- plz help ppl...... (Computer Science)
Other Threads in the PHP Forum
- Previous Thread: Sending attachements over php
- Next Thread: PHP Email
| Thread Tools | Search this Thread |
advanced ajax apache api array basics beginner binary broken cakephp check checkbox class cms code combobox cookies cron curl database date datepart display dynamic echo email error file files folder form forms function functions google head href htaccess html image include includingmysecondfileinthechain insert integration ip java javascript job joomla js limit link login loop mail menu mlm multiple mysql oop parse password paypal pdf php problem procedure query radio random recursion regex remote script search server sessions smarty smash sms soap source space sql stored syntax system table traffic tutorial unicode update upload url validator variable video web xml youtube





