List:General Discussion« Previous MessageNext Message »
From:Brent Baisley Date:September 4 2009 1:20pm
Subject:Re: a better way, code technique?
View as plain text  
You should store the current user id in a session variable. Then you
don't have to hit the database at all.

There really is no short way of doing it. Normally you would create a
function (i.e. runQuery) that you pass the query too. Then it handles
running the query, fetching the data, error checking, etc. That way
you don't have to rewrite the same lines every time you want to run a
query.

Brent Baisley

On Fri, Sep 4, 2009 at 6:51 AM, AndrewJames<andrewhudds@stripped> wrote:
> is there a better way (hopefully simpler) to code this?
>
> i want to get the user id of the logged in user to use in my next statement.
>
> $q1 = sprintf("SELECT uid FROM users WHERE users.username='$username'");
> $result1 = mysql_query($q1);
> $uid = mysql_fetch_array($result1);
> $u = $uid['uid'];
>
> it seems like a long way around to get 1 bit of data??
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>
>
Thread
a better way, code technique?AndrewJames4 Sep
  • AW: a better way, code technique?Majk.Skoric4 Sep
    • AW: a better way, code technique?Majk.Skoric4 Sep
  • Re: a better way, code technique?Per Jessen4 Sep
    • AW: Re: a better way, code technique?Majk.Skoric4 Sep
      • Re: AW: Re: a better way, code technique?AndrewJames4 Sep
        • AW: AW: Re: a better way, code technique?Majk.Skoric4 Sep
  • Re: a better way, code technique?Brent Baisley4 Sep
    • RE: a better way, code technique?Gavin Towey4 Sep
    • RE: a better way, code technique?Daevid Vincent4 Sep