Re: Finding next recored in a array

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

 



Richard Kurth wrote:
include ("includes/location.php");
$query = "    SELECT    day
       FROM    emailcampaign
       where    campaign_id = '1'
       AND    member_id = '8'
   ";
$DB_Change_Campaign_Results = safe_query($query);
$Campaign_array = array();
while ( $row = mysql_fetch_assoc($DB_Change_Campaign_Results) ) {
  $Campaign_array[] = $row['day'];
}
if ( isset($Campaign_array[($k + 1)])) {
   echo $Campaign_array[($k + 1)];
} else {
   echo 'Not found';
}
var_dump($Campaign_array);


This is what I get now when I run this

1

*array*
 0 => string '0' /(length=1)/
 1 => string '1' /(length=1)/
 2 => string '3' /(length=1)/
 3 => string '6' /(length=1)/
 4 => string '9' /(length=1)/
 5 => string '12' /(length=2)/
 6 => string '15' /(length=2)/
 7 => string '20' /(length=2)/
 8 => string '25' /(length=2)/
 9 => string '30' /(length=2)/




Are there going to be wholes in the date range?

if so, you will have to do that last bit like this.


<?php

include ("includes/location.php");

#
# Setting $k
# Make sure that $k is an integer, not a string.
# hence, no quotes
$k = 5;

$query = "	SELECT	day
		FROM	emailcampaign
		WHERE	campaign_id = '1'
		AND	member_id = '8'
	";
$DB_Change_Campaign_Results = safe_query($query);
$Campaign_array = array();
while ( $row = mysql_fetch_assoc($DB_Change_Campaign_Results) ) {
	$Campaign_array[] = $row['day'];
}

sort($Campaign_array);

foreach ( $Campaign_array AS $day ) {
	if ( $day <= $k ) {
		$day = next($Campaign_array);
		break;
	}
}

echo $day;

var_dump($Campaign_array);

?>



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
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