implode() & explode() in arrays - Newbie
| From: | mailing | Date: | Sat, 10 May 2003 15:01:53 +0000 |
| Subject: | implode() & explode() in arrays - Newbie | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-147105@lists.php.net to get a copy of this message | ||
Hi
I am *trying* to do the following:
I have a db that contains categories. I want to select all categories that that have had new
activity today, and than send email to the subscribers of those categories.
When I look at the array results they are all in one unseparated line. eg:
SportFoodDrinkHotels....etc and my call on the database would only give me the results of people
with all those categories selected, Eg If I had 2 categories with new activity today, sport and
Bio-Tech, it will only give me the email addresses of people with both those categories, whereas I
need to choose all email address with Sport OR Bio-Tech OR Sport , [and] Bio-Tech.
I thought that I would need to implode () adding a delimiter and then explode() into an array.
Here is my code:
$sql_cat ="select catname from category where latest_date = '$today' ";
$result = @mysql_query($sql_cat) or die(mysql_error());
while ($row =mysql_fetch_array($result))
{
$catname = $row["catname"];
$catid = $row["catid"];
$chosen_cat= implode(",", $catname);
}
$cat_chosen= explode( ",", $chosen_cat);
while (list ($va, $cat) = each ($catz))
{
echo "<BR>$va $cat";
}
echo $cat_chosen;
....and then send email to all with "$cat_chosen" in their chosen categories.
It clearly does not work... and I am starting to get in a real mess.
I can not work out if it is my method, code or order that I am doing it in that is wrong. If any one
can help me onto the right tracks (in newbie terms please) I would really appreciate your knowledge.
At the moment I am getting errors with implode statement, and only email addresses of people that
have chosen both categories.
Many thanks for any light.
Cheers
James