Jump to content

A little help needed with a array problem.


smith.james0

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.