gracie Posted March 31, 2008 Share Posted March 31, 2008 I'm working on a auction site and added a search feature to it. I can get it to return a search result using the following statements - $sqlString = "SELECT * FROM items WHERE name LIKE '%" . $search . "%' LIMIT $offset, $rowsPerPage"; $sqlResult = mysql_query($sqlString); $searchnumrows = mysql_num_rows($sqlResult); $String = "SELECT * FROM items WHERE name LIKE '%" . $search . "%' "; $Result = mysql_query($String); $numrows = mysql_num_rows($Result); I have a field in my 'items' table called dateends and i would like to return all the auction items that havent expired. I have tried the following statement and i get no result at all. i hope someone might be able to tell me i'm going wrong. Thanks. $sqlString = "SELECT * FROM nam_items WHERE dateends > NOW() AND name LIKE '%" . $search . "%' LIMIT $offset, $rowsPerPage"; $sqlResult = mysql_query($sqlString); $searchnumrows = mysql_num_rows($sqlResult); $String = "SELECT * FROM nam_items WHERE dateends > NOW() AND name LIKE '%" . $search . "%' "; $Result = mysql_query($String); $numrows = mysql_num_rows($Result); Quote Link to comment Share on other sites More sharing options...
aschk Posted April 1, 2008 Share Posted April 1, 2008 What datatype is your dateends column? It needs to be a datetime to work correctly when comparing against NOW(). Also, why are you doing the same statement twice, one with a limit and the other without? I should also point out that LIKE %string% will be HORRIBLY inefficient because NO INDEX can be used on it. Quote Link to comment Share on other sites More sharing options...
gluck Posted April 2, 2008 Share Posted April 2, 2008 I'm working on a auction site and added a search feature to it. I can get it to return a search result using the following statements - $sqlString = "SELECT * FROM items WHERE name LIKE '%" . $search . "%' LIMIT $offset, $rowsPerPage"; $sqlResult = mysql_query($sqlString); $searchnumrows = mysql_num_rows($sqlResult); $String = "SELECT * FROM items WHERE name LIKE '%" . $search . "%' "; $Result = mysql_query($String); $numrows = mysql_num_rows($Result); I have a field in my 'items' table called dateends and i would like to return all the auction items that havent expired. I have tried the following statement and i get no result at all. i hope someone might be able to tell me i'm going wrong. Thanks. $sqlString = "SELECT * FROM nam_items WHERE dateends > NOW() AND name LIKE '%" . $search . "%' LIMIT $offset, $rowsPerPage"; $sqlResult = mysql_query($sqlString); $searchnumrows = mysql_num_rows($sqlResult); $String = "SELECT * FROM nam_items WHERE dateends > NOW() AND name LIKE '%" . $search . "%' "; $Result = mysql_query($String); $numrows = mysql_num_rows($Result); As the earlier user said: your column type doesn't seem to match. Quote Link to comment 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.