pornflakes Posted August 13, 2009 Share Posted August 13, 2009 Hi guys, I got this problem with my search: it can´t find any results when the content of the form(select) has more than one word. i.e. if it´s filled with "nothing" the search results are fine but if it´s filled with "nothing here" it shows no results. It gets the list of the action from the mysql table fine. (the table has collums : id,code,action,date,insert) <form method="post" action="search.php"> Choose action:<br> <select name="laction"> <?php $query2 = mysql_query("SELECT DISTINCT action FROM test ORDER BY id"); while($col2 = mysql_fetch_array($query2)) { echo "<option value=" . $col2['action'] .">" . $col2['action'] . "</option>"; } ?> </select> <input type="submit" value="Search" /> </form> then searches <?php $laction=@$_POST["laction"]; if (isset($laction)){ $result = mysql_query("SELECT * FROM test WHERE LOWER(action) = LOWER('$laction') ORDER BY id"); } ?> This is where it shows the result. <?php echo "<table border='1'> <tr> <th>Code</th> <th>Action</th> <th>Date</th> <th>Insert</th> </tr>"; while($row = @mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['code'] . "</td>"; echo "<td>" . $row['action'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['insert'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> btw I´m still kinda new to this... Thanks for your time Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/ Share on other sites More sharing options...
MadTechie Posted August 13, 2009 Share Posted August 13, 2009 Could you post some samples of what you have tried and what's in the database, for example is "nothing here" in the database ? if you have something like their is nothing to be seen in here in the database and you want to find entries that that "nothing" and "here" then you could use LIKE SELECT * FROM test WHERE action LIKE '%nothing%' AND action LIKE '%here%' ORDER BY id or for fulltext searches SELECT * FROM test WHERE MATCH(action) AGAINST('nothing','here')ORDER BY id Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-897708 Share on other sites More sharing options...
pornflakes Posted August 13, 2009 Author Share Posted August 13, 2009 ok, the table looks like this : id code action date insert 1 655 nothing 12/08/2009 21:03 Luke 2 655 something 12/08/2009 21:03 dude1 3 700 nothing here 13/08/2009 19:59 dude1 the search from the form is fine for "nothing" and "something" is ok, but when I select "nothing here" in the form, the result of the search is empty Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-897713 Share on other sites More sharing options...
MadTechie Posted August 13, 2009 Share Posted August 13, 2009 Strange, (moving to SQL section) Any weird characters ? what about trying action LIKE '%nothing%here%' Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-897718 Share on other sites More sharing options...
pornflakes Posted August 13, 2009 Author Share Posted August 13, 2009 No weird characters, just text space and text. That should work, action LIKE '%nothing%here%' ...but I would need it to work with the variable... I just don´t understand how can it work perfectly fine when "nothing" or "something" is stored inside the variable, but when "nothing here" is stored there it doesn´t work... Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-897727 Share on other sites More sharing options...
pornflakes Posted August 14, 2009 Author Share Posted August 14, 2009 Some additional info... MySQL server version 5.3.0 I get no errors, it just doesn´t show any results. The table looks like this: CREATE TABLE `test` ( `id` int(15) NOT NULL AUTO_INCREMENT, `code` int(15) NOT NULL, `action` varchar(30) NOT NULL, `date` varchar(20) NOT NULL, `insert` varchar(25) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-897985 Share on other sites More sharing options...
MadTechie Posted August 14, 2009 Share Posted August 14, 2009 I couldn't see any reason for this not working so I tried it and it works fine SELECT * FROM `test` WHERE `action` = 'nothing here' 1 total, Query took 0.0009 sec) 3 700 nothing here 13/08/2009 19:59 dude1 Setup -- -- Table structure for table `test` -- CREATE TABLE `test` ( `id` int(15) NOT NULL auto_increment, `code` int(15) NOT NULL, `action` varchar(30) NOT NULL, `date` varchar(20) NOT NULL, `insert` varchar(25) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; INSERT INTO `test` (`id`, `code`, `action`, `date`, `insert`) VALUES (1, 655, 'nothing', '12/08/2009 21:03', 'Luke'), (2, 655, 'something', '12/08/2009 21:03', 'dude1'), (3, 700, 'nothing here', '13/08/2009 19:59', 'dude1'); Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-898010 Share on other sites More sharing options...
pornflakes Posted August 14, 2009 Author Share Posted August 14, 2009 Ya, exactly, but I posted it in PHP forum first because of this: <form method="post" action="search.php"> Choose action:<br> <select name="laction"> <?php $query2 = mysql_query("SELECT DISTINCT action FROM test ORDER BY id"); while($col2 = mysql_fetch_array($query2)) { echo "<option value=" . $col2['action'] .">" . $col2['action'] . "</option>"; } ?> </select> <input type="submit" value="Search" /> </form> The search in the mysql itself is fine, but when I use the variable for searching there is that problem. The problem is that I does not show any results when I use this html form to do the search... It loads the values from the table ok, does the search fine but only for the entries from the table, that have 1 word, for the "nothing here" value it does not find anything. Am I explaining my point wrong here or something?.. Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-898398 Share on other sites More sharing options...
MadTechie Posted August 14, 2009 Share Posted August 14, 2009 Echo the query to check its correct and valid Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-898536 Share on other sites More sharing options...
pornflakes Posted August 15, 2009 Author Share Posted August 15, 2009 Which query? if I echo echo $result; I get Resource id #7 echo $query2; I get Resource id #5 Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-898772 Share on other sites More sharing options...
pornflakes Posted August 15, 2009 Author Share Posted August 15, 2009 Finaly figured it out, I´ll just post it if someone makes the same mistake. In the select form I just changed the option value to id of the action and the search turned out fine. <form method="post" action="search.php"> Choose action:<br> <select name="laction"> <?php $query2 = mysql_query("SELECT DISTINCT id, action FROM test ORDER BY id"); while($col2 = mysql_fetch_array($query2)) { echo "<option value=" . $col2['id'] .">" . $col2['action'] . "</option>"; } ?> </select> <input type="submit" value="Search" /> </form> Then the select <?php $laction=@$_POST["laction"]; if (isset($laction)){ $result = mysql_query("SELECT * FROM test WHERE (id) = ('$laction') ORDER BY id"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170184-solved-problem-with-mysql-search/#findComment-898793 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.