Re: Finding next recored in a array
| From: | Richard Kurth | Date: | Mon, 17 Sep 2007 18:50:16 +0000 |
| Subject: | Re: Finding next recored in a array | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262174@lists.php.net to get a copy of this message | ||
M. Sokolewicz wrote:
Rick Pasotto wrote:$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]; }On Sun, Sep 16, 2007 at 06:04:45PM -0700, Richard Kurth wrote:if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; } is very over-the-top. What's wrong with if (isset($Campaign_array[$k+1]) { echo $Campaign_array[$k + 1]; } Not to mention I don't really like the whole way this has been handled, I'm sure there are better ways, but for this we'd need to know more about what you're doing and what you're trying to achieve, which we obviously don't. 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.Richard Kurth wrote:Yup. Sorry 'bout that.Rick Pasotto wrote:I figured out way it was not working $k + 1 > count needed to be $k + 1 < countOn Sun, Sep 16, 2007 at 07:09:02PM -0400, brian wrote:I tried this and it gives me nothing back. It should give me a 8 $Campaign_array= array('0','1','3','5','8','15','25'); $val="5"; $k = array_search($val,$Campaign_array); if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }Richard Kurth wrote:Nope. Just use array_search(). $k = array_search('5',$Campaign_array); if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }$Campaign_array| = array('0','1','3','5','8','15','25');| I know that I can find the next recored in a array using next. What I do not understand is if I know the last number was say 5 how do I tell the script that that is the current number so I can select the next record ||I think you'll need your own function for this.But now it works perfect