Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 10-22-2014, 02:30 PM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [SOLVED] how i check if userid into touserarray or not

Hello ,

Code:
$check = $db->query_first("SELECT * FROM " . TABLE_PREFIX . " pmtext 
WHERE touserarray NOT IN ( 2,4,5 ) ");
sure it's not working becouse touserarray filed is array not a number.
so how i ckeck about if this userid into this array or not ?
i see already files of vb , and i found this fun unserialize()
but i don't understand it ...
Reply With Quote
  #2  
Old 10-22-2014, 04:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, it's a serialized array. It may be possible to come up with a regular expression that would let you check using sql, but the easier way to do it would be to read all the records, use unserialize to make an array, then search the array. Unfortunately, you need to read all the rows from that table to do it that way.

Depending on what you're doing, you may want to use the pm table. Then you could do something like:

Code:
$check = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "pmtext as pmtext
LEFT JOIN ".TABLE_PREFIX."pm AS pm ON(pm.pmtextid=pmtext.pmtextid)
WHERE pm.userid NOT IN ( 2,4,5 ) ");
Edit: actually I'm not sure about that query since I haven't tested it.

Edit again...also, I guess that will only work for finding users who haven't deleted the pm already.
Reply With Quote
  #3  
Old 10-23-2014, 05:06 AM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Yes, it's a serialized array. It may be possible to come up with a regular expression that would let you check using sql, but the easier way to do it would be to read all the records, use unserialize to make an array, then search the array. Unfortunately, you need to read all the rows from that table to do it that way.

Depending on what you're doing, you may want to use the pm table. Then you could do something like:

Code:
$check = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "pmtext as pmtext
LEFT JOIN ".TABLE_PREFIX."pm AS pm ON(pm.pmtextid=pmtext.pmtextid)
WHERE pm.userid NOT IN ( 2,4,5 ) ");
Edit: actually I'm not sure about that query since I haven't tested it.

Edit again...also, I guess that will only work for finding users who haven't deleted the pm already.
thnx brother ,
look that's Query don't make What I want to do .
Let me explain it more ...
i want make a code to sure that some moderators don't see any meassge to some users [Sending PM and PM receiving] , so i must check if These users-ids into touserarray or not .
your Query is really a good idea , i did not think of it, despite its simplicity
but result of this Query cannot exception for [receiving messages] to these users-ids . only exception for [sent messages] .
i use regular expression before , but iam not good to used it Especially if [touserarray] contain more than User like that
PHP Code:
a:1:{s:2:"cc";a:2:{i:1;s:5:"admin";i:8;s:4:"soso";}} 
So I prefer to use MySql Query ... that's okay to read all rows but as i said i don't understand use unserialize () and how i use it with result Query
Reply With Quote
  #4  
Old 10-23-2014, 07:42 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm, I'm not sure I completely understand. But anyway, you could do something like this:

Code:
$msgs = $db->query_read_slave("SELECT * FROM " . TABLE_PREFIX . " pmtext");
while ($check = $db->fetch_array($msgs))
{
   if (($touser=@unserialize($check['touserarray'])) !== FALSE)
   {
      // check $touser[]
   }
}
to be honest I don't know how to do the "check $touser[]" part. From your example it looks like $touser['cc'] would be an array of cc'd users, like (1=>admin, 8=>soso}. But does that mean the touserarray only contains the users who were cc'd? I don't know.
Reply With Quote
Благодарность от:
omardealo
  #5  
Old 10-23-2014, 09:59 AM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Hmm, I'm not sure I completely understand. But anyway, you could do something like this:

Code:
$msgs = $db->query_read_slave("SELECT * FROM " . TABLE_PREFIX . " pmtext");
while ($check = $db->fetch_array($msgs))
{
   if (($touser=@unserialize($check['touserarray'])) !== FALSE)
   {
      // check $touser[]
   }
}
to be honest I don't know how to do the "check $touser[]" part. From your example it looks like $touser['cc'] would be an array of cc'd users, like (1=>admin, 8=>soso}. But does that mean the touserarray only contains the users who were cc'd? I don't know.
hey ,
i get something , it's working good to get all user-id or usernames from touserarray
and than you can make check

Code:
global $db ,$vbulletin;
$touser = array();
$sql = $db->query_read("SELECT touserarray FROM " . TABLE_PREFIX . "pmtext where pmtextid = 149");
        while ($sql1 = $db->fetch_array($sql)) 
        { 
$touser = unserialize($sql1['touserarray']);
foreach($touser AS $key => $item)
{
    if (is_array($item))
    {
        foreach($item AS $subkey => $subitem)
        {
            $username = $subitem;
            $userid = $subkey;
            # store the data as $user_arr[$id] = $name
            $user_arr[$subkey] = $subitem;
        }
    }
    else
    { 
        $username = $item;
        $userid = $key[$i];
        $user_arr[$key[$i]] = $item;
    }
    # store the data as $user_arr[$id] = $name
    $user_arr[$userid] = $username;
    # or if you just want to print off the data during the loop...
    echo "ID: $userid; name: $username" . PHP_EOL;
}

    // LOOP
	foreach ($user_arr as $k => $v)
	{
	// var to all user-id you can use&print it in templates $all_userid
	$all_userid .= $k . PHP_EOL;
	// OR you can print all user-id on this loop
	echo $k ;
	// OR you can user&print all user-id by array
	$all_userid[] = $k . PHP_EOL;
	}
	// print the array 
	print_r ($all_userid);
}

your code is very simple ,I would like to used a small code
but i don't understand this part


Code:
   if (($touser=@unserialize($check['touserarray'])) !== FALSE)
   {
      // check $touser[]
   }
Reply With Quote
  #6  
Old 10-23-2014, 11:19 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I didn't look at all of your code, but I think my code is very simple because I left out all the things your code does! There probably isn't any way to make it smaller.
Reply With Quote
  #7  
Old 10-23-2014, 11:39 AM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I didn't look at all of your code, but I think my code is very simple because I left out all the things your code does! There probably isn't any way to make it smaller.
okay but i still understand your code or how i used it
Reply With Quote
  #8  
Old 11-04-2014, 12:45 PM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Solution :


PHP Code:
// query to get all pm for all users
$searchuser $db->query_read("SELECT * FROM " TABLE_PREFIX " pmtext ORDER BY dateline DESC");

while (
$result $db->fetch_array($searchuser))
{

$touser unserialize($result['touserarray']);

// loop pm array
foreach($touser AS $key => $item)
{
        foreach(
$item AS $subkey => $subitem)
        {
           
// username and userid inside array 
            
$username $subitem;
            
$userid $subkey;
            
    
// here you can put your Condition (in my case i want show all pm for all users Except specific member)
    // if user (mark) Send a multi-message to all of the John and Catherine and Michael
    // and you want Review all pm Except pm ( to or from "John" )
    // this Condition will be Review all PM (from or to) all users Except "John"
    // Review pm from mark to Catherine AND pm from mark to Michael but not Review pm from mark to John Although it's the same message
    
    
if ( ($username != "John") || ($result['fromusername'] != "John") )
        {
       echo 
"from:" .$result[fromusername];
       echo 
"to:" .$username;
       echo 
"title:" .$result[title];
       echo 
"text:" .$result[message];
       echo 
"date:" .vbdate($vbulletin->options['dateformat'], $result['dateline'], true).".".vbdate($vbulletin->options['timeformat'], $result['dateline']).";
         }
         
        } 
}

Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:11 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04672 seconds
  • Memory Usage 2,261KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_code
  • (2)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (1)post_thanks_box_bit
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete