How to query SELECT SUM of Total from three different table php - php

Hope you good Guys! I have a big problem on SELECT three different table and SUM there Total so that I may get Grand total of those three tables.
The table as follows, I just mention some of fields:
1:payment
id idnumber school_fee trans_fee
1 va03 10000 20000
2:payment_one
id idnumber school_fee trans_fee
1 va01 10000 30000
3:payment_two
id idnumber school_fee trans_fee
1 va02 40000 50000
I have already get 'Total' from each table, what I want is to SUM UP those Total I get, to have Grand total from those three tables.
Here my php codes;
1:payment:
<?php
//include mysql connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT
*,SUM(school_fee+trans_fee)
As Total FROM payment
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
$raw_results2 = mysql_query("SELECT * FROM payment
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
if(mysql_num_rows($raw_results2) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
// $results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show id
($results['id'])
}{
echo " Total amount of money payed by " .$results['class']
." "."class is " . $results ['Total'] . " /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
}
?>
2:payment_one
<?php
//include mysql connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT
*,SUM(school_fee+trans_fee)
As Total FROM payment_one
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
$raw_results2 = mysql_query("SELECT * FROM payment_one
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
if(mysql_num_rows($raw_results2) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
// $results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show id
($results['id'])
}{
echo " Total amount of money payed by " .$results['class']
." "."class is " . $results ['Total'] . " /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
}
?>
3:payment_two
<?php
//include mysql connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT
*,SUM(school_fee+trans_fee)
As Total FROM payment_two
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
$raw_results2 = mysql_query("SELECT * FROM payment_two
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
if(mysql_num_rows($raw_results2) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
// $results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show id
($results['id'])
}{
echo " Total amount of money payed by " .$results['class']
." "."class is " . $results ['Total'] . " /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
}
?>
Any help I'will be thankfully.

If I understand correctly, all of your three tables [payment][payment_one][payment_two] have same columns: id, idnumber, school_fee trans_fee.
You would be able to use one single table instead, and distinguish them by introducing a new column: tablenum, then it will be simple to obtain what you want. Please note both [id] and [tablenum] are primary key (composite primary key) now.
New table schema and the data would be (I'm not very sure about the purpose of your idnumber column):
[payment]
id tablenum idnumber school_fee trans_fee
1 0 va03 10000 20000
1 1 va01 10000 30000
1 2 va02 40000 50000
SQL example:
SELECT
school_fee,
trans_fee,
(school_fee + trans_fee) as 'total'
FROM payment WHERE id=1

Related

How to submit row from one table to another using php, msqli

I have the following php search script.
<?php
$query = $_GET['query'];
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT * FROM florinvtable
WHERE (`Brand` LIKE '%".$query."%') OR (`Description` LIKE '%".$query."%') OR (`Category` LIKE '%".$query."%')
ORDER BY Category, Brand, Price") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo "<div style='position:relative; font-size:18px; width:500px;'><span style='font-size:14px'>".$results['Category']."</span> - <strong>".$results['Brand']."</strong> - ".$results['Description']." - <span style='color:red;'>$".$results['Price']."</span> ".$results['Size']."</div>";
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
}
else{ // if there is no matching rows do following
echo "No results";
}
}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;
}
?>
I would like to incorporate a submit button for each row displayed that I can click on to copy a row to an identical separate table. You might ask, why maintain two identical tables? The answer is the original table is frequently truncated. That said, how would I incorporate a submit button into the above script using the script below.
<?php
$query = "INSERT INTO floradtable (Category, Brand, Price)
SELECT Category, Brand, Price FROM florinvtable
WHERE id='".$mysqli->real_escape_string($_REQUEST['id'])."'
LIMIT 0,1";
$mysqli->query($query);
?>
As a side note, I know I am mixing mysql with mysqli which I will address after I work out a solution for the current problem. Any help is appreciated.
Add this.
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
$query = "INSERT INTO floradtable (Category, Brand, Price) VALUES";
while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
$query .= "('".$results['Category']."','".$results['Brand']."','".$results['Price']."'),";
echo "<div style='position:relative; font-size:18px; width:500px;'><span style='font-size:14px'>".$results['Category']."</span> - <strong>".$results['Brand']."</strong> - ".$results['Description']." - <span style='color:red;'>$".$results['Price']."</span> ".$results['Size']."</div>";
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
$query = substr($query, 0, -1);//to remove the trailing comma
$mysqli->query($query);
}

php search query only outputs two results...not the entire row

Hi I have a search query in index.html..when the user presses search...it goes to searchjobs.php.
I would like it to output the entire row. Which is
job_id
job_title
job_description
job_location
job_category
Currently it's only outputting only two of those fields which is job_title and job _description. How do I make it output the entire row? For example if the person searches for 'Leeds' I would like it to output the entire row about the job in leeds.
I think the issue is in the echo area.
If I enter more variables in the php script...it won't run.
<?php
mysql_connect("*****", "root", "*****") or die("Error connecting to database: ".mysql_error());
/*
if connection fails it will stop loading the page and display an error
*/
mysql_select_db("jobslist") or die(mysql_error());
/* tutorial_search is the name of database we've created */
$query = $_GET['query'];
// gets value sent over search form
$min_length = 4;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT * FROM jobs_list
WHERE (`job_title` LIKE '%".$query."%') OR (`job_location` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// jobs_list is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo "<p><h3>".$results['job_id']."</h3>"
.$results['job_title'].
.$results['job_description'].
.$results['job_location'].
.$results['job_category'].
"</p>";
// posts results gotten from database you can also show id ($results['id'])
}
}
else{ // if there is no matching rows do following
echo "No results";
}
}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;
}
?>
You are using concatination dots on both sides of the variable, remove the extra dots:
echo '<p><h3>'.$results['job_id'].'</h3>'
. $results['job_title']
. $results['job_description']
. $results['job_location']
. $results['job_category']
. '</p>';
I assume you are currently testing and trying, otherwise you should structure your job description properly i.e.
$tplJob= '<div class="job_entry">
<h3>ID: %s</h3>
<div class="title">%s</div>
<div class="description">%s</div>
<div class="location">Location: %s</div>
<div class="category">Category: %s</div>
</div>';
// echo formatted output based on above template variable
echo sprintf($tplJob, $results['job_id'], $results['job_title'], $results['job_description'], $results['job_location'], $results['job_category']);

Change + to an & in search string

I'm pretty new to PHP and have this script that I am using to search a database I have for jobs. The problem is when the query arrives to this script it looks something like this search-result.php?query=engineer+sydney ... However, I need search for both words together and appear like this search-result.php?query=engineer&sydney with the & instead of the +
Is this something I should be trying to do from the search form or within the search script itself? I've added the search script below and the form below that.
Any help would be great!
<div class="joblist">
<?php
$query = $_GET['query'];
$query = sanitise($query);
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT * FROM job_jobs
WHERE (`description` LIKE '%".$query."%') OR (`summary` LIKE '%".$query."%') OR (`title` LIKE '%".$query."%') OR (`location` LIKE '%".$query."%') ") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo "<h3 style='padding:0;margin:0;'><a href='job-view.php?query=".$results['jid']."'>".$results['title']. "</a></h3>";
echo "<i style='color:#999;'>Posted on: " . date("jS M Y", strtotime($results['dateposted']))."</i><br/>" . $results['summary'] . "<br/>";
echo "Salary: " . $results['rate'] . " | Work Type: " . $results['worktype'] . " | Location: " . $results['location'];
echo "<br/><br/>";
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
}
else{ // if there is no matching rows do following
echo "<h3>No Results</h3>Your search returned no results. Please try again.";
}
}
else{ // if query length is less than minimum
echo "<h3>Error</h3>The minimum length is $min_length characters. Please try again.";
}
?>
</div>
<nav class="widget-search">
<h3>Search for a Job</h3>
<form action="search-result.php" method="GET">
<button class="search-btn-widget"></button>
<input class="search-field" type="text" name="query" onblur="if(this.value=='')this.value='eg. Civil Engineer Perth';" onfocus="if(this.value=='eg. Civil Engineer Perth')this.value='';" value="eg. Civil Engineer Perth" />
</form>
</nav>
whenever you send data using GET method it forms a NAME=VALUE pair.and the '+' you are seeing is whitespace which some browser use % or some may use + also.
query=engineer+sydney
----^name-------^value
$query = $_GET['query'];
$query =str_replace(" ","&",$query);
now what you can do is fetch the query value and replace the whitespace with '&' or whatever sign you want
$result = str_replace('+','&',$_GET["query"]);
echo $result;
Thanks
break your query variable with space
$arr_query = explode(" ",$query);
now make a dynamic where
$where = ""
$i=0;
foreach($arr_query as $val)
{
$i+=1;
if($i==1)
{
$where .= " WHERE (`description` LIKE '%".$val."%') OR (`summary` LIKE '%".$val."%') OR (`title` LIKE '%".$val."%') OR (`location` LIKE '%".$val."%') ";
}
else
{
$where .= " AND (`description` LIKE '%".$val."%') OR (`summary` LIKE '%".$val."%') OR (`title` LIKE '%".$val."%') OR (`location` LIKE '%".$val."%') ";
}
}
now you can use this $where in you query as follows.
$raw_results = mysql_query("SELECT * FROM job_jobs $where ") or die(mysql_error());

How to SUM, SUM of Total from three table

Sorry I would like to repeat the question since I think was not clear to you, Im doing this b'cose is difficult to me to get what I expect.
I want to get SUM of Total which i get from three table from single query, Here my tables!!
1: payment
id | school_fee | trans_fee
1 20000 3000
2 10000 2000
The total is 35000
and the codes is here
<?php
//mysql_connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT SUM(school_fee+trans_fee) As Total
FROM payment WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`,
`title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example
if
$query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
//
$results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show
id ($results['id'])
}{
echo " Total amount of money payed by "
.$results['class'] ." "."class is " . $results ['Total'] .
" /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
?>
2:payment_one
id | school_fee | trans_fee
1 10000 20000
2 30000 50000
The Total is 110000
The CODEs is the same with the first one table except name of the table
here the codes
<?php
//mysql_connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT SUM(school_fee+trans_fee) As Total
FROM payment_one WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`,
`title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example
if
$query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
//
$results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show
id ($results['id'])
}{
echo " Total amount of money payed by "
.$results['class'] ." "."class is " . $results ['Total'] .
" /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
?>
The last one is
3: payment_two
id | school_fee | trans_fee
1 10000 20000
2 30000 10000
The Total is 70000
Codes as follows
<?php
//mysql_connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT SUM(school_fee+trans_fee) As Total
FROM payment_two WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`,
`title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example
if
$query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
//
$results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show
id ($results['id'])
}{
echo " Total amount of money payed by "
.$results['class'] ." "."class is " . $results ['Total'] .
" /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
?>
So I want to query by php so that I may get 215000 as Grand total of those three table,
I need the help please.
NOTE: id is auto increament.
You could do that with UNION:
SELECT SUM(total) FROM
(
SELECT SUM(school_fee+trans_fee) As Total
FROM payment
UNION
SELECT SUM(school_fee+trans_fee) As Total
FROM payment_one
UNION
SELECT SUM(school_fee+trans_fee) As Total
FROM payment_two
) a
sqlfiddle demo

php searching multiple fields on msql and return exactly answer

my be i may change the question explanation since no any help,But I real want help.
I have a search box in my form which enable user to search student data in mysql table, I only succeed on searching single field eg (first name or second name or sir name) the BIG problem to me is how to search multiple field on the same text input field or any number of text input field eg(text1, text2, text3) only I want is to have exactly result. Sorry if any mistake.
Here the php codes I use to get single field search.
<html>
<head></head>
<body><input type="text" name="query" value=""/>
<input name="submit" type="submit" value="Search" />
<?php
$query="query";
//mysql_connect
$query='query';
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
$raw_results = mysql_query("SELECT * FROM stdreg_exam
WHERE (`fname` LIKE '%".$query."%') or (`secname` LIKE '%".$query."%')or
(`date` LIKE '%".$query."%') or (`surname` LIKE '%".$query."%')") or
die(mysql_error());
$raw_results2 = mysql_query("SELECT(idnumber) FROM student
WHERE (`fname` LIKE '%".$query."%') or (`secname` LIKE
'%".$query."%') or (`date` LIKE '%".$query."%')or
(`surname` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
// if one or more rows are
returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
// $results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
echo "<table width='750' height='5' cellpadding='2'
cellspacing='0' border='0'>";
echo"<tr><td>Std_id</td><td>Mathematics</td><td>English</td>
<td>Kiswahili</td><td>Geograph</td><td>Ict</td><td>Science</td>
<td>History</td><td>Pds</td><td>V skill</td><td>French</td>
<td>Religion</td><td>Civics</td>";
echo "<h4> ".$results['exam_name']." Examination result for
" .$results['fname']." " .$results['secname']
." ".$results['surname']." ".$results['class']." Class"."
held on</p>".$results['date']."<hr><th>"; echo"<tr>";
echo ""."<td>".$results2['idnumber'].""."<td>".$results['mathematics']."%"."
<td>".$results['english']."%"."<td>".$results['kiswahili']."%"."
<td>".$results['geograph']."%"."<td>".$results['ict']."%"."
<td>".$results['science']."%"."<td>".$results['history']."%"."
<td>".$results['pds']."%"."<td>".$results['vskill']."%"."
<td>".$results['french']."%"."<td>".$results['religion']."%"."
<td>".$results['civics']."%"."</td></p>";echo"</table>";
//posts results gotten from database(title and text) you can also show id
($results['id'])
}
}
}
else{
// if there is no matching rows do following
echo "No such information in School database";
}
}
else{
// if query length is less than minimum
echo "Enter more strings!!!Minimum length is ".$min_length; "Charactes";
}
?>
If you have 3 text fields, let's say text1, text2 and text3 and you need to get search result from DB. You could try something like this
$query = "SELECT your_feilds,another_fields FROM your_table WHERE 1=1 ";
if($_POST['text1'])
$query .= " AND text1_field like '%$_POST['text1']%' ";
if($_POST['text2'])
$query .= " AND text2_field like '%$_POST['text2']%' ";
if($_POST['text3'])
$query .= " AND text3_field like '%$_POST['text3']%' ";
$result = mysql_query($query);
The above answer from #Shafeeq is very functional and is working as I have used the same approach for one of my applications, but there is one issue, if you have a another field let us say date and you want to search between two dates.
The query will be like that
if($_POST['from_date'] && $_POST['To_date'])
$query .= " AND date between '$from_field' AND '$To_field' ";
Then It does not work for other fileds

Categories