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++;
}
Related
enter image description here
How can I make a loop with php where I separate the comments as rounds
All comments for the round 1
<div id="$row['round']">
$row['comments']
</div>
All comments for the round 2
<div id="$row['round']">
$row['comments']
</div>
but I can have many rounds, so I don't know the exact query to use
<div id="chat" class="chat">
<ul class="nav nav-tabs">
<?php
$stmt = $DB->query("SELECT * FROM messages WHERE $id = video_id GROUP BY round ORDER BY round DESC");
while ($row = $stmt->fetch()) {
echo '<li><a data-toggle="tab" href="#menu'.$row['round'].'">'.$row['round'].'</a></li>';
}
?>
</ul>
<div class="tab-content">
<?php
$i=-1;
$stmt = $DB->query("SELECT * FROM messages WHERE $id = video_id GROUP BY round ORDER BY round DESC");
while ($row = $stmt->fetch()) {
echo '<div class="tab-pane '.( $i = $i ? 'active' : '' ).'" id="menu'.$row['round'].'">';
$test = $row['round'];
$stmt2 = $DB->query("SELECT * FROM messages INNER JOIN system_users ON messages.user_id = u_userid WHERE $id = video_id AND $test = round ORDER BY date ASC");
while ($row2 = $stmt2->fetch()) { ?>
<br />
<p><b>round:</b> <?php echo $row2["round"]; ?></p>
<p><b>Message:</b> <?php echo $row2["message"]; ?></p>
<p><b>User:</b> <?php echo $row2["u_username"]; ?></p>
<p><b>time:</b> <?php echo date_format (new DateTime($row2["date"]), 'd|m|Y H:i:s'); ?></p>
<hr />
<?php
}$i =0;
echo '</div>';
}
?>
</div>
I am completely sure this is not the best solution, but it is working,
thanks anyway..
I have set-up a news page which retrieves news from MYSQL news table.
I am trying to identify if the news column is odd or even, so if the news columns is odd or even it will add a class to the div element.
My code is as follows:
<?php
$cat = $_GET['cat'];
$date = $_GET['date'];
if ($date !="") {
$date = explode('-', $date);
$year = $date[1];
$month = $date[0];
$month = date("m", strtotime($month));
$sql = "SELECT * FROM news WHERE year(newsDate) = '$year' AND month(newsDate) = '$month' AND newsState = 1 ORDER BY newsDate DESC";
} else {
$sql = "SELECT * FROM news WHERE newsState = 1 ORDER BY newsDate DESC";
}
$result = $conn->query($sql);
$rows = $result->num_rows;
$pager = new PS_Pagination($conn, $sql, 5, 10, null);
$rs = $pager->paginate();
$num = $rs->num_rows;
if($num >= 1 ){
while($row = $rs->fetch_assoc()){
?>
<div class="news <?php echo $num; ?>">
<div class="four columns">
<p><img src="/news-images/thumbs/thumb_<?php echo $row['newsImage1']; ?>" alt=""/></p>
</div>
<div class="eight columns">
<h3><?php echo $row['newsTitle']; ?></h3>
<p><?php echo stripslashes(strip_tags($row['newsDescription'])); ?></p>
</div>
</div>
<?php } } else {
echo "No records found!";
}
if ($rows >= 5) {
echo "<div class='page-nav blog-nav'>";
echo $pager->renderFullNav();
echo "</div>";
}
?>
TAke any flag which maintains odd-even position...
$f = 0; //ADDED THIS LINE
if($num >= 1 ){
while($row = $rs->fetch_assoc()){
if($f%2==0) //ADDED THIS LINE
$class_name = "even"; //ADDED THIS LINE
else //ADDED THIS LINE
$class_name = "odd"; //ADDED THIS LINE
?>
<div class="news <?php echo $class_name; ?>">
<div class="four columns">
<p><img src="/news-images/thumbs/thumb_<?php echo $row['newsImage1']; ?>" alt=""/></p>
</div>
<div class="eight columns">
<h3><?php echo $row['newsTitle']; ?></h3>
<p><?php echo stripslashes(strip_tags($row['newsDescription'])); ?></p>
</div>
</div>
<?php $f++; } } else {
echo "No records found!";
}
if($num >= 1 ){
$tr = 1;
while($row = $rs->fetch_assoc()){
if($tr%2 == 0)
{
//then even class
}
else
{
//odd class
}
?>
<div class="news <?php echo $num; ?>">
<div class="four columns">
<p><img src="/news-images/thumbs/thumb_<?php echo $row['newsImage1']; ?>" alt=""/></p>
</div>
<div class="eight columns">
<h3><?php echo $row['newsTitle']; ?></h3>
<p><?php echo stripslashes(strip_tags($row['newsDescription'])); ?></p>
</div>
</div>
<?php $tr++; } } else {
echo "No records found!";
}
Use counter variable and check if it is even or odd ?
Create variable, increment that in each loop and check, if $i % 2 is 0 (even) or 1 (odd).
$i = 1;
while($row = $rs->fetch_assoc()){
?>
<div class="news <?php echo $num; echo $i % 2 == 0 ? ' even' : ' odd' ?>">
<div class="four columns">
<p><img src="/news-images/thumbs/thumb_<?php echo $row['newsImage1']; ?>" alt=""/></p>
</div>
<div class="eight columns">
<h3><?php echo $row['newsTitle']; ?></h3>
<p><?php echo stripslashes(strip_tags($row['newsDescription'])); ?></p>
</div>
</div>
<?php
$i++;
}
Take $classname = '';
Get news ID in loop and divide / 2 and compare whether you getting odd / even value. In case odd value add $classname = 'oddCLASS' and in case even value add $classname = 'evenCLASS' and updare class = $classname wherever you required.
This way it will automatically update dynamic class.
so the fastest way to do this is just by using a boolean:
$odd = false;
while ( .... )
{
echo ($odd = !$odd) ? 'odd' : 'even';
}
No need to keep a counter for that, no need for a modulo and it keeps the code pretty clean. My preferred way unless you need to keep a counter. And even then: $counter & 1 == 1 is faster than $counter % 2 == 1 and does exactly the same.
Simple explanation:
echo ($odd = !$odd) ? 'odd' : 'even';
// will become
$odd = ! $odd; // it flips the boolean
if ($odd)
echo 'odd';
else
echo 'even';
<?php
$host='localhost';
$user='root';
$password='root';
$database='database';
$startindex=#$_REQUEST['seek'];
$db=mysql_connect($host, $user, $password)
or die ("Impossibile connettersi al server $host");
mysql_select_db($database, $db)
or die ("Impossibile connettersi al database $database");
$query="SELECT * FROM ordini_master";
$dbResult=mysql_query($query, $db);
$AffectedRows=mysql_affected_rows($db);
mysql_data_seek($dbResult, $startindex);
$row=mysql_fetch_row($dbResult);
foreach($row as $k=>$v)
{
$myfield=mysql_fetch_field($dbResult, $k);
print($myfield->name . " : $v <br/>");
}
mysql_free_result($dbResult);
mysql_close($db);
print("<br/>Seleziona il record<br/>");
for($index=0; $index<$AffectedRows; $index++)
{
print("<a href=\"{$_SERVER['PHP_SELF']}?seek=$index\" >" .
($index+1) . "</a> ");
}
?>
This code allow the navigation between a query records, so it create a page foreach record in database and so shows one record time. How can i modify that code to paging every 10 records? So i want to show 10 records time and create a page for the next.
Sorry for my english (I'm italian) , i hope you can help me.
What you need first is the LIMIT statement from mysql. MySql states:
The LIMIT clause can be used to constrain the number of rows returned
by the SELECT statement. LIMIT takes one or two numeric arguments,
which must both be nonnegative integer constants (except when using
prepared statements).
With two arguments, the first argument specifies the offset of the
first row to return, and the second specifies the maximum number of
rows to return. The offset of the initial row is 0 (not 1):
As for how to implement it in your code I could not have written a better answer as the one found here.
Use LIMIT to get as many records as you wish.
Example:
SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
Here is your modified code. This should work for your.
I haven't tested it but give it a try:
<?php
$host='localhost';
$user='root';
$password='root';
$database='database';
$startindex=(isset($_REQUEST['seek']) ? $_REQUEST['seek'] : 0);
$db=mysql_connect($host, $user, $password)
or die ("Impossibile connettersi al server $host");
mysql_select_db($database, $db)
or die ("Impossibile connettersi al database $database");
$queryCnt = "SELECT count(*) as cnt FROM ordini_master";
$CntRow=mysql_fetch_row(mysql_query($query, $db));
$CntData = $CntRow[0];
$step = 10;
$query="SELECT * FROM ordini_master LIMIT $startindex, $step";
$result=mysql_query($query, $db);
while ($row = mysql_fetch_assoc($result)) {
foreach($row as $k=>$v) {
$myfield=mysql_fetch_field($result, $k);
print($myfield->name . " : $v <br/>");
}
}
mysql_free_result($result);
mysql_close($db);
print("<br/>Seleziona il record<br/>");
for($index=0; $index<$CntData; $index=$index+$step) {
print("<a href=\"{$_SERVER['PHP_SELF']}?seek=$index\" >" .
($index+1) . "</a> ");
}
Use the information from tadman too.
It's very important to do something to prevent SQL injection and it's also necessary to use PDO or the mysqli extension because the mysql extension will not longer be supported.
You can use COUNT to display your records and create pages
function getLimitData($start,$limit){
//getting all items
$db = new PDO('mysql:host=localhost; dbname=data','root','');
$results = $db->query("SELECT * FROM table ORDER BY ID DESC limit $start,$limit");
$results = $results->fetchAll(PDO::FETCH_ASSOC);
return $results;
}
//database connection
$db = new PDO('mysql:host=localhost; dbname=data','root','');
//pagination pages
$nav_counter = basename($_SERVER['SCRIPT_FILENAME']);
$page_counter = $nav_counter;
$nav_counter = rtrim($nav_counter, ".php");
$cPage = $page_counter + 1;
//creating next pages
$first_next = $nav_counter + 1 ;
$sec_next = $first_next + 1 ;
$third_next = $sec_next + 1 ;
$fourth_next = $third_next + 1 ;
$fifth_next = $fourth_next + 1 ;
$sixth_next = $fifth_next + 1 ;
$seventh_next = $sixth_next + 1 ;
$next_page = $seventh_next + 1;
//creating previous pages
$first_prev = $nav_counter - 1 ;
$sec_prev = $nav_counter - 2 ;
$third_prev = $nav_counter - 3 ;
$fourth_prev = $nav_counter - 4 ;
$fifth_prev = $nav_counter - 5 ;
$sixth_prev = $nav_counter - 6 ;
$seventh_prev = $nav_counter - 7 ;
//row count
$tableExists = $db->tableExist();
$ROW_COUNT = $db->getRowCount();
$numRows= 9; //number of items to be displayed
//last page
//last page
$last_page = ($ROW_COUNT / $numRows) - 1;
if(!is_int($last_page)){
$last_page = (int)$last_page + 1;
}
$pageNate = '';
if($ROW_COUNT <= $numRows){
$pageNate = 'class="hide"';
}else{
$pageNate = 'class="exist"';
}
//displaying torrents
$start = 0;
$limit = $numRows;
if ($page_counter !== 'index.php') {
$start = ($limit * $nav_counter);
}
//getting number of rows left in the table
$rows_left = $db->getLimitData($start, $limit);
$number_rows = 0;
foreach ($rows_left as $r) {
$number_rows = $number_rows + 1;
}
if ($number_rows < $numRows) {
$limit = $number_rows;
}
$items = $db->getLimitData($start, $limit);
?>
displaying item
<ol>
<?php foreach($items as $item) : ?>
<li><php echo $item['Value']; ?></li>
<?php endforeach; ?>
</ol>
pagination code
<?php
$pages = array();
for ($counter = 1; $counter <= $last_page; $counter++) {
$pages[] = $counter;
}
//storing pages in array and creating a page if it doesn't exist
foreach ($pages as $key) {
$page = $key.'.php';
//if page doesn't exists create page
if(file_exists($page)== false && $key <= $last_page){
copy('index.php', $page);
}
}
?>
<p class="pagenav" >
<a href="index.php" <?php if ($page_counter == 'index.php') {echo 'class="hide"';} ?>><<</a>
<a href="<?php if ($page_counter == '1.php') {echo 'index.php';}else{echo "$first_prev".".php";} ?>" <?php if ($page_counter == 'index.php') {echo 'class="hide"';} ?>><</a>
<a href="<?php echo "$seventh_prev".".php"; ?>" <?php if($seventh_prev <= 0){echo 'class="hide"';} ?>><?php echo $seventh_prev;?></a>
<a href="<?php echo "$sixth_prev".".php"; ?>" <?php if($sixth_prev <= 0){echo 'class="hide"';} ?>><?php echo $sixth_prev;?></a>
<a href="<?php echo "$fifth_prev".".php"; ?>" <?php if($fifth_prev <= 0){echo 'class="hide"';} ?>><?php echo $fifth_prev;?></a>
<a href="<?php echo "$fourth_prev".".php"; ?>" <?php if($fourth_prev <= 0){echo 'class="hide"';} ?>><?php echo $fourth_prev;?></a>
<a href="<?php echo "$third_prev".".php"; ?>" <?php if($third_prev <= 0){echo 'class="hide"';} ?>><?php echo $third_prev;?></a>
<a href="<?php echo "$sec_prev".".php"; ?>" <?php if($sec_prev <= 0){echo 'class="hide"';} ?>><?php echo $sec_prev;?></a>
<a href="<?php echo "$first_prev".".php"; ?>" <?php if($first_prev <= 0 ){echo 'class="hide"';} ?>><?php echo $first_prev;?></a>
<a <?php if ($page_counter == 'index.php') {echo 'class="hide"';}else{ echo 'id="here"';} ?>><?php echo $nav_counter; ?></a>
<a href="<?php echo $first_next.'.php'; ?>" <?php if($first_next <= $last_page){echo 'class="exist"';}else{echo 'class="hide"';} ?>><?php echo $first_next;?></a>
<a href="<?php echo "$sec_next".".php"; ?>" <?php if($sec_next <= $last_page){echo 'class="exist"';}else{echo 'class="hide"';} ?>><?php echo $sec_next;?></a>
<a href="<?php echo "$third_next".".php"; ?>" <?php if($third_next <= $last_page){echo 'class="exist"';}else{echo 'class="hide"';} ?>><?php echo $third_next;?></a>
<a href="<?php echo "$fourth_next".".php"; ?>" <?php if($fourth_next <= $last_page){echo 'class="exist"';}else{echo 'class="hide"';} ?>><?php echo $fourth_next;?></a>
<a href="<?php echo "$fifth_next".".php"; ?>" <?php if($fifth_next <= $last_page){echo 'class="exist"';}else{echo 'class="hide"';} ?>><?php echo $fifth_next;?></a>
<a href="<?php echo "$sixth_next".".php"; ?>" <?php if($sixth_next <= $last_page){echo 'class="exist"';}else{echo 'class="hide"';} ?>><?php echo $sixth_next;?></a>
<a href="<?php echo "$seventh_next".".php"; ?>" <?php if($seventh_next <= $last_page){echo 'class="exist"';}else{echo 'class="hide"';} ?>><?php echo $seventh_next;?></a>
<a href="<?php echo "$first_next".".php"; ?>" <?php if($first_next <= $last_page){echo 'class="exist"';}else{echo 'class="hide"';} ?>>></a>
<a href="<?php echo $last_page.'.php'; ?>" <?php if($nav_counter == $last_page){echo 'class="hide"';}else{echo 'class="exist"';} ?>>>></a>
</p>
I'm using joomla with K2 and I want to order news in The archive module first by year. When you click on The year it Needs to show all articles from that year. Bit The module also Needs to expand The months to filter deeper
How can I modify the module to act like This?
Greets
So this is what I mean
2012
- Januari
- Februari
- March
- etc etc
2013
- Januari
- Februari
- March
- etc etc.
Both year and month needs to be filterable
How can I modify the module to act like This?
Greets
So this is what I mean
List item
2012
Januari
Februari
March
etc etc
2013
Januari
Februari
March
etc etc.
Both year and month needs to be filterable
How can I modify the module to act like This?
Greets
<div id="k2ModuleBox<?php echo $module->id; ?>" class="k2ArchivesBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">
<ul>
<?php foreach ($months as $month): ?>
<li>
<?php if ($params->get('archiveCategory', 0) > 0): ?>
<a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=date&month='.$month->m.'&year='.$month->y.'&catid='.$params->get('archiveCategory')); ?>">
<?php echo $month->name.' '.$month->y; ?>
<?php if ($params->get('archiveItemsCounter')) echo '('.$month->numOfItems.')'; ?>
</a>
<?php else: ?>
<a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=date&month='.$month->m.'&year='.$month->y); ?>">
<?php echo $month->name.' '.$month->y; ?>
<?php if ($params->get('archiveItemsCounter')) echo '('.$month->numOfItems.')'; ?>
</a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
The query is from another file
public static function getArchive(&$params)
{
$mainframe = JFactory::getApplication();
$user = JFactory::getUser();
$aid = (int)$user->get('aid');
$db = JFactory::getDBO();
$jnow = JFactory::getDate();
$now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
$nullDate = $db->getNullDate();
$query = "SELECT DISTINCT MONTH(created) as m, YEAR(created) as y FROM #__k2_items WHERE published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0";
if (K2_JVERSION != '15')
{
$query .= " AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") ";
if ($mainframe->getLanguageFilter())
{
$languageTag = JFactory::getLanguage()->getTag();
$query .= " AND language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") ";
}
}
else
{
$query .= " AND access<={$aid} ";
}
$catid = $params->get('archiveCategory', 0);
if ($catid > 0)
$query .= " AND catid=".(int)$catid;
$query .= " ORDER BY created DESC";
$db->setQuery($query);
$rows = $db->loadObjectList();
$months = array(JText::_('K2_JANUARY'), JText::_('K2_FEBRUARY'), JText::_('K2_MARCH'), JText::_('K2_APRIL'), JText::_('K2_MAY'), JText::_('K2_JUNE'), JText::_('K2_JULY'), JText::_('K2_AUGUST'), JText::_('K2_SEPTEMBER'), JText::_('K2_OCTOBER'), JText::_('K2_NOVEMBER'), JText::_('K2_DECEMBER'), );
if (count($rows))
{
foreach ($rows as $row)
{
if ($params->get('archiveItemsCounter'))
{
$row->numOfItems = modK2ToolsHelper::countArchiveItems($row->m, $row->y, $catid);
}
else
{
$row->numOfItems = '';
}
$row->name = $months[($row->m) - 1];
$archives[] = $row;
}
return $archives;
}
}
This solved my issue:
<div id="k2ModuleBox<?php echo $module->id; ?>" class="k2ArchivesBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">
<?php
foreach ($months as $month) {
$years[$month->y][] = $month;
}
?>
<?php foreach ($years as $year => $months) : ?>
<h4><?php echo $year; ?></h4>
<ul>
<?php foreach ($months as $month): ?>
<li>
<?php if ($params->get('archiveCategory', 0) > 0): ?>
<a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=date&month='.$month->m.'&year='.$month->y.'&catid='.$params->get('archiveCategory')); ?>">
<?php echo $month->name.' '.$month->y; ?>
<?php if ($params->get('archiveItemsCounter')) echo '('.$month->numOfItems.')'; ?>
</a>
<?php else: ?>
<a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=date&month='.$month->m.'&year='.$month->y); ?>">
<?php echo $month->name.' '.$month->y; ?>
<?php if ($params->get('archiveItemsCounter')) echo '('.$month->numOfItems.')'; ?>
</a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
</div>
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.