Jump to content

searching mysql database using php


svgmx5

Recommended Posts

Hey everyone, i hope someone here can help me out with this small issue i have.

 

Currently i have a script that does a search query on my DB,i want it to search for three things, a starting date, an ending date and the state. Currently its only working if i search for a date and a state, but if i try to search for the startind date and endind date i get no results.

 

So what i'm trying to figure out is how to make it search for the starting date and ending date.

 

Currently on my database i have the id, name, city, state and date fields . the date field is filled out as follow: YYYY/MM/DD

 

And this is the script that does the query:

 

				if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
				   // cast var as int
				   $currentpage = (int) $_GET['currentpage'];
				} else {
				   // default page num
				   $currentpage = 1;
				} // end if
				$date = $_GET['fromDate'];
				$state = $_GET['state'];		
				$rowsperpage = 30;		
				$offset = ($currentpage - 1) * $rowsperpage;

				//retrieve the info from DB
				$sql = "SELECT COUNT(*) FROM leads WHERE date = '$date' && state = '$state'";
				$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);
				$r = mysql_fetch_row($result);
				$numrows = $r[0];
				$totalpages = ceil($numrows / $rowsperpage);		


				$sql = "SELECT * FROM leads WHERE date = '$date' && state = '$state' LIMIT $rowsperpage OFFSET $offset";

				$result = mysql_query($sql) or die("Problem, with Query:".mysql_error());	
				$num = 0;

 

Finally here is my form were i input the fields:

 

<form method="get" action="results.php">
            	<table width="800" align="right" cellpadding="0" cellspacing="5">
                
                	<tr>
                    
                    	<td width="233"><p>Date From:
                    	<input type="text" name="fromDate" />
                    	</p></td>
                        <td width="196"><p>
                        </p></td>
                        <td width="234"><p>State:
                        <input type="text" name="state" />
                        </p></td>
                      <td width="110">
                      <input type="hidden" name="searching" value='yes'/>
                  		<input name="search2" type="submit" id="search2" value="Search" />
                      </td>
                    
                    </tr>
                    
                </table>
          </form>

 

I hope someone can help me out wit this issue

 

Thanks in advanced!

Link to comment
https://forums.phpfreaks.com/topic/185614-searching-mysql-database-using-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.