View Full Version : in_array(): Wrong datatype for second argument
SmEdD
11-14-2003, 02:56 AM
Warning: in_array(): Wrong datatype for second argument on line 123
if ($bbuserinfo['userid']) {
$datecut = $bbuserinfo['lastvisit'];
} else {
$datecut = TIMENOW - (24 * 60 * 60 * 1);
}
$countnew = $DB_site->query("
## GET NEW POSTS / THREADS ##
SELECT post.postid, post.threadid
FROM " . TABLE_PREFIX . "post AS post
WHERE dateline >= $datecut
AND visible = '1'");
while($getnew = $DB_site->fetch_array($countnew)) {
$new['posts']++;
if (!in_array($getnew['threadid'], $threadids)) {
$new['threads']++;
$threadids[] = $getnew['threadid'];
}
}
Line 123 is
if (!in_array($getnew['threadid'], $threadids)) {
Lesane
11-14-2003, 06:01 AM
Try to change:
$datecut = TIMENOW - (24 * 60 * 60 * 1);
into:
$datecut = TIMENOW() - (24 * 60 * 60 * 1);
SmEdD
11-14-2003, 10:54 AM
Didn't work :(
Xenon
11-14-2003, 02:14 PM
before that line:
while($getnew = $DB_site->fetch_array($countnew)) {
put that code:
$threadids = array();
Dean C
11-14-2003, 03:51 PM
if (!in_array($getnew['threadid'], explode(',', $threadids))) {
SmEdD
11-14-2003, 08:11 PM
Hmmm . . . still don't work, I donno how it didn't since you are all amazing coders . . . Is there any other way of redoing the in_array. I also tryed a combination of all of thoes lines but nothing seems to want to work.
Dean C
11-14-2003, 08:45 PM
I'm assuming the contents of $threadids is a list of thread id's. If so the code above should work ^^ I use it all the time with global admin cp options :)
Xenon
11-14-2003, 09:34 PM
@Dean: you should look at the code before trying to help:
$threadids[] = $getnew['threadid'];
you can clearly see it's not a list but an array ;)
but it hasn't been intialised in the first loop.
that's why i thought the initialisation of it in front of the loop should do it...
KuraFire
11-15-2003, 11:11 AM
Putting
$threadids = array();
all the way at the top of the code segment you pasted in the first post should do it.
HOWEVER!
This code gives you the exact same results and is cleaner and simpler:
$datecut = ($bbuserinfo['userid'] != 0) ? $bbuserinfo['lastvisit'] : TIMENOW - (24 * 60 * 60 * 1);
$new = $DB_site->query_first("SELECT COUNT(post.postid) as posts, COUNT(DISTINCT(post.threadid)) as threads
FROM " . TABLE_PREFIX . "post AS post
WHERE dateline >= $datecut
AND visible = '1'");
Depending on the amount of data, it can be a lot faster (with lots of threads and posts) to a little bit slower (with few threads and posts on a big board nonetheless).
You may want to do some benchmarking on your own board to see which method is faster on your forums. Keep in mind that the results (speed-wise) will depend solely on how many new threads / posts there actually are in the result.
Good luck :)
SmEdD
11-15-2003, 04:47 PM
lol I am so stupid . . . The reason the other wern't working was cause I was uploading to the wrong site, but I wasn't paying attection when I clicked connect so that is why.
But ya it works now, so thanks.
NTLDR
11-15-2003, 08:33 PM
Putting
$threadids = array();
all the way at the top of the code segment you pasted in the first post should do it.
Well seeing as thats my code, with a few variable names altered posted by SmEdD, that is how I did it. That line can be found at the top of the file he obtained the code from along with all the other variables initialized.
KuraFire
11-15-2003, 11:56 PM
Well seeing as thats my code, with a few variable names altered posted by SmEdD, that is how I did it. That line can be found at the top of the file he obtained the code from along with all the other variables initialized.
so like, he stole your code and you're complaining about him not properly stealing it? o_O
I fail to see how this, whatever "this" is, is relevant to me... or were you not addressing me but just quoting me for whatever reason? :confused:
SmEdD
11-16-2003, 04:35 AM
Ya it's NTLDR 's and I didn't claim it was mine so . . . It's just nice useing one query instead of 2.
And ya I edited it cause it was going on my forums home page instead of the wicked portal you made.
NTLDR
11-16-2003, 04:57 PM
I fail to see how this, whatever "this" is, is relevant to me... or were you not addressing me but just quoting me for whatever reason? :confused:
I was just quoting the part of your post which had the part of the code that is needed for it to work properly. My reply wasn't specificly aimed at you :)
KuraFire
11-16-2003, 06:02 PM
I was just quoting the part of your post which had the part of the code that is needed for it to work properly. My reply wasn't specificly aimed at you :)
Aaah, okay, gotcha! :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.