php mysql help, is it already in db?

I need to see if an item is already in the database, I can do this:

$query = "SELECT * FROM oys_reg_users WHERE reg_email = '".$email."'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results == 0) {

but it seems like there would be a more efficient way.... do I use count rows, or something else?  I just need to know if it already exists or not,

Thanks,  Chris
Who is Participating?
ErburethConnect With a Mentor Commented:
If you only want to verify whether the result exists, you could use
SELECT COUNT(*) FROM table WHERE oys_reg_users WHERE reg_email = '".$email."'";

which is a little bit faster, as it returns only the result count, instead of whole set of results.
You should use COUNT(*) to make it little bit faster, however it is also fine
St_Aug_Beach_BumAuthor Commented:
Thank you both!  Appreciate the help :)
Cornelia YoderArtistCommented:
If the reason you need to know whether it exists or not is so you can decide whether to INSERT or UPDATE, consider MySQL's REPLACE.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.