can anyone help me how to create a search command....I am just new to php and I cant find any sites or tutorials to help me....

here is the story..

I want make a search box that will post all the scheduled trips with the corresponding destination, origin, date of arrival and date of departure......but I do not know how to do it....here is my code....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Partas Bus</title>
<style type="text/css">
body {
	background-color: #CEF7F5;
}
</style>
<link href="css/homelayout.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
  <div id="logo"></div>
  <div id="navigation"><a href="home.php">Home</a> | <a href="reservation.php">Reservation</a> | <a href="contactus.php">Contact Us</a></div>
  <div id="headerImg"></div>
  <div id="bodyArea">
  <div id="left"><h2>Trip </h2>
  <br/>
  <p> <select>
      <option>Origin</option>
      <option>Pasay City</option>
     <option>Cubao, Quezon City</option>
     <option>Sampaloc, Manila</option>
     <option>Angeles City, Pampanga(DMIA)</option>
     <option>Baguio City, Benguet</option>
     <option>Bangued, Abra</option>     <option>Candon City, Ilocos Sur</option>
     <option>Carmen, Pangasinan</option>
     <option>San Fernando City, La Union</option>
 	<option>Sison, Pangasinan</option>
<option>Tarlac City, Tarlac</option>
<option>Urdaneta City, Pangasinan</option>
<option>Vigan City, Ilocos Sur</option>
<option>Laoag City, Ilocos Norte</option>
</select></p>
<br/>
    <p> <select>
      <option>Destination</option>
      <option>Pasay City</option>
     <option>Cubao, Quezon City</option>
     <option>Sampaloc, Manila</option>
     <option>Angeles City, Pampanga(DMIA)</option>
     <option>Baguio City, Benguet</option>
     <option>Bangued, Abra</option>     <option>Candon City, Ilocos Sur</option>
     <option>Carmen, Pangasinan</option>
     <option>San Fernando City, La Union</option>
<option>Sison, Pangasinan</option>
<option>Tarlac City, Tarlac</option>
<option>Urdaneta City, Pangasinan</option>
<option>Vigan City, Ilocos Sur</option>
<option>Laoag City, Ilocos Norte</option>
</select></p>
<br />
<h15>Departure Date</h15>
<br />
<select>
<option>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>

</select>
<select>
<option>Day</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select>
<option>Year</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
</select></p>
<br /><br />
<h15>Return Date</h15>
<br />
<select>
<option>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>

<select>
<option>Day</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>

<select>
<option>Year</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
</select>

/* here is the code for the search button.....where should i place the command and how?*/
<br /><br />
 <form method="post" action="search_result.php?go" id="searchform" >			
<input type="submit" class="button" value="search"  name='submit'/>

</form> 
</div>
  <div id="right">
    <p>&nbsp;</p>
    <p><img src="images/wetakepride.jpg" width="754" height="253" /></p>
    <p>&nbsp;</p>
    <b>Partas Bus Company</b>
    <p>&nbsp;</p>
    <p>&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;A company owned by &nbsp;&nbsp;Mr. Chavit Singson, the company stands to their motto: <i>   &nbsp;&nbsp;We take pride in our courteous and safe drivers.</i>&nbsp;&nbsp;  Partas provide quality buses, trained drivers and safe trips for &nbsp;&nbsp;the satisfaction of their customers.</p>
    
  </div> 
  </div>
</div>
</body>
</html>

thank you very much if you could help me!!! i have been researching for two days straight without sleep..

Your opening <form> tag should be before your first select box to group all your form options into the same form. Then when you click the search button it will submit all their selections to your search_results.php page

what have you then been looking for?

1. in your posted file you need the attribute "name" in all of your <select>-tags. this makes php reefer to that value.
2. in the file search_result.php you do something like this:

<?php
$destination=$_REQUEST["destination"];    //your array passed to your file
$year=$_REQUEST["year"];                  // -"-
$r=mysql_query("SELECT * FROM ... WHERE `destination`='".$destination."' AND ` year`=".$year);
?>

you can then output your data with mysql_fetcharray or something similar.
You may want to vary your boolean logic in the mysql-statement.

Your search page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Partas Bus</title>
<style type="text/css">
body {
	background-color: #CEF7F5;
}
</style>
<link href="css/homelayout.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<div id="wrapper">
  <div id="logo"></div>
  <div id="navigation"><a href="home.php">Home</a> | <a href="reservation.php">Reservation</a> | <a href="contactus.php">Contact Us</a></div>
  <div id="headerImg"></div>
  <div id="bodyArea">
  <div id="left"><h2>Trip </h2>
  <br/>
  <?php 
  $data = array();
  $data['origins'] = array(0=>'Pasay City',1=>'Cubao, Quezon City',2=>'Sampaloc, Manila');
  $data['destinations'] = array(0=>'Pasay City',1=>'Cubao, Quezon City',2=>'Sampaloc, Manila');
  //could be same array?
  //arrays are good to test, they should be pulled from a database eventually of the available destinations/origins
  ?>
  <form method="post" action="search_result.php?go" id="searchform" >
  <p>
	<select name='origin'>
		<option>Origin</option>
		<?php 
		foreach($data['origins'] as $k=>$v){
			echo "		<option value='{$v}'>{$v}</option>\r\n";
		}
		?>
	</select>
	</p>
<br/>
    <p>
	<select name='destination'>
		<option>Destination</option>
		<?php 
		foreach($data['destinations'] as $k=>$v){
			echo "		<option value='{$v}'>{$v}</option>\r\n";
		}
		?>
	</select>
	</p>
<br />
<h15>Departure Date</h15>
<br />
<select name='dep_month'>
<option>Month</option>
<option value='1'>January</option>
<option value='2'>February</option>
<option value='3'>March</option>
<option value='4'>April</option>
<option value='5'>May</option>
<option value='6'>June</option>
<option value='7'>July</option>
<option value='8'>August</option>
<option value='9'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
 
</select>
<select name='dep_day'>
<option>Day</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
<select name='dep_year'>
<option>Year</option>
<option value='2012'>2012</option>
<option value='2013'>2013</option>
<option value='2014'>2014</option>
<option value='2015'>2015</option>
<option value='2016'>2016</option>
</select></p>
<br /><br />
<h15>Return Date</h15>
<br />
<select name='ret_month'>
<option>Month</option>
<option value='1'>January</option>
<option value='2'>February</option>
<option value='3'>March</option>
<option value='4'>April</option>
<option value='5'>May</option>
<option value='6'>June</option>
<option value='7'>July</option>
<option value='8'>August</option>
<option value='9'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
 
<select name='ret_day'>
<option>Day</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
 
<select name='ret_year'>
<option>Year</option>
<option value='2012'>2012</option>
<option value='2013'>2013</option>
<option value='2014'>2014</option>
<option value='2015'>2015</option>
<option value='2016'>2016</option>
</select>
 
/* here is the code for the search button.....where should i place the command and how?*/
<br /><br />
			
<input type="submit" class="button" value="search"  name='submit'/>
 
</form> 
</div>
  <div id="right">
    <p>&nbsp;</p>
    <p><img src="images/wetakepride.jpg" width="754" height="253" /></p>
    <p>&nbsp;</p>
    <b>Partas Bus Company</b>
    <p>&nbsp;</p>
    <p>&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;A company owned by &nbsp;&nbsp;Mr. Chavit Singson, the company stands to their motto: <i>   &nbsp;&nbsp;We take pride in our courteous and safe drivers.</i>&nbsp;&nbsp;  Partas provide quality buses, trained drivers and safe trips for &nbsp;&nbsp;the satisfaction of their customers.</p>
 
  </div> 
  </div>
</div>
</body>
</html>

search_result.php

<?php
foreach($_POST as $k=>$v){
echo $k.'-->'.$v."<br/>\r\n";
}
//will print out the vars being passed on from the search page
?>

I can help you Create a Table with all the data....
and then there can be Search box above every table.....so that if you want to filter data then you can do that by typing in the textbox....
like if you type "alaska" over the location row then all the rows containg ALASKA as location will only be displayed...
Tell me if you want to do this....i can tell you :)
Or you can mail me... hope this helped

If I can help you, can I at least get a free Bus pass? Where is this place though? :). If it is too far from Princeton, New Jersey, it's ok :).

Stop punishing your fingers by typing these

<select name='dep_day'>
<option>Day</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>

All dates, months, and years should be written in php like this

<?php
## you may want to write simple php function to get the number of days for the month
$days_ofMonth = 31;
echo '<select name="dep_day"/>';
for($dep_day = 1; $dep_day <= $days_ofMonth; $dep_day++){
?>
<option value="<?php echo $dep_day;?>"><?php echo $dep_day;?></option>
<?php
}
echo '</select>';
?>

You can focus more on your programming than typing identical numbers. Let the php work for you.

commented: helpful +4

i want it to be a drop down box......if i type that will it be still drop down???

All dates, months, and years should be written in php like this

<?php
## you may want to write simple php function to get the number of days for the month
$days_ofMonth = 31;
echo '<select name="dep_day"/>';
for($dep_day = 1; $dep_day <= $days_ofMonth; $dep_day++){
?>
<option value="<?php echo $dep_day;?>"><?php echo $dep_day;?></option>
<?php
}
echo '</select>';
?>

You can focus more on your programming than typing identical numbers. Let the php work for you.

I want it to be dropdown?? will it still be like a dropdown if i type this??

Thank you for all of your replies......i really appreciate it....

Yes, it will be in the dropdown.

search_result.php

<?php
foreach($_POST as $k=>$v){
echo $k.'-->'.$v."<br/>\r\n";
}
//will print out the vars being passed on from the search page
?>

where did you get $k and $v???

search_result.php

<?php
foreach($_POST as $k=>$v){
echo $k.'-->'.$v."<br/>\r\n";
}
//will print out the vars being passed on from the search page
?>

$k and $v are just made up variables.

foreach loops through an array of key and value pairs, so for short I call them $k and $v, you can actually name them what you like though.

for just values you could use:

foreach($cars as $car){
echo $car;
}


or with the key as well:

foreach($cars as $carid=>$car){
echo $carid.$car;
}

I tried everything that you suggested and I come up of this search command

<title>Partas Bus</title>
<style type="text/css">
body {
	background-color: #CEF7F5;
}
</style>
<link href="css/homelayout.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
  <div id="logo"></div>
  <div id="navigation"><a href="home.php">Home</a> | <a href="reservation.php">Reservation</a> | <a href="trips.php"> Trips</a> | <a href="contactus.php">Contact Us</a> | <a href="ticket.php"> Ticket</a></div>
  <div id="headerImg"></div>
  <div id="bodyArea">
  <div id="left"><h2>Trip </h2>
  <br/>
  
  <form method="post" action="search_result.php" >
  <p> <select>
      <option>Origin</option>
      <option>Pasay City</option>
     <option>Cubao, Quezon City</option>
     <option>Sampaloc, Manila</option>
     <option>Angeles City, Pampanga(DMIA)</option>
     <option>Baguio City, Benguet</option>
     <option>Bangued, Abra</option>     <option>Candon City, Ilocos Sur</option>
     <option>Carmen, Pangasinan</option>
     <option>San Fernando City, La Union</option>
 	<option>Sison, Pangasinan</option>
<option>Tarlac City, Tarlac</option>
<option>Urdaneta City, Pangasinan</option>
<option>Vigan City, Ilocos Sur</option>
<option>Laoag City, Ilocos Norte</option>
</select></p>
<br/>
    <p> <select>
      <option>Destination</option>
      <option>Pasay City</option>
     <option>Cubao, Quezon City</option>
     <option>Sampaloc, Manila</option>
     <option>Angeles City, Pampanga(DMIA)</option>
     <option>Baguio City, Benguet</option>
     <option>Bangued, Abra</option>     <option>Candon City, Ilocos Sur</option>
     <option>Carmen, Pangasinan</option>
     <option>San Fernando City, La Union</option>
<option>Sison, Pangasinan</option>
<option>Tarlac City, Tarlac</option>
<option>Urdaneta City, Pangasinan</option>
<option>Vigan City, Ilocos Sur</option>
<option>Laoag City, Ilocos Norte</option>
</select></p>
<br />
<h15>Departure Date</h15>
<br />
<select>
<option>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>

</select>
<select>
<option>Day</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select>
<option>Year</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
</select></p>
<br /><br />


 			
<input type="submit" class="button" value="search"  name='submit'/>

</form>

and here is my search_result command

<title>Partas Bus</title>
<style type="text/css">
body {
	background-color: #CEF7F5;
}
</style>
<link href="searchresultlayout.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">

  <div id="logo"><a href="home.php">Home</a> | <a href="reservation.php">Reservation</a> | <a href="trips.php"> Trips</a> | <a href="contactus.php">Contact Us</a> | <a href="ticket.php"> Ticket</a></div>
  <div id="headerImg"></div>
 
  </div>
  
  <form method="post" action="search_result.php" >
</form>
  
  <div id="bodyArea"></div>
  
  <br />
 
      <table border="1">
		<tr>
				<th>Origin</th>
				<th>Destination</th>
				<th>Date of Departure</th>
				<th>Time</th>
                <th>Fare</th>
				
                
		</tr>
        
 <tr >
		
<?php

			mysql_connect("localhost","root","") or die(mysql_error()); 
mysql_select_db("ticket_reservation") or die(mysql_error()); 

            $search = $_POST['search'];
		$result= mysql_query("Select * From tbltrip_info WHERE origin_description LIKE '%$search%' || destination_description LIKE '%$search%'|| date LIKE '%$search%'");
		
while ($res = mysql_fetch_array($result))
		  {

		$origin_description = $res['origin_description'];
		$destination_description = $res['destination_description'];
		$date = $res['date'];
		$time = $res['time'];
		$fare = $res['fare'];
	
		
				/*echo "<table width='400' border='1' cellspacing='0' cellpadding='3'>";
				echo '<th><b>Origin description</b></th><th><b>Destination description</b></th><th><b>date</b></th>';*/
				echo '<tr><td class="rows">'; echo $origin_description; '</td></tr>';
				echo '<td class="rows">'; echo $destination_description; '</td>';
				echo '<td class="rows">'; echo $date = $res; '</td>';
				echo '<td class="rows">'; echo $time = $res; '</td>';
				echo '<td class="rows">'; echo $fare= $res; '</td>';
				
		echo '</tr>';
		
			}

mysql_close();


echo '</table>';

 
 ?>
 
 
</body>
</html>

Still it is still not working....can you help me find what is wrong with my codes??? I am begging you.........

Hi,

Something is wrong with these echoes..

echo '<tr><td class="rows">'; echo $origin_description; '</td></tr>';
echo '<td class="rows">'; echo $destination_description; '</td>';
echo '<td class="rows">'; echo $date = $res; '</td>';
echo '<td class="rows">'; echo $time = $res; '</td>';
echo '<td class="rows">'; echo $fare= $res; '</td>';
 
echo '</tr>';

it should be something like

echo '<tr><td class="rows">'.$origin_description.'</td></tr>';
echo '<td class="rows">'.$destination_description.'</td>';
echo '<td class="rows">'.$date = $res.'</td>';
echo '<td class="rows">'.$time = $res.'</td>';
echo '<td class="rows">'.$fare= $res.'</td>';
 
echo '</tr>';

And these

echo '<td class="rows">'.$date = $res.'</td>';
echo '<td class="rows">'.$time = $res.'</td>';
echo '<td class="rows">'.$fare= $res.'</td>';

Although it will get outputted , it is not standard. It should be define before echoing them. Your codes will look nice and well organized.

ADDED LATER on EDIT

The above should be changed to these, because the values has already been assigned from the query results.

echo '<td class="rows">'.$date.'</td>';
echo '<td class="rows">'.$time.'</td>';
echo '<td class="rows">'.$fare.'</td>';

OR to these

echo '<td class="rows">'.$res['date'].'</td>';
echo '<td class="rows">'.$res['time'].'</td>';
echo '<td class="rows">'.$res['fare'].'</td>';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.