Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 08-04-2009, 05:57 AM   #1 (permalink)
Junior Member
 
Join Date: 04-19-09
Posts: 7
iTrader: 0 / 0%
Latest Blog:
None

levani is liked by many
Use variable as an array argument

The value of the variable $numbers is 1, 2, 3, 4, 5 but this code doesn't work:

PHP Code:
$wp_query->query(array('post__in'=>array($numbers),'showposts'=>5,'paged'=>$paged)); 
When I type those numbers manually it works:

PHP Code:
$wp_query->query(array('post__in'=>array(12345),'showposts'=>5,'paged'=>$paged)); 
What is the problem?
levani is offline  
Add Post to del.icio.us
Reply With Quote
Old 08-04-2009, 06:13 AM   #2 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Try just doing ('post_in'=>$numbers,'showposts'

You're creating array with one element that is also an array.

I'm assuming by $numbers is 1,2,3,4,5 you mean $numbers = array(1,2,3,4,5)
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 08-04-2009, 06:48 AM   #3 (permalink)
Junior Member
 
Join Date: 04-19-09
Posts: 7
iTrader: 0 / 0%
Latest Blog:
None

levani is liked by many
This code doesn't seem to work...

Here is how I get the $numbers string:

PHP Code:
<?php
$post_ids 
$wpdb->get_col("SELECT comment_post_ID FROM $wpdb->comments WHERE user_id = $current_user->ID AND comment_approved = '1' ");
$numbers implode(', '$post_ids);
?>
The first line gets IDs from database and the second line adds , symbol in order to use these numbers as an array argument. Is anything wrong?
levani is offline  
Add Post to del.icio.us
Reply With Quote
Old 08-04-2009, 08:03 AM   #4 (permalink)
v7n Mentor
 
Izzmo's Avatar
 
Join Date: 11-01-03
Location: Kansas City
Posts: 1,338
iTrader: 0 / 0%
Latest Blog:
Starting p90x today

Izzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web pro
Send a message via ICQ to Izzmo Send a message via AIM to Izzmo Send a message via MSN to Izzmo Send a message via Yahoo to Izzmo
Do this..

PHP Code:
$wp_query->query(array('post__in'=>explode(", "$numbers),'showposts'=>5,'paged'=>$paged)); 
The reason is $numbers is a string... so when you put that into the array, it will have 1 value, and that is the value of $string.

The explode function will split the values of numbers up and put them into an array.
__________________
Izzmo
Coding Guru Extraordinaire
ZeroWeb Hosting & Design - Customizable hosting for every type of user!
Izzmo is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
For fun: Delete an array from array Costin Trifan Coding Forum 3 05-30-2009 11:33 AM
Could not convert Javascript argument error? langar Coding Forum 12 08-08-2008 07:55 AM
SEO Is Not An Argument peter_d SEO Forum 4 08-21-2007 09:23 AM
array weirdness in php I like pie Coding Forum 7 01-27-2007 12:36 AM
Adding 1 to array? spl1nter Coding Forum 4 09-14-2004 08:22 PM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 06:20 PM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.