Advanced Search

Results 1 to 4 of 4

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

  1. #1
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Store more than 1 piece of information in a single variable

    ok, firstly here's my script...

    PHP Code:
    <?php 

    $db_host 
    '*****'
    $db_user '*****'
    $db_pass '*****'
    $db_name '*****'
    $db_name2 '*****'
    $time time(); 

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

    mysql_select_db($db_name); 

    $query "SELECT * FROM `clanmembers`"
    $result mysql_query($query) or die('Query failed. ' mysql_error()); 
    while (
    $row mysql_fetch_array($result)){ 
    $user_loginname $row['user_loginname']; 

    mysql_close_db
    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()); 

    ?>
    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.

    Smithster.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Place these lines:

    Code:
    $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());
    inside your last while statement like so:

    Code:
    <?php 
    
    $db_host = '*****'; 
    $db_user = '*****'; 
    $db_pass = '*****'; 
    $db_name = '*****'; 
    $db_name2 = '*****'; 
    $time = time(); 
    
    $conn = mysql_connect($db_host, $db_user, $db_pass); 
    
    mysql_select_db($db_name); 
    
    $query = "SELECT * FROM `clanmembers`"; 
    $result = mysql_query($query) or die('Query failed. ' . mysql_error()); 
    while ($row = mysql_fetch_array($result)){ 
    $user_loginname = $row['user_loginname']; 
    } 
    mysql_close_db; 
    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()); 
    
    } 
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks but already tried that one!!

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/psmith83/public_html/clan/public/pm.php on line 24
    I can only think that something more needs to be done in the first query statements. Where it selects the user_loginnames from the database. With it written as it is, doesn't an array need to be created around the part where it says $user_loginname = $row['user_loginname'];?

  4. #4
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I have corrected the problem. I was using the wrong mysql_fetch statement.

    I've also made changes to my script to make it better too.

    Here's the finished working script...

    PHP Code:
    <?php

    $db_host 
    '*****';
    $db_user '*****';
    $db_pass '*****';
    $db '*****';
    $db2 '*****';
    $time time();

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

    $query 'select user_id FROM psmith83_clancentral.e107_user as e107_user inner join psmith83_clan.clanmembers as clanmembers on e107_user.user_loginname = clanmembers.user_loginname';
    $result mysql_query($query) or die('Query failed. ' mysql_error());
    while (
    $row mysql_fetch_assoc($result)){
    $user_id $row['user_id'];
    $user_id mysql_real_escape_string($user_id);
    mysql_select_db($db);
    $query "INSERT INTO e107_private_msg VALUES (NULL, '1', '$user_id',
    '
    $time', '0', 'Clan War 2', 'Clan War Arranged', '0', '0', '', '+rr+',
    '0')"
    ;
    mysql_query($query) or die('Query 3 failed. ' mysql_error());
    }
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •