Last Updated on Saturday, 12 January 2013 12:01 Written by Richi González Saturday, 12 January 2013 12:00
Have you been in a situation where you need to check if either a phone number or a user, for example, exists in your database? When I didn’t know how to do that, I looked through several articles looking for the best and most efficient way of doing it until I found this one.
1. Let’s say we have a table called ‘users’ and it has two columns: id, name. This is our table:Learn More
Last Updated on Friday, 4 January 2013 12:00 Written by Richi González Friday, 4 January 2013 12:00
For the last website I made, I created a really flexible and friendly administration panel where there were a lot of statistics to analyze how the website was performing. I came across different ways of counting records in a table, yet stuck with this one, the most efficient:
The query is really simple, we will use SELECT COUNT(1), then mysql_fetch_row() that count. The code would look like this:Learn More