Jump to content

Line up table rows for found data


cjrose77

Recommended Posts

Here is a link to the website I am designing. http://173.167.65.189/singleton/

the username and password is ksingleton

at the bottom where the calendar is the query is searching for scheduled events, i am only posting the company_id right now,  the problem I am having is I want a scheduled event that continues through the week to stay in line with the one before.  But if the schedule before ended and a new one continues it moves the next date company_id up.  How can i align the table rows or create an empty table row on all other days if there was a schedule before.  here is the code for the calendar.

 

<?php

$db = new mysqli();

$setdate=strtotime($_GET['date']);

$session=$_GET['session'];

$calview=$_GET['calview'];

if ($setdate <> "") {

  $date=$setdate;

} else {

$date=time();

}

$day=date('d',$date);

$month=date('m',$date);

$year=date('Y',$date);

$first_day=mktime(0,0,0,$month,1,$year);

$title=date('F',$first_day);

 

$day_of_week = date('D', $first_day);

 

switch($day_of_week) {

case "Sun": $blank = 0;break;

case "Mon": $blank = 1;break;

case "Tue": $blank = 2;break;

case "Wed": $blank = 3;break;

case "Thu": $blank = 4;break;

case "Fri": $blank = 5;break;

case "Sat": $blank = 6;break;

}

 

$days_in_month = cal_days_in_month(0, $month, $year);

 

echo "<table cellpadding=0 cellspacing=0 border=0>";

echo "<tbody>";

echo "<tr>";

echo "<td><a href=?session=$session&calview=day>Day</a></td>";

echo "<td><a href=?session=$session&calview=week>Week</a></td>";

echo "<td><a href=?session=$session&calview=month>Month</a></td>";

echo "</tr>";

echo  "<tr>";

echo      "<td colspan=3>";

if ($calview=="month") {

echo        "<table border=1 width=800>";

echo            "<tbody>";

echo              "<tr height=25><th colspan=7> $title $year </th></tr>";

echo              "<tr height=25><td width=58 align=center>Sunday</td><td width=58 align=center>Monday</td><td width=58 align=center>Tuesday</td><td width=58 align=center>Wednesday</td><td width=58 align=center>Thursday</td><td width=58 align=center>Friday</td><td width=58 align=center>Saturday</td></tr>";

 

$day_count = 1;

 

echo              "<tr height=50>";

 

while ( $blank > 0 ) {

echo              "<td></td>";

$blank = $blank-1;

$day_count++;

}

 

$day_num = 1;

 

while ($day_num <= $days_in_month ) {

$newdate = $month ."/". $day_num ."/". $year;

$msqlnewdate = date('m/d/Y',strtotime($newdate));

echo "<td valign=top><table cellpadding=0 cellspacing=0 border=0><tr><td><a href=?session=$session&calview=day&date=$newdate> $day_num </a></td></tr>";

$db = new mysqli('localhost','username','password', 'rsdata');

 

if (!$db) {

  echo 'ERROR: Could not connect to database.';

} else {

$query = $db->query("SELECT * FROM rentals WHERE date_format(str_to_date(pdate_out,'%Y-%m-%d'), '%m/%d/%Y') <= '$msqlnewdate' AND date_format(str_to_date(pdate_in, '%Y-%m-%d'), '%m/%d/%Y') >= '$msqlnewdate'");

if ($query) {

  while ($result = $query->fetch_object()) {

      echo "<tr><td>".$result->company_id."</td></tr>";

  }

}

echo "</table>";

}

 

 

$day_num++;

$day_count++;

 

if ($day_count > 7) {

echo "</tr><tr>";

$day_count=1;

}

}

 

while ($day_count >1 && $day_count <=7 ) {

echo "<td></td>";

$day_count++;

}

echo "</tr></table>";

} else if ($calview=="week") {

 

} else {

 

}

       

echo      "</td>";

echo  "</tr>";

echo "</tbody>";

echo "</table>";

?>

 

MOD EDIT: DB credentials edited out.

Link to comment
https://forums.phpfreaks.com/topic/232765-line-up-table-rows-for-found-data/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.