Alternative to "SELECT *"
Am having lots of questions pop up, so am posting them as I think them..hope you don't mind
Having read that ideally, you should not use SELECT * and specify which columns you want instead, e.g.
I have successfully changed all my coding accordingly with one exception:
SELECT column1, column2 FROM...
while ($gptp <=5)
$gptget = mysql_query("SELECT * FROM $gptplan
WHERE userid = '$gptuser' AND email = '$gptemail' LIMIT 1");
while($row = mysql_fetch_array($gptget))
while ($gptlvl <=9)
Any ideas how I could work this one? Or am I allowed to occasionally have an exception to the rule?
Looks to me like you use 4 columns -- just look at which array indexes are used with $row -- so you could make them the columns used in your SELECT. (Note that if those are the only 4 columns in that table, then it's not bad performance-wise to just use "*", though that makes your source code a bit less readable.)
Are these ;
supposed to be
I didn't notice that before, but probably explains the OP's question: it looks like the table must have a bunch of columns with names like lvl1new, lvl1tot, lvl2new, lvl2tot, etc.... Now I'm sort of leaning toward a DB redesign to move those enumerated columns into one or more separate tables with a foreign key into the main table.
Originally Posted by Dasher
Thankyou for your help.
NogDog - you are correct. There are approx 18 columns being called in each table (5 of them) out of 20 columns. The other 2 being my verification (userid and email)
It would be possible to list them all in the SELECT, but would make reading very difficult. If I am calling all but two of the columns, would that be acceptable use of the *?
I have heard of foreign keys before, but as yet have had no introduction, so do not understand them yet.
As an additional question, I am also going to have to set all the lvl1new, lvl2new etc... to 0 upon each login. Is there any way of doing this as within the original query, or do I have to run it as a separate UPDATE query? (which is what i am expecting)
Last edited by max2474; 05-20-2012 at 08:03 AM.
having lots of questions pop up, so am posting them as I think them..hope you don't mind
Having read that ideally, you should not use SELECT * and specify which columns you want instead
best dividend stocks
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)