Re: Finding next recored in a array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



brian wrote:
Richard Kurth wrote:

What I am trying to is get all the days from a table where email campaign = number. and then look at the last day that was sent and find it in the list and get the next day that follows that day. At this point the script below is not working. So if you have any Ideas that would be a better way of doing this please let me know.


$query = "SELECT day FROM emailcampaign where campaign_id = '$emailcampaign' AND member_id = '$members_id'";
$DB_Change_Campaign_Results = safe_query($query);
for ($i=0; $i < mysql_num_rows($DB_Change_Campaign_Results); $i++) {
$Change_Campaign_row = mysql_fetch_array($DB_Change_Campaign_Results);
$Campaign = $Change_Campaign_row['day'];
$Campaign_array[$Campaign] = $Change_Campaign_row;
}
$k = array_search($val,$Campaign_array);
if ($k + 1 < count($Campaign_array)){ echo $Campaign_array[$k + 1]; }



You can simplify this greatly:

$Campaign_array = Array();

$DB_Change_Campaign_Results = safe_query($query);

while ($row = mysql_fetch_array($DB_Change_Campaign_Results))
{
  array_push($Campaign_array, $row['day']);
}

Because you're only selecting day from the table, your row data consists of only one column. You're repeating stuff unnecessarily by doing this:

$Campaign = $Change_Campaign_row['day'];
$Campaign_array[$Campaign] = $Change_Campaign_row;

IOW, for the row that contains '5', you'd end up with $Campaign_array[5] == an array that essentially just points to the value '5'.

I also noticed that your dump shows that the days begin with 0. If these are calendar days you're adding a further layer of complexity.


0 represents the email campain to send 0 mens send the one that gois out the day the campain starts. the next number in the list is the next day a email is sent out would represent 5 day after the starting day

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux