Dysan Posted January 18, 2008 Share Posted January 18, 2008 Hi, How do I search the database for the name "Simon"? Then, if it exists output "Exists". If it doesn't exist, output "Not Found"? Quote Link to comment https://forums.phpfreaks.com/topic/86705-not-found-message/ Share on other sites More sharing options...
revraz Posted January 18, 2008 Share Posted January 18, 2008 $query = "SELECT username FROM table WHERE username = 'Simon'"; $result = mysql_query($query); if (mysql_num_rows ($result) > 0) { echo "Exists"; } else { echo "Not Found"; } Quote Link to comment https://forums.phpfreaks.com/topic/86705-not-found-message/#findComment-443084 Share on other sites More sharing options...
simcoweb Posted January 18, 2008 Share Posted January 18, 2008 Something like: $name = $_POST['name']; $sql = "SELECT * FROM tablename WHERE name='$name'"; $results = mysql_query($sql) or die(mysql_error()); if($results){ echo "Exists!"; } else { echo "Does NOT exist!"; } Quote Link to comment https://forums.phpfreaks.com/topic/86705-not-found-message/#findComment-443086 Share on other sites More sharing options...
Daniel0 Posted January 18, 2008 Share Posted January 18, 2008 There are various ways you could do that. You could do a simple SELECT * FROM table WHERE field LIKE '%Simon%'; or you could take use of MySQL's full-text searching. Alternatively, you could use more advanced searching algorithms such as Zend Framework's implementation of Lucene: Zend_Search_Lucene. I suppose that you by searching mean "check if it contains". Quote Link to comment https://forums.phpfreaks.com/topic/86705-not-found-message/#findComment-443087 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.