01-20-2017, 03:25 PM
My internet was down (I live in Rural Alaska, so that can be a pain).
Just to add a few things into the mix. A lot of times I end my variables with Q, R, or C for Query, Results, and Count. Sometimes I don't do the R one and give it a better name.
It's kind of nice to have
$findUsersQ - the query
$findUsersC - the number of users found
and
$foundUsers or $findUsersR - The results.
It's your code...obviously just have fun with it, but the consistent urls make life easier.
Another thing that makes life easier is if you have a column named "total", make your variable total, your form input name total, your form input id total. EVERYTHING. give it one name. I've learned my lesson on that. Then total=total=total=total and you don't have to keep going to the db to figure out what's wrong.
A few more db things.
You can string those things together if you want.
So you can do
BUT the one thing I always want to think about is what happens if the db returns either zero results (because something is broken) or more results than I would expect.
That's where you want to wrap things in the
It doesn't seem that important until you have a bug or you are designing something like a support ticket system and you delete your old tickets. You always want something other than an error to happen if you get no results found.
Just to add a few things into the mix. A lot of times I end my variables with Q, R, or C for Query, Results, and Count. Sometimes I don't do the R one and give it a better name.
It's kind of nice to have
$findUsersQ - the query
$findUsersC - the number of users found
and
$foundUsers or $findUsersR - The results.
It's your code...obviously just have fun with it, but the consistent urls make life easier.
Another thing that makes life easier is if you have a column named "total", make your variable total, your form input name total, your form input id total. EVERYTHING. give it one name. I've learned my lesson on that. Then total=total=total=total and you don't have to keep going to the db to figure out what's wrong.
A few more db things.
You can string those things together if you want.
So you can do
Code:
$findUser = $db->query("SELECT * FROM users WHERE fname = ?",array('bob'))->results();
BUT the one thing I always want to think about is what happens if the db returns either zero results (because something is broken) or more results than I would expect.
That's where you want to wrap things in the
Code:
if($findUserC > 0){
Code:
//do stuff here
Code:
}else{
Code:
//Display some message.
It doesn't seem that important until you have a bug or you are designing something like a support ticket system and you delete your old tickets. You always want something other than an error to happen if you get no results found.