954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php drop down menu to search multiple sql tables

I am about to pull what little hair I have let trying to figure if this is possible. On my website I have a drop down menu with different tables in the drop down part.

What I am trying to do is have a user choose the table to get info from then in the search box type in keywords of what to search for.

Can this be done if so HOW? :eek:

Thanks

my website has the menu I am talking about but of course it does not work. www.jci.tju.edu/~lwilliam/ Need to find a script or somewhere that shows me how to do it. (The tables are not related, some may have a feild or two that are the same.)

lawfour
Newbie Poster
11 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

The values in the dropdown are actual table names in your database? And you want the user to enter a search term, pick a database table, click submit, then see results from that table?

What database are you using? MySQL? Postgres? MSSQL? Oracle?

This is a simple thing to do unless one or more of the following statements are NOT true. Please reply to let us know where you need help.

1. I know how to submit an HTML FORM to a PHP page and work with the $_POST, $_GET, $_REQUEST objects.

2. I know how to connect to a database, query a database, and work with the results with PHP.

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

I am using MySQL

Q1. I know how to submit an HTML FORM to a PHP page and work with the $_POST, $_GET, $_REQUEST objects.

A1. I know how to submit an HTML form using PHP but I never used $_POST, $_GET, $_REQUEST at least not in php.

I use this to submit forms on my site:
mail("me@emailaddress.com", "KCC Abraham Gas Order", "Air Gas Link: weblink.php \n\n Investigator: $x_Investigator \n\n Requested by: $x_Requested_By \n\n Customer Number:",
"From: larry@{$_SERVER['SERVER_NAME']}\r\n" );

Q2. I know how to connect to a database, query a database, and work with the results with PHP.

A2. I use PHPMAKER to create my php/sql pages at the moment I am good at editing just about anything.

So I don't have a clue on where to start. This is as far as I can go

My Table Names

Airgas TicketsProductsPending RepairsCommon Equip.Lab Equip.VendorsRTP's

I know sad but I am trying.

Thanks

LW

lawfour
Newbie Poster
11 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

Hi Lawfour

Ok the first thing is I think your ready to move on to hand-writing your php instead of using a tool to do it for you. The people in this form are great and we can answer almost any question you have. -And while writing by hand might take a while at first you will eventually generate many methods and algorithms that you will re-use over and over so things will eventually become less frustrating.

Ok, here is how you will need to do form submission for now on. The mail() method simply wont work.

Make a form like this

[HTML]

onetwothree


[/HTML]

Notice that the submit button is not a type="submit". We are going to call a javascript function called validate first before we potentially send off bad info to the php page. the function looks like this

function validate() {

fm = document.thisForm

//use validation here to make sure the user entered
//the information correctly

fm.submit()

}


Notice that the form has an action="process.php". That means that there will be $_POST variables available to you in that php file. When the user hits the submit button and the javascript sends the form, the browser will re-direct to process.php

Here's what that page might look like

[PHP]<?php

echo $_POST['my_textbox'];
echo $_POST['my_dropdown'];

//The name of these post variables is the same as the name
//of the elements that were in the form

?>[/PHP]

Now, Let me know if your have grasped all that and if you respond (in otherwords if you have looked back on this thread which some people dont even do). Then perhaps Troy and I can help you with the database and dynamic form part

On a side note. If you would have used method="GET" in the form, you would use $_GET[] in the php

-B

bwest
Junior Poster in Training
57 posts since Jul 2004
Reputation Points: 14
Solved Threads: 1
 

Ok, I hope I got the code right so far, if it is, now I need to connect to database.

I created the process.php file with this info:

<?php

echo $_POST['my_textbox'];
echo $_POST['my_dropdown'];

//The name of these post variables is the same as the name
//of the elements that were in the form

?>

This is the search (live) htt://www.lawfour/esr/search.php

I added the JS right under the form post info.




Search:

  


Airgas TicketsProductsPending RepairsCommon Equip.Lab Equip.VendorsRTP's

 



lawfour
Newbie Poster
11 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

The javascript typically goes between the tags at the top of the page.

Here is a basic db connection class

[PHP]<?
class MyOps {

/* Global Variables */

var $conn = "localhost";
var $user = "db_username";
var $pass = "password";
var $db = "database_name";


/*****************dbconnect()***************************
* dbconnect() will remotely connect to a database *
* with a set of specified arguments. *
* *
* @conn = IP Address of the remote/local database *
* @user = DB Username *
* @pass = DB Password *
* @db = DB Name *
* *
*******************************************************/

function dbconnect() {

$link = mysql_connect($this->conn, $this->user, $this->pass, $this->db) or die("Could not connect : " . mysql_error());

$db_select = mysql_select_db($this->db) or die("error");

return $link;

}

}

?>[/PHP]


Then you import this file and use it like this in other php files that connect to the database

[PHP]
include ("db_scripts/dbconnect.php");

$dbops = New MyOps;
$link = $dbops->dbconnect();[/PHP]

Your overall page will look something like this

==============================start page
<?

//database connection

//query table names

//make a string of table names like this
$list = "ab";

?>

(javascript validation)


<?php echo $list; ?>

bwest
Junior Poster in Training
57 posts since Jul 2004
Reputation Points: 14
Solved Threads: 1
 


<?

include ("http://www.lawfour.com/esr/dbconnect.php");

$dbops = New MyOps;
$link = $dbops->dbconnect();
$list = "Common Equip.Lab Equip.VendorPending RepairsProductsPartsRTPAirgas Tickets";

?>






Search:

  


Airgas TicketsProductsPending RepairsCommon Equip.Lab Equip.VendorsRTP's

 




lawfour
Newbie Poster
11 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

(javascript validation)


Search:

  




<?php echo $list; ?>



<?
include ("http://www.lawfour.com/esr/dbconnect.php");
$dbops ="New MyOps";
$link ="$dbops->dbconnect()";
$list =" Common Equip.Lab Equip.VendorPending RepairsProductsPartsRTPAirgas Tickets ";
?>
Airgas TicketsProductsPending RepairsCommon Equip.Lab Equip.VendorsRTP's

 




lawfour
Newbie Poster
11 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 
Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

OK,

Thanks

lawfour
Newbie Poster
11 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

There really is almost all the code here in this thread that you would need. You just will need to implement your html and do the query. Besides that, the stuff above will be good for most of your project. As far as your connection goes and that fatal error. You might want to make sure you have properly set up the database. Sometimes the connection isnt "localhost" but is something else so check with your host. There could be about two dozen reasons why you cant connect but once you do just come back to this form because there's lots of good code here.

Good luck

bwest
Junior Poster in Training
57 posts since Jul 2004
Reputation Points: 14
Solved Threads: 1
 

Im having problem with my php and connect to multiple database. I use MySQL. I have index.php, process.php, search.php and dbconnect.php..When I try to run it just do nothing. just 'page error'..I don't know where the mistakes come from..

-----------------------------------------------------
I don't know exactly the common@basic page for process.php, and dbconnect.php..Help me..

zianchan
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

banner1.jpg Home       Admin       About Us         Words: Search Type PenyeliaNama PelajarProgram




zianchan
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

this happen when i submit search button

Parse error: parse error in c:\phpdev\www\projecttheses\process.php on line 11

the mistakes in here:echo_$POST['words'];

zianchan
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

(javascript validation)

banner1.jpg Home       Admin       About Us         Words: Search Type PenyeliaNama PelajarProgram




<?php echo $list?>;

zianchan
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You