Jump to content

MySQL search with filtering, please help!


phpnewnoob

Recommended Posts

Hi Everybody,

 

I think it's fairly simple, but i am a noob in PHP so need help from advanced coders.

 

I have MySQL table which is being filled up everyday, there are 7 fields in the table (submitter, choosebank, choosetype, ampaid, amret, date, descript).

What I need is to create a search.php which will be looking up data in all fields and printing it on the screen and the search should be filtered. What I mean is when a user wants to search for data let's say using submitter  who's name is Mitchel then it should search for all data and print all rows containing submitter (Mitchel) and the rest six fields. And if user searches let's say using submitter (Mitchel) and a certain date (let's say DEC-25-2011) then it should find all data containing Mitchel and DEC-25-2011 in the same row and print all rows which contain the same search parameter and the rest of the fields.

 

Any help would be greatly appreciated!

 

Here is the code I have so far, but it doesn't work.

 

<code>

 

<?php

 

include ("blocks/db.php");

 

$sql = mysql_query("SELECT * FROM banks WHERE submitter LIKE '$sub' or choosebank LIKE '$bank' or choosetype LIKE '$type' or $money_column LIKE '$money_column' or $money_value LIKE '$money_amount' or inputdate LIKE '$inputdate' or descript LIKE '$descript'") or die(mysql_error());

 

echo "<table width='1000' border='1' cellspacing='0' cellpadding='1'>";

echo "<tr>";

echo "<td width='100'>Submitter</td>";

echo "<td width='90'>Bank</td>";

echo "<td width='110'>Type of Payment</td>";

echo "<td width='110'>Amount Paid</td>";

echo "<td width='110'>Amount Returned</td>";

echo "<td width='100'>Date</td>";

echo "<td width='366'>Description</td>";

echo "</tr>";

echo "</table>";

 

while ($row = mysql_fetch_array($sql)){

 

echo "<table width='1000' border='1' cellspacing='0' cellpadding='1'>";

echo "<tr>";

echo "<td width='100'>$row[submitter]</td>";

echo "<td width='90'>$row[choosebank]</td>";

echo "<td width='110'>$row[choosetype]</td>";

echo "<td width='110'>$row[ampaid]</td>";

echo "<td width='110'>$row[amret]</td>";

echo "<td width='100'>$row[date]</td>";

echo "<td width='366'>$row[descript]</td>";

echo "</tr>";

echo "</table>";

 

}

 

?>

 

</code>

Link to comment
Share on other sites

Hi SergeiSS,

 

Hmm, that's a good question!

die(mysql_error()); reports that mysql_query near LIKE"" is not right, or something like that, I dont remember exactly, but I will check it out once I am at home and will post the HTML part  as well (which I should've done with the firt post) so that you have a better idea.

 

Thanks for th ereply! Appreciate that!

Link to comment
Share on other sites

First of all write you query to the variable

 

$query_str="SELECT * FROM banks WHERE submitter LIKE '$sub' or choosebank LIKE '$bank' or choosetype LIKE '$type' or $money_column LIKE '$money_column' or $money_value LIKE '$money_amount' or inputdate LIKE '$inputdate' or descript LIKE '$descript'";
// and then echo it
echo $query_str.'<br>';

 

Then check what do you have in this query. Write it here.... We will check together. And show the exact error message from MySQL. And also, please, don't show your PHP code if the problem is inside MySQL query :)

Link to comment
Share on other sites

Hey SergeiSS,

 

You were right, I echoed it and that's a query error.

I have rewrote the code and now it works, but there are still some issues with the date printout. I will give more details once I am back at home. I am going forward with your help!

 

Thanks for your reply, I appreciate that much!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.