Re: [PHP-DB] Store more than 1 piece of information in a single variable

2007-08-03 Thread Michael Preslar
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 [EMAIL PROTECTED] 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());

 }

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Store more than 1 piece of information in a single variable

2007-08-03 Thread Uber Wannabe

(see below)

-Original Message-
From: Arena Servers [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 03, 2007 10:44 AM
To: php-db@lists.php.net
Subject: [PHP-DB] Store more than 1 piece of information in a single
variable

ok, firstly here's my script...

?php

$db_host = '*';

$db_user = '*';

$db_pass = '*';

$db_name = '*';

$db_name2 = '*';

$time = time();

$conn = mysql_connect($db_host, $db_user, $db_pass);

//N/A - Add $ in front of mysql_select_db and (maybe not necessary) specify
connection
$mysql_select_db($db_name, $conn);

//N/A - No ' needed.
$query = SELECT * FROM clanmembers;

//N/A - Specify connection in query (maybe not necessary)
$result = mysql_query($query, $conn) or die('Query failed. ' .
mysql_error());

//N/A - I think mysql_fetch_assoc brings the result in with keys;
mysql_fetch_array would let you reference by indices.
while ($row = mysql_fetch_assoc($result))
//N/A - Toss names in an array; otherwise, you're overwriting each username
every time you fetch.
$user_loginname[] = $row['user_loginname'];

//N/A - Maybe not necessary to close DB in between queries.
mysql_close_db;

mysql_select_db($db_name2);

//N/A - Again, no ' needed.  Also, your query should recursively check each
username from above.
foreach($user_loginname As $msguser)
{
$query = SELECT user_id FROM e107_user WHERE user_loginname =
'$msguser';
$result = mysql_query($query, $conn) or die('Query 2 failed. ' .
mysql_error());

//N/A - We'll use mysql_fetch_assoc() instead, and an if statement.
if($row = mysql_fetch_assoc($result)
{
$user_id = ($row['user_id']);
//N/A - Put code to message user here
}
}
?


Now, the script's task is to select loginnames from one database1, compare
them to database2, select the user_id associated with the loginnames in
database2 and send a private message to each of those loginnames.

Just now, the script selects only the last loginname from database1 and then
sends a private message to that 1 person.

I need it to select all the loginnames which currently there are 25. So what
do I need to change for this to work?

Thanks in advance.

Paul

Arena Servers - Web Hosting
http://www.arenasmithster.co.uk

-End Original Message-


Comments are in original message.  I hope at least some of them help. 

-- N/A

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Store more than 1 piece of information in a single variable

2007-08-03 Thread Niel
 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']

 mysql_fetch_array($res) will fetch both associative and numerical
indexes, so it will have  $row[0] and $row['user_id'] in it. It has an
optional second parameter to indicate associative, numerical or both,
defaulting to both.  mysql_fetch_row only fetches numerically indexed
arrays

--
Niel Archer

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re: [PHP-DB] Store more than 1 piece of information in a single variable

2007-08-03 Thread juanjo
El mensaje ha llegado correctamente pero... estoy de vacaciones hasta el 
próximo 20 de Agosto. Atenderé tu correo a la vuelta. Si por el motivo que 
fuere necesitas ponerte en contacto con ADIMEDIA puedes hacerlo en [EMAIL 
PROTECTED] o en el Telf. 934 63 57 37.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php