Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Selecting rows from database with different ids

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

liam_d

The original NP Emo KidEstablished Member
Impact
25
Hi all i am trying to select topics from many forums (in phpbb3) and this is the code:

PHP:
	if (preg_match ("/^([0-9.,-]+)$/", $forum)) 
	{
		$sql = $db->sql_build_query('SELECT',
		array(
		'SELECT'   => 'p.*, u.*',
		'FROM'      => array(
			POSTS_TABLE   => 'p',
			USERS_TABLE   => 'u',
		),
		'WHERE'      => "p.topic_id = '{$topics[$i]['topic_id']}'
			AND p.forum_id = '{$forum}'
			AND p.poster_id = u.user_id",
		'ORDER_BY'   => "post_id ASC"
		));
	}

And you see the "($forum)" well it currently only works if i use one number, but what if i want to select from more than one forum, how do i use more numbers in there?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
are you not able to place that in a for loop, like:

for(i=0;i>=4;i++){

$forum = i;
//code here;

}

like so
 
0
Close
I really don't understand that :(
 
0
Close
PHP:
 if (preg_match ("/^([0-9.,-]+)$/", $forum)) 
    {
        $sql = $db->sql_build_query('SELECT',
        array(
        'SELECT'   => 'p.*, u.*',
        'FROM'      => array(
            POSTS_TABLE   => 'p',
            USERS_TABLE   => 'u',
        ),
        'WHERE'      => "p.topic_id = '{$topics[$i]['topic_id']}'
            AND p.forum_id IN('{$forumids}')
            AND p.poster_id = u.user_id",
        'ORDER_BY'   => "post_id ASC"
        ));
    }
Where $forumids would be a comma separated list of forum id's
 
0
Close
Thanks a lot someone on devshed said the same, but note you can't put '' around the (1,3,5) or it gives an error.

So it would read:

PHP:
if (preg_match ("/^([0-9.,-]+)$/", $forum)) 
    {
        $sql = $db->sql_build_query('SELECT',
        array(
        'SELECT'   => 'p.*, u.*',
        'FROM'      => array(
            POSTS_TABLE   => 'p',
            USERS_TABLE   => 'u',
        ),
        'WHERE'      => "p.topic_id = '{$topics[$i]['topic_id']}'
            AND p.forum_id IN ({$forum})
            AND p.poster_id = u.user_id",
        'ORDER_BY'   => "post_id ASC"
        ));
    }

Thanks buddy :)

Ps. it needed to stay as "$forum" as well, as it is used throughout my script :)
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back