WhiteCube Posted December 10, 2007 Share Posted December 10, 2007 hi! I have this code $result = mysql_query("SELECT * FROM rpg_user WHERE username = '$username'") or die(mysql_error()); which finds the row in my table which matches my $username variable.. However.. sometimes.. it's not there.. What code can i use to tell me so? something like if($username does not exist in row){ echo "does not exist" }else{ echo "does exist" } can someone write up a simple script for me? Thanks! Link to comment https://forums.phpfreaks.com/topic/80986-solved-php-fetches-mysql-table/ Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 you can use mysql_num_rows function for that below is an example $result = mysql_query("SELECT * FROM rpg_user WHERE username = '$username'") or die(mysql_error()); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { echo "exists"; } else { echo "does not exists"'; } hope its helpful Link to comment https://forums.phpfreaks.com/topic/80986-solved-php-fetches-mysql-table/#findComment-410861 Share on other sites More sharing options...
WhiteCube Posted December 11, 2007 Author Share Posted December 11, 2007 Great stuff!! lol Your helping me out a lot!! lol Link to comment https://forums.phpfreaks.com/topic/80986-solved-php-fetches-mysql-table/#findComment-411714 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.