[thelist] Rusty PHP questions...

Tom Dell'Aringa pixelmech at gmail.com
Mon Oct 15 10:05:34 CDT 2007


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



More information about the thelist mailing list