Re: a little logic...

From: Date: Mon, 19 May 2003 00:52:18 +0000
Subject: Re: a little logic...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148131@lists.php.net to get a copy of this message
On Sun, 18 May 2003 19:43:19 +0200 "Ryan A" <ryan@jumac.com> wrote: > Hi, > Having a little logic problem here...This is my (original)code: > ---------------------------------------------------------------------------- > --- > $q = "SELECT cno FROM main_co where user='".$user."' and > pass='".$pass."'"; > $r = mysql_result(mysql_query($q),0) or die("Error: " . mysql_error()); > > $_SESSION['cno'] = $r; > ---------------------------------------------------------------------------- > --- > > what logic should I use to get/add $company and $site? > (This is what i want to make of it) > eg: > ---------------------------------------------------------------------------- > --- > $q = "SELECT cno,company,site FROM main_co where user='".$user."' and > pass='".$pass."'"; > $r = mysql_result(mysql_query($q),0) or die("Error: " . mysql_error()); > > $_SESSION['cno'] =$r //??? > $_SESSION['company'] = $r // ??? > $_SESSION['site'] = $r; // ??? > ---------------------------------------------------------------------------- > --- > > After reading up in the manual I think $r becomes an array/ or I should make > it an array or somehow use an array...right? I HATE arrays so dont really > know how to use them or even if I need one here...the only arrays I use are > the ones that return a resultset after querying the database. Short answer: Read deeper the manual - you still leak some understanding about the way arrays work. Long answer: If you were to hold all the data in sessions, you should have assign the whole resultset to your session and act through it. $_SESSION['db_result'] = $r; Alternatively, if only a few values were needed, refer directly to its elements. $_SESSION['db_result']['site'] = $r['site']; moreover, as jason mentioned, you have some probs with the way you use you DB connection. Try stealing some code from elsewhere. -- Maxim Maletsky maxim@php.net

« previous php.general (#148131) next »