phpnewnoob Posted January 3, 2012 Share Posted January 3, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/254248-mysql-search-with-filtering-please-help/ Share on other sites More sharing options...
Pikachu2000 Posted January 3, 2012 Share Posted January 3, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/254248-mysql-search-with-filtering-please-help/#findComment-1303576 Share on other sites More sharing options...
phpnewnoob Posted January 3, 2012 Author Share Posted January 3, 2012 Oh, sorry, will take into consideration. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/254248-mysql-search-with-filtering-please-help/#findComment-1303578 Share on other sites More sharing options...
SergeiSS Posted January 3, 2012 Share Posted January 3, 2012 You wrote a lot of PHP code, but start the name of your topic from word 'MySQL'. And where do you have a problem - in PHP or in MySQL query? Quote Link to comment https://forums.phpfreaks.com/topic/254248-mysql-search-with-filtering-please-help/#findComment-1303608 Share on other sites More sharing options...
phpnewnoob Posted January 3, 2012 Author Share Posted January 3, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/254248-mysql-search-with-filtering-please-help/#findComment-1303791 Share on other sites More sharing options...
SergeiSS Posted January 3, 2012 Share Posted January 3, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/254248-mysql-search-with-filtering-please-help/#findComment-1303862 Share on other sites More sharing options...
phpnewnoob Posted January 4, 2012 Author Share Posted January 4, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/254248-mysql-search-with-filtering-please-help/#findComment-1304218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.