smith.james0 Posted June 9, 2006 Share Posted June 9, 2006 I am making a script to send out a email when there are events happening on the current day. At the moment it sends out one email for every event, this becomes a problem when there are three or four events on one day [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] I get the events from the db using this at the moment[code]while ( $row = mysql_fetch_array($result ) ) {$event_type = $row[event_type];}[/code]The problem with this it over writes the varables each time. I could use[code]while ( $row = mysql_fetch_array($result ) ) {$i = $i+1;$event_type$i = $row[event_type];}[/code]But then I would end up with lots $event_type$i But i would'nt know how many [img src=\"style_emoticons/[#EMO_DIR#]/excl.gif\" style=\"vertical-align:middle\" emoid=\":excl:\" border=\"0\" alt=\"excl.gif\" /] Is there some way of putting them into an array, then I could count how many were in the array, and use something like this.[code] $cnt = count(array_name); for($i=1; $i<$cnt; $i++){CODE [/code]I would like the end product to be something like$message = "The following events are happening to day</ br>$event_type1</ br>$event_type2 </ br>etc etcThanks in advance James Link to comment https://forums.phpfreaks.com/topic/11608-a-little-help-needed-with-a-array-problem/ Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 [code]$events = array();while ( $row = mysql_fetch_array($result ) ) {$events[] = $row[event_type];}[/code] Link to comment https://forums.phpfreaks.com/topic/11608-a-little-help-needed-with-a-array-problem/#findComment-43809 Share on other sites More sharing options...
.josh Posted June 9, 2006 Share Posted June 9, 2006 [code]while ( $row = mysql_fetch_array($result ) ) {$event_type[] = $row[event_type];}[/code]then when you are building your email, you would add a while loop to your $message[code]$message = "The following events are happening today:";$x = 0;while ($event_type[$x]) { $message .= $event_type . "<br>"; $x++;}[/code] Link to comment https://forums.phpfreaks.com/topic/11608-a-little-help-needed-with-a-array-problem/#findComment-43810 Share on other sites More sharing options...
Barand Posted June 9, 2006 Share Posted June 9, 2006 Something like[code]$event_type = array();while ( $row = mysql_fetch_array($result ) ) { $event_type[] = $row[event_type];}echo 'The following event types happened today<br>' . join ('<br>', $event_type);[/code] Link to comment https://forums.phpfreaks.com/topic/11608-a-little-help-needed-with-a-array-problem/#findComment-43811 Share on other sites More sharing options...
.josh Posted June 9, 2006 Share Posted June 9, 2006 dammit Barand I forgot about join again [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]yeah you can use join or even implode on $event_type, after the first while loop, instead of the 2nd while loop. Link to comment https://forums.phpfreaks.com/topic/11608-a-little-help-needed-with-a-array-problem/#findComment-43814 Share on other sites More sharing options...
smith.james0 Posted June 9, 2006 Author Share Posted June 9, 2006 Thanks for the quick replys, I will try them out tomorrow.Thanks James Link to comment https://forums.phpfreaks.com/topic/11608-a-little-help-needed-with-a-array-problem/#findComment-43837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.