I have a problem. I have a column called 'dates' inside table called 'Programs'.
The dates are strung together with '&'. For example: 2007-10-01&2007-01-15... etc...
I need to print only the first date of each program. How can I do this? I know I would probably need to use explode to separate the dates??
I'm learning PHP and still a beginner. Thanks in advance.
Buddy
Get a recordset correctly into an array
Moderator: General Moderators
Yes, use explode(). If you already have the dates into a PHP variable, then getting the first date will be really easy.
Code: Select all
$dates = explode('&', $yourvariableholdingthedates);
echo $dates[0]; //prints the first dateSet Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Looping through
feyd | Please use
When I do a print_r($isPrinted) the output looks like this:
As you can see there duplicates in this array. How do I check for duplicates when adding to this array? I dont know how to use in_array with an array since this is a multidimensional array.
Buddy
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hey guys I have this loop which populates the $isPrinted array.Code: Select all
$isPrinted = array();
while ($day_num <= $days_in_month) {
$newDay = mktime(0,0,0,$month, $day_num, $year);
$day_of_week = date('D', $newDay);
foreach ($chosen_dates as $c) {
if ($c['day'] == $day_num) {
if ($section == false){
}
else
{
$datenum = $c['datenum'];
echo $datenum. " ";
$date_search = mysql_query("SELECT num, category FROM programsWHERE dates REGEXP '&$datenum&'");
$date_found = mysql_num_rows($date_search);
if ($date_found > 0) {
while($row = mysql_fetch_object($date_search)) {
$isPrinted[] = array('section'=>$c['section'], 'courseNum'=>$row->num);
}
}
}
}
}
$day_num++;
}Code: Select all
Array ( [0] => Array ( [section] => 2 [courseNum] => 9 ) [1] => Array ( [section] => 1 [courseNum] => 3 ) [2] => Array ( [section] => 1 [courseNum] => 7 ) [3] => Array ( [section] => 2 [courseNum] => 3 ) [4] => Array ( [section] => 2 [courseNum] => 10 ) [5] => Array ( [section] => 3 [courseNum] => 9 ) [6] => Array ( [section] => 1 [courseNum] => 3 ) [7] => Array ( [section] => 1 [courseNum] => 3 ) )Buddy
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]