[thelist] Rusty PHP questions...

Darrell King darrellgking at gmail.com
Mon Oct 15 11:49:30 CDT 2007

1) If you are going to use all the fields from a given table, then
SELECT * makes sense. Don't use it if you only need some of the
columns just because it looks cleaner in the PHP.

2) Why reassign $_GET['id'] to $raceid? It's an unnecessary step
unless you are going to do something with the latter that you don't
want affecting the former. This might be the case if you are going to
escape the input bur re-display the original variable in the output
HTML,. for instance.  Think twice about the reassignment if it's just
to be pretty, though, especially if efficiency concerns you.

3) I recommend putting the MySQL connection into an external file and
including it in the HTML document where needed via a PHP include.

4) If you need only the one database, why not select it only once?

On 10/15/07, Tom Dell'Aringa <pixelmech at gmail.com> wrote:
> Hey there,
> Got a quick little helper job using some PHP/mySQL and it's just been ages
> since I've done anything. I've got the thing working as she wanted, but I
> had a couple quick questions.
> 1. One best practice is to never use SELECT * - could someone explain why,
> and tell me when this is okay if ever? Right now I am doing this:
> $query = sprintf("SELECT name, date, city, distance, start, state, score,
> course_type, price, size, chip, food, beer, url, frequency, sponsors,
> description FROM event_list WHERE id = $raceId");
> Which seems a bit excessive... but if it makes it work better I'm for it.
> These are indeed all the columns in this table.
> 2. They are connecting to the db directly in the page code, which I know is
> a no-no - is the best way to do this simply to have an include like '
> connect.php'? Also, they are selecting the database at the top of the page
> as well - shouldn't I do this before each query, or does it matter? (top of
> page is like so)
> mysql_connect("domain.com", "user", "pw") or die(mysql_error());
> mysql_select_db("db_name") or die(mysql_error());
> 3. Lastly, just checking that I am setting my variable correctly. They are
> appending an id onto the get string for each link, so I set it at the top of
> the page like so, so I can test for it at the section when I need it:
> $raceId = $_GET['id'];
> Thanks in advance for any tips, please CC me at pixelmech at gee mail dot
> com.
> Tom
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !

Darrell G. King
DarrellGKing at gmail.com
(C) 1/585.820.8231

More information about the thelist mailing list