OK, in phpmyadmin this works ok
SELECT `forumid`
FROM `forum`
WHERE 1 AND `countid` = 5 LIMIT 0 , 30
this brings up 3 forums, but everytime i've tried to put them in a string, it seems to bunch them all together, so say they were '1' '5' and '11' the string would be "1511".
any way separating the values into x number of strings (in PHP)?
sorry for the db newbie
help with selecting / separating values
Moderator: General Moderators
-
zerodegreeburn
- Forum Newbie
- Posts: 24
- Joined: Thu Jul 04, 2002 6:42 am
- Contact:
php returns db results in array format so it is probably working.
Just loop through the results and print em like this:
Just loop through the results and print em like this:
Code: Select all
foreach($pub as $beer){
echo "Value: ".$beer;
}- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
zerodegreeburn
- Forum Newbie
- Posts: 24
- Joined: Thu Jul 04, 2002 6:42 am
- Contact:
i used this code to get it partly working:
this makes it come out as $id1,$id2,$id3,
what i'm trying to do is use this code in another sql query:
WHERE forumid IN ($id1,$id2,$id3)
so if i could just get rid of the last , then it would work
?>
Code: Select all
<?php
$forumid = $DB_site->query('SELECT forumid FROM forum WHERE countid=5 ORDER BY forumid');
while ($forumids = mysql_fetch_array($forumid)):
$forum_ids .= "$forumids[forumid],";
endwhile;
?>what i'm trying to do is use this code in another sql query:
WHERE forumid IN ($id1,$id2,$id3)
so if i could just get rid of the last , then it would work
?>
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try this:
Mac
Code: Select all
<?php
$result = $DB_site->query('SELECT forumid FROM forum WHERE countid=5 ORDER BY forumid');
while ($row = mysql_fetch_array($result)) {
$forum_ids[] = $row['forumid'];
}
$forum_ids = implode(',', $forum_ids);
?>-
zerodegreeburn
- Forum Newbie
- Posts: 24
- Joined: Thu Jul 04, 2002 6:42 am
- Contact:
thanks, but i got it to work like this and i dont want to chagne anything now 
then i can just use it like this:
WHERE forumid IN ($forum_ids)
thanks for the help
Code: Select all
<?php
$idforum = $DB_site->query('SELECT forumid FROM forum WHERE countid=5 ORDER BY forumid');
while ($forumids = mysql_fetch_array($idforum)):
$forum_ids .= "$forumids[forumid],";
endwhile;
// get rid of last comma
$forum_ids = substr("$forum_ids", 0, -1);
?>WHERE forumid IN ($forum_ids)
thanks for the help