PDA

View Full Version : [SOLVED] how i check if userid into touserarray or not


omardealo
10-22-2014, 02:30 PM
Hello ,

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

kh99
10-22-2014, 04:09 PM
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:

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

omardealo
10-23-2014, 05:06 AM
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:

$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
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

kh99
10-23-2014, 07:42 AM
Hmm, I'm not sure I completely understand. But anyway, you could do something like this:

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

omardealo
10-23-2014, 09:59 AM
Hmm, I'm not sure I completely understand. But anyway, you could do something like this:

$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

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


if (($touser=@unserialize($check['touserarray'])) !== FALSE)
{
// check $touser[]
}

kh99
10-23-2014, 11:19 AM
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.

omardealo
10-23-2014, 11:39 AM
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

omardealo
11-04-2014, 12:45 PM
Solution :


// 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']).";
}

}
}
}