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"? 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"; } 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!"; } 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". Link to comment https://forums.phpfreaks.com/topic/86705-not-found-message/#findComment-443087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.