Timma Posted March 26, 2007 Share Posted March 26, 2007 How would I write a function that returns true if it finds a matching entry in the table. For example: In table tab, column col, there are multiple different entries but a matching entry may be about to be inserted, how can I check if it's already there? I also need it to return true or false for the purpose of an if statement. If it is already in the database it should return true. function check(){ } My code so far, yes pathetic. Link to comment https://forums.phpfreaks.com/topic/44310-checking-mysql/ Share on other sites More sharing options...
Timma Posted March 26, 2007 Author Share Posted March 26, 2007 Bump. Link to comment https://forums.phpfreaks.com/topic/44310-checking-mysql/#findComment-215215 Share on other sites More sharing options...
dustinnoe Posted March 26, 2007 Share Posted March 26, 2007 <?php function check($field, $table, $string) { $check = mysql_query("SELECT {$field} FROM {$table} WHERE {$field}='{$string}' LIMIT 1"); $result = mysql_num_rows($check); return $result; } $field = "Field to check in"; $table = "Table to check in"; $string = "String to check for in db"; $check_row = check($field, $table, $string); if ($check_row) { // Insert new row } ?> Link to comment https://forums.phpfreaks.com/topic/44310-checking-mysql/#findComment-215226 Share on other sites More sharing options...
Timma Posted March 26, 2007 Author Share Posted March 26, 2007 Thanks alot. Link to comment https://forums.phpfreaks.com/topic/44310-checking-mysql/#findComment-215231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.