Is there any way I could shorten this code? If I want one variable from a table in my database, I do this:
$blah=mysql_query("Select * from users where username='".$_SESSION['username']."'"); $row=mysql_fetch_array($blah); $city=$row["city"];
$blah=mysql_query("Select city from users where username='{$_SESSION['username']}'"); $row=mysql_fetch_array($blah); $city=$row["city"];
Would changing the * to 'city' make much of a difference in processing time?
nothing noticable, but why select more than you need?
influx wrote:Is there any way I could shorten this code? If I want one variable from a table in my database, I do this: $blah=mysql_query("Select * from users where username='".$_SESSION['username']."'"); $row=mysql_fetch_array($blah); $city=$row["city"];
Yes,
$blah=mysql_query("Select column_name from users where username='$_SESSION[username]'");
...just replace column_name with the actual name or a variable containing the name.
Create an index on the database table for the column "username", that would probably have the most noticable effect with regard to speed.
And [man]mysql_result[/man] can also reduce the amount of PHP and number of intermediate variables.