Re: Store more than 1 piece of information in a single variable

From: Date: Fri, 03 Aug 2007 16:05:01 +0000
Subject: Re: Store more than 1 piece of information in a single variable
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-43877@lists.php.net to get a copy of this message
First.. You're using mysql_fetch_array when you wanted mysql_fetch_assoc.. .. select user_id from whatever .. and then $row = mysql_fetch_array($res) .. youd have a $row[0].. mysql_fetch_assoc would allow $row['user_id'] Secondly.. You can use one query to select all the info.. select e107.user_id FROM db2.e107_user as e107 left join db1.clanmembers as clan on e107.user_loginname = clan.user_loginname You'll still want to mysql_select_db($db2) for your insert query Thirdly.. I'd change the insert query to: $user_id = mysql_real_escape_string($user_id); $query = "INSERT INTO e107_private_msg VALUES (NULL, '1', '$user_id', NOW(), '0', 'Clan War 2', 'Clan War Arranged', '0', '0', '', '+rr+', '0')"; mysql_query($query) or die('Query 3 failed. ' . mysql_error()); Where the entire query is surrounded by double quotes, so you dont have to back slash singles.. $user_id is escaped, so its safe.. using mysql's NOW() function instead of php's time().. On 8/3/07, Arena Servers <smithster@arenasmithster.co.uk> wrote: > mysql_select_db($db_name2); > > $query = "SELECT user_id FROM e107_user WHERE > user_loginname = '$user_loginname'"; > > $result = mysql_query($query) or die('Query 2 failed. ' . mysql_error()); > > while ($row = mysql_fetch_array($result)){ > > $user_id = ($row['user_id']); > > $query = 'INSERT INTO e107_private_msg VALUES (NULL, \'1\', > \''.$user_id.'\', \''.$time.'\', \'0\', > \'Clan War 2\', \'Clan War Arranged\', \'0\', \'0\', > \'\', \'+rr+\', \'0\');'; > > $result = mysql_query($query) or die('Query 3 failed. ' . mysql_error()); > > }

« previous php.db (#43877) next »