Jump to content

Archived

This topic is now archived and is closed to further replies.

smith.james0

A little help needed with a array problem.

Recommended Posts

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 etc


Thanks in advance James

Share this post


Link to post
Share on other sites
[code]$events = array();
while ( $row = mysql_fetch_array($result ) ) {

$events[] = $row[event_type];

}[/code]

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.