Hi i have a code that displays title, date and location. I want it to put on a div, unfortunately there is some wrong in my code and it loops my div.
I just want all may data to be inside "may-container" i just don't know how to create this container.
Hope you could help me with this. Thanks
<div class="may-container">
<div class="May">
title
date
location
</div>
<div class="May">
title
date
location
</div>
</div>
Here is my code
$counter = 0;
while ( $startdate <= $enddate) {
if ( date("F",strtotime($result['date'])) == "May" && date("m, Y",strtotime($result['date'])) >= date("m, Y") )
{
if ($counter < 1)
{
echo "<div class='May-container'>";
$counter++;
}
echo "<div class= 'May'>";
echo $result['title'],"<br>";
echo date ('F \ j,\ Y',strtotime($result['date']) ), "<br>";
echo $result['location'];
echo "</div>";
}
$startdate = strtotime("+120 day", $startdate);
}
if your code date("F",strtotime($result['date'])) produces a month in words then why do you have to put if and else?
why not:
while ( $startdate <= $enddate) {
echo "<div class='" . date('F',strtotime($result['date'])) . "'>";
echo $result['title'],"<br>";
echo date ('F \ j,\ Y',strtotime($result['date']) ), "<br>";
echo $result['location'];
echo "</div>";
$startdate = strtotime("+120 day", $startdate);
}
EDIT: to answer your comment, you can try this code:
This code is only applicable if your Data is sorted out by date
$last_month = '';
$is_first = true;
while ( $startdate <= $enddate) {
if($last_month != date('F',strtotime($result['date']))){
echo '</div>';
$is_first = true;
}
if($is_first){
$last_month = date('F',strtotime($result['date']));
echo "<div class='". strtolower($last_month) . "-container'>";
$is_first = false;
}
echo "<div class='" . date('F',strtotime($result['date'])) . "'>";
echo $result['title'],"<br>";
echo date ('F \ j,\ Y',strtotime($result['date']) ), "<br>";
echo $result['location'];
echo "</div>";
$startdate = strtotime("+120 day", $startdate);
}
if the code above code runs as what i expected(sorry i didnt run it for i dont have enough time to) it will yields something like:
<div class="may-container">
<div class="May">
title
date
location
</div>
<div class="May">
title
date
location
</div>
</div>
<div class="june-container">
<div class="June">
title
date
location
</div>
<div class="June">
title
date
location
</div>
</div>
Related
how can i change the first day in the first column of weeks into Monday.
here's the code i got from a website, and I've been trying to change the position of the days but still it displays the first day of the week as Sunday. how can i change it to Monday, thanks in advance
if(isset($_POST['func']) && !empty($_POST['func'])){
switch($_POST['func']){
case 'getCalender':
getCalender($_POST['year'],$_POST['month']);
break;
case 'getEvents':
getEvents($_POST['date']);
break;
default:
break;
}
}
/*
* Get calendar full HTML
*/
function getCalender($year = '',$month = '')
{
$dateYear = ($year != '')?$year:date("Y");
$dateMonth = ($month != '')?$month:date("m");
$date = $dateYear.'-'.$dateMonth.'-01';
$currentMonthFirstDay = date("N",strtotime($date));
$totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN,$dateMonth,$dateYear);
$totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7)?($totalDaysOfMonth):($totalDaysOfMonth + $currentMonthFirstDay);
$boxDisplay = ($totalDaysOfMonthDisplay <= 35)?35:42;
?>
<div id="calender_section">
<h2>
<<
<select name="month_dropdown" class="month_dropdown dropdown"><?php echo getAllMonths($dateMonth); ?></select>
<select name="year_dropdown" class="year_dropdown dropdown"><?php echo getYearList($dateYear); ?></select>
>>
</h2>
<div id="event_list" class="none"></div>
<div id="calender_section_top">
<ul>
<li>Po</li>
<li>Út</li>
<li>St</li>
<li>Čt</li>
<li>Pá</li>
<li>So</li>
<li>Ne</li>
</ul>
</div>
<div id="calender_section_bot">
<ul>
<?php
$dayCount = 1;
for($cb=1;$cb<=$boxDisplay;$cb++){
if(($cb >= $currentMonthFirstDay+0 || $currentMonthFirstDay == 7) && $cb <= ($totalDaysOfMonthDisplay)){
//Current date
$currentDate = $dateYear.'-'.$dateMonth.'-'.$dayCount;
$eventNum = 0;
//Include db configuration file
include 'dbConfig.php';
//Get number of events based on the current date
$result = $db->query("SELECT title FROM events WHERE date = '".$currentDate."' AND status = 1");
$eventNum = $result->num_rows;
//Define date cell color
if(strtotime($currentDate) == strtotime(date("Y-m-d"))){
echo '<li date="'.$currentDate.'" class="grey date_cell">';
}elseif($eventNum > 0){
echo '<li date="'.$currentDate.'" class="light_sky date_cell">';
}else{
echo '<li date="'.$currentDate.'" class="date_cell">';
}
//Date cell
echo '<span>';
echo $dayCount;
echo '</span>';
//Hover event popup
echo '<div id="date_popup_'.$currentDate.'" class="date_popup_wrap none">';
echo '<div class="date_window">';
echo '<div class="popup_event">Events ('.$eventNum.')</div>';
echo ($eventNum > 0)?'view events':'';
echo '</div></div>';
echo '</li>';
$dayCount++;
?>
<?php }else{ ?>
<li><span> </span></li>
<?php } } ?>
html:
<select class="col-lg-4 col-xs-12 col-sm-5" name="fromYear" ><?php $starting_year =date('Y', strtotime('-50 year'));$ending_year = date('Y', strtotime('+4 year'));$current_year = date('Y');$selected_year = date('y',$profile->fromYear);for($starting_year; $starting_year <= $ending_year; $starting_year++) { echo '<option value="'.$starting_year.'"';if( $selected_year ) {echo ' selected="selected"'; }echo ' >'.$starting_year.'</option>';}?><select>
this code dynamically generates Dropdown for Year. How can I get year selected from the database in this code? for example,if i select 2009 in databse than this code display 2009 as selected
You don't need to do "$selected_year = date('Y',$profile->fromYear);" please check my code
<?php
$starting_year = date('Y', strtotime('-50 year'));
$ending_year = date('Y', strtotime('+4 year'));
$current_year = date('Y');
$selected_year = $profile->fromYear; //previosly selected year
?>
<select class="col-lg-4 col-xs-12 col-sm-5" name="fromYear" >
<?php
for($starting_year; $starting_year <= $ending_year; $starting_year++) {
echo '<option value="'.$starting_year.'"';
if($selected_year == $starting_year){
echo ' selected="selected"';
}
echo ' >'.$starting_year.'</option>';
}?>
I think you want the selected year as the current year please check my code
<select class="col-lg-4 col-xs-12 col-sm-5" name="fromYear" >
<?php
$starting_year =date('Y', strtotime('-50 year'));
$ending_year = date('Y', strtotime('+4 year'));
$current_year = date('Y');
$selected_year = date('Y',$profile->fromYear);
for($starting_year; $starting_year <= $ending_year; $starting_year++)
{
echo '<option value="'.$starting_year.'"';
if( $selected_year == $starting_year)
{
echo ' selected="selected"';
}
echo ' >'.$starting_year.'</option>';
}
?>
<select>
I am using SimplePie to display the RSS results from multiple sources, however I'm finding that there's several I don't need to see. How do I only show the results that are 5 days old or younger?
Here's my current PHP code:
foreach ($feed->get_items(0) as $item):
$url = $item->get_permalink();
$title = $item->get_title();
$date = $item->get_date('F j, Y - g:i a');
$description = $item->get_description();
if (strpos($url,'craigslist') !== false) {
echo ' <div id="linkCell" style="width: 100%;">';
echo ' <div id="vAlign">';
echo ' <p class="linkTitle">';
echo ' '.$title.'';
echo ' </p><br />';
echo ' <span class="date">'.$date.'</span><br>';
echo ' <p class="description">'.$description.'</p>';
echo ' </div>';
echo ' </div>';
}
endforeach;
Thanks in advance!
Something like this should work. Need to convert date to unix timestamps, find the difference, and then convert this to days.
foreach ($feed->get_items(0) as $item):
$url = $item->get_permalink();
$title = $item->get_title();
$date = $item->get_date('F j, Y - g:i a');
$datestrtotime = strtotime($date);
$now = time();
$datediff = $now - datestrtotime;
$daysdifference = floor($datediff/(60*60*24));
$description = $item->get_description();
if($daysdifference>5)
{
if (strpos($url,'craigslist') !== false) {
echo ' <div id="linkCell" style="width: 100%;">';
echo ' <div id="vAlign">';
echo ' <p class="linkTitle">';
echo ' '.$title.'';
echo ' </p><br />';
echo ' <span class="date">'.$date.'</span><br>';
echo ' <p class="description">'.$description.'</p>';
echo ' </div>';
echo ' </div>';
}
}
endforeach;
In the code below, I'm pulling all upcoming training classes from my database. I'm checking to see if the endDate has passed and I'm also checking if the status !='2'
I want this to return the 4 most recent results. It works fine until statusdoes =2. I understand that the loop is technically running 4 times, but only displaying the results with status !='2'
How can I change this so that if status = '2' the loop will continue until it finds 4 results that meet the criteria?
<?php
$today = date("Y-m-d");
$count = 0;
$sth = $dbh->query('SELECT * from training ORDER BY startDate ASC');
$sth->setFetchMode(PDO::FETCH_ASSOC);
while($count <= 4 && $row = $sth->fetch()) {
if($row['endDate'] > $today && $row['status'] != '2') {?>
<li>
<img class="post_thumb" src="/images/img.jpg" alt="" />
<div class="post_description">
<small class="details">
<?php echo date("m/d/Y", strtotime($row['startDate'])) . ' - ' . date("m/d/Y", strtotime($row['endDate'])) ?>
</small>
<a class="post_caption" href="/register.php?course_id=<?php echo $row['courseId'] . '&id=' . $row['id'] ?>"><?php echo $row['title'] ?></a>
</div>
</li>
<?php }
$count++;
}
?>
You must put the $count++ inside the if loop, otherwise it will always get incremented.
As in:
<?php
$today = date("Y-m-d");
$count = 0;
$sth = $dbh->query('SELECT * from training ORDER BY startDate ASC');
$sth->setFetchMode(PDO::FETCH_ASSOC);
while($count <= 4 && $row = $sth->fetch()) {
if($row['endDate'] > $today && $row['status'] != '2') {?>
<li>
<img class="post_thumb" src="/images/img.jpg" alt="" />
<div class="post_description">
<small class="details">
<?php echo date("m/d/Y", strtotime($row['startDate'])) . ' - ' . date("m/d/Y", strtotime($row['endDate'])) ?>
</small>
<a class="post_caption" href="/register.php?course_id=<?php echo $row['courseId'] . '&id=' . $row['id'] ?>"><?php echo $row['title'] ?></a>
</div>
</li>
<?php
$count++;
}
}
?>
You can break out out of the loop, if its four
while($row = $sth->fetch()) {
....
if($row['status']=='2' && $count >="4") break;
$count++;
}
I am trying to outputting data from a SQL table
Table cols are:
sheduleID, userID, empID, timeSlot, WeekSlot, daySlot
Connecting to DB
$schedQ = "SELECT * FROM seo_schedule WHERE empID=1 AND weekSlot=1";
$Em1Wk1Res = mysql_query($schedQ) or die(mysql_error());
Displaying Data
echo "<div class='week1'>";
while ($Em1WkRow = mysql_fetch_array($Em1Wk1Res)) {
$clientQ = "SELECT * FROM clients WHERE userID=".$Em1WkRow["userID"]."";
$clientRes = mysql_query($clientQ) or die(mysql_error());
$clientRow = mysql_fetch_array($clientRes);
echo "<div class='day".$Em1WkRow["daySlot"]."'>";
if ($Em1WkRow["timeSlot"] == "am") {
echo "<span class='".$Em1WkRow["timeSlot"]."'>";
echo $clientRow["company"];
echo "</span>";
}
else if ($Em1WkRow["timeSlot"] == "pm") {
echo "<span class='".$Em1WkRow["timeSlot"]."'>";
echo $clientRow["company"];
echo "</span>";
}
echo "</div>";
}
echo "</div>";
Current Output
<div class="week1">
<div class="day1">
<span class="am">Company 1</span>
</div>
<div class="day1">
<span class="pm">Company 1</span>
</div>
<div class="day2">
<span class="am">Company 2</span>
</div>
<div class="day2">
<span class="pm">Company 2</span>
</div>
...etc fir rest of days in week 1
</div>
What I want to be displayed is:
<div class="week1">
<div class="day1">
<span class="am">Company 1</span>
<span class="pm">Company 1</span>
</div>
<div class="day2">
<span class="am">Company 2</span>
<span class="pm">Company 2</span>
</div>
...etc fir rest of days in week 1
</div>
How do I go about doing this....?
You need a nested while to go through the days of the week rendering <span />s inside the week container. I'm not a php dev so can't help you with the implementation, sorry.
The question is do these events depend on a specific time or are you just trying to throw them in 1 company event per day AM and PM? In which case, you can just do:
$arr = array(0 => "am", 1 => "pm");
echo "<div class='week1'>";
while($Em1WkRow = mysql_fetch_array($Em1Wk1Res))
{
$clientQ = "SELECT * FROM clients WHERE userID='" . $Em1WkRow["userID"] . "'";
$clientRes = mysql_query($clientQ) or die(mysql_error());
$i = 0;
$out .= "<div class='day" . $Em1WkRow["daySlot"] . "'>"; // start day
while($clientRow = mysql_fetch_array($clientRes) && $i < 2)
{
// add current day's event
$out .= "<span class='" . $arr[$i++] . "'>";
$out .= $clientRow["company"];
$out .= "</span";
}
$out .= "</div>" // end day
}
echo $out; // display all week's info
echo "</div>"; // end week
This is what I ended up doing...
function emp_schedule($empID) {
$weeks = array(1, 2, 3, 4);
foreach ($weeks as $i => $week) {
$schedQ = "SELECT * FROM seo_schedule WHERE empID=$empID AND weekSlot=$week";
$Em1WkRes = mysql_query($schedQ) or die(mysql_error());
echo "<div class='week'>";
echo "<div class='head'><span class='ts'>Wk ".$week."</span> <span>Monday</span> <span>Tuesday</span> <span>Wednesday</span> <span>Thursday</span> <span>Friday</span></div>";
echo "<div class='ts'><span><strong>AM</strong></span><span><strong>PM</strong></span></div>";
while ($Em1WkRow = mysql_fetch_array($Em1WkRes)) {
$clientQ = "SELECT * FROM clients WHERE userID='".$Em1WkRow["userID"]."'";
$clientRes = mysql_query($clientQ) or die(mysql_error());
while($clientRow = mysql_fetch_array($clientRes)) {
$schd = "<div class='".$Em1WkRow["timeSlot"]."'>";
$schd .= "<span class='client'>".$clientRow["company"]."</span>";
$schd .= "</div>";
$days = array(1, 2, 3, 4, 5);
foreach ($days as $i => $day) {
if ($Em1WkRow["daySlot"] == $day && $Em1WkRow["timeSlot"] == "am" ) {
echo "<div class='day ".$Em1WkRow["daySlot"]."'>";
echo $schd;
}
if ($Em1WkRow["daySlot"] == $day && $Em1WkRow["timeSlot"] == "pm" ) {
echo $schd;
echo "</div>";
}
}
}
}
echo "</div>";
}
}
Mess I Know but it works.