Page 1 of 1
help with selecting / separating values
Posted: Sun Jul 06, 2003 9:27 am
by zerodegreeburn
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
Posted: Sun Jul 06, 2003 4:07 pm
by m@ndio
php returns db results in array format so it is probably working.
Just loop through the results and print em like this:
Code: Select all
foreach($pub as $beer){
echo "Value: ".$beer;
}
Posted: Mon Jul 07, 2003 3:17 am
by twigletmac
Could we see the code you're using to put them into a string.
Mac
Posted: Mon Jul 07, 2003 4:31 am
by zerodegreeburn
i used this code to get it partly working:
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;
?>
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

?>
Posted: Mon Jul 07, 2003 5:05 am
by twigletmac
Try this:
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);
?>
Mac
Posted: Mon Jul 07, 2003 5:13 am
by zerodegreeburn
thanks, but i got it to work like this and i dont want to chagne anything now
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);
?>
then i can just use it like this:
WHERE forumid IN ($forum_ids)
thanks for the help