RE: [PHP] a little logic...

From: Date: Sun, 18 May 2003 18:10:29 +0000
Subject: RE: [PHP] a little logic...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148105@lists.php.net to get a copy of this message
> 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; // ??? > ------------------------------------------------------------------------ -- Learn to use the mysql_fetch_* functions. The fetch a whole row instead of one column from the result set. $q = "SELECT cno,company,site FROM main_co where user='".$user."' And pass='".$pass."'"; $rs = mysql_query($q) or die(...); if($r = mysql_fetch_assoc($rs)) { $_SESSION['cno'] = $r['cno']; $_SESSION['company'] = $r['company']; $_SESSION['site'] = $r['site']; } Or you could use array_merge() instead of those last 3 lines. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#148105) next »