PHP dynamic calander - php

Im trying to make a calander in php (for school). it has to be made 100% generated values. I can do that but I cant figure out how to make it start on monday. It has to be made with only php and html,so no js css or sql is allowed to make it easier. I'm probaly doing everything wrong here but if anyone knows how I can make a calander, all help is welcome. (:
<?php
$D1 = date("l-j-m");
$D2 = date("l-j-m", strtotime("+ 1 days"));
$D3 = date("l-j-m", strtotime("+ 2 days"));
$D4 = date("l-j-m", strtotime("+ 3 days"));
$D5 = date("l-j-m", strtotime("+ 4 days"));
$D6 = date("l-j-m", strtotime("+ 5 days"));
$D7 = date("l-j-m", strtotime("+ 6 days"));
$U1 = date("g-a");
$U2 = date("g-a", strtotime("+ 1 hours"));
$U3 = date("g-a", strtotime("+ 2 hours"));
$U4 = date("g-a", strtotime("+ 3 hours"));
$U5 = date("g-a", strtotime("+ 4 hours"));
$U6 = date("g-a", strtotime("+ 5 hours"));
$U7 = date("g-a", strtotime("+ 6 hours"));
$U8 = date("g-a", strtotime("+ 1 hours"));
$U9 = date("g-a", strtotime("+ 2 hours"));
$U10 = date("g-a", strtotime("+ 3 hours"));
$U11 = date("g-a", strtotime("+ 4 hours"));
$U12= date("g-a", strtotime("+ 5 hours"));
$U13 = date("g-a", strtotime("+ 6 hours"));
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Recept 2</title>
</head>
<body>
<table border="solid">
<thead>
<tr>
<th></th>
<th><?php echo($D1); ?></th>
<th><?php echo($D2); ?></th>
<th><?php echo($D3); ?></th>
<th><?php echo($D4); ?></th>
<th><?php echo($D5); ?></th>
<th><?php echo($D6); ?></th>
<th><?php echo($D7); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo($U1); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U2); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U3); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U4); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U5); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U6) ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U7); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U8); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>1<?php echo($U9); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U10); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U11); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><?php echo($U12); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>

You can use the following HTML template along with the PHP code below - not the most elegant solution but should be simple enough for understanding by a newbie:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
<style type="text/css">
th.br_bot
{
border-bottom: 1px solid black;
padding: 2px;
}
th.br_btr
{
border-bottom: 1px solid black;
border-right: 1px solid black;
padding: 2px;
}
td.week_num
{
font-size: 9pt;
border-bottom: 1px solid black;
border-right: 1px solid black;
background-color: #D0D0D0;
padding: 2px;
}
td.day
{
font-size: 9pt;
border-bottom: 1px solid black;
border-right: 1px solid black;
}
td.day_red
{
font-size: 9pt;
border-bottom: 1px solid black;
border-right: 1px solid black;
background-color: #EFC2C3;
}
td.day_blue
{
font-size: 9pt;
border-bottom: 1px solid black;
border-right: 1px solid black;
background-color: #B6CBEF;
}
span.week_day
{
color: black;
}
span.week_end
{
color: red;
}
</style>
</head>
<body>
<table id="cal" cellspacing="0" cellpadding="0" style="border-left:1px solid black; border-top:1px solid black;font-weight:bold;">
<tr style="font-size:9pt;" bgcolor="#D6B695">
<th colspan="8" class="br_btr"> JANUARY </th>
<th colspan="8" class="br_btr"> FEBRUARY </th>
<th colspan="8" class="br_btr"> MARCH </th>
<th colspan="8" class="br_btr"> APRIL </th>
</tr>
<tr>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
</tr>
<tr><td>{SECTION_1}</td></tr>
<tr style="font-size:9pt;" bgcolor="#D6B695">
<th colspan="8" class="br_btr"> MAY </th>
<th colspan="8" class="br_btr"> JUNE </th>
<th colspan="8" class="br_btr"> JULY </th>
<th colspan="8" class="br_btr"> AUGUST </th>
</tr>
<tr>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
</tr>
<tr><td>{SECTION_2}</td></tr>
<tr style="font-size:9pt;" bgcolor="#D6B695">
<th colspan="8" class="br_btr"> SEPTEMBER </th>
<th colspan="8" class="br_btr"> OCTOBER </th>
<th colspan="8" class="br_btr"> NOVEMBER </th>
<th colspan="8" class="br_btr"> DECEMBER </th>
</tr>
<tr>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
</tr>
<tr><td>{SECTION_3}</td></tr>
</table>
</body>
</html>
<?php
// returns HTML for the given month
function month_calendar($year,$month)
{
$my_time = mktime(0,0,0,$month,1,$year); // Unix timestamp for the beginning of the month
$start_day = date('N', $my_time);
$start_week = (int)date('W',$my_time); // because date returns zero-padded value
$daysInMonth = date('t',$my_time); // how many days in the given month
$dayNumber = date('z',$my_time) + 1; // day of the year for the 1st date of the month (0 - 365)
$output = Array();
// show first week
$current_week = '<td align="center" class="week_num">'.($start_week++).'</td>';
if($start_week > 52) $start_week = 1;
$dayOfWeek = 1;
while($dayOfWeek < $start_day)
{
// show empty cells until we reach the start of the month
$current_week .= '<td class="day"> </td>';
$dayOfWeek++;
}
$dayOfMonth = 1;
while($dayOfWeek <= 7)
{
$current_week .= '<td class="day"><span class="week_'.($dayOfWeek > 5 ? 'end' : 'day').'" style="padding:2px">'.($dayOfMonth++).'</span></td>';
$dayOfWeek++;
$dayNumber++;
}
$output[] = $current_week;
while($dayOfMonth <= $daysInMonth)
{
$current_week = '<td align="center" class="week_num">'.($start_week++).'</td>';
if($start_week > 52) $start_week = 1;
$dayOfWeek = 1;
while($dayOfWeek <= 7)
{
if($dayOfMonth <= $daysInMonth) $current_week .= '<td class="day"><span class="week_'.($dayOfWeek > 5 ? 'end' : 'day').'" style="padding:2px">'.($dayOfMonth++).'</span></td>';
else $current_week .= '<td class="day"> </td>'; // show empty cells after the end of the month
$dayOfWeek++;
$dayNumber++;
}
$output[] = $current_week;
}
return $output;
}
// returns HTML for 4 months - starting at the given month/year
function section($year,$month)
{
$month_1 = month_calendar($year, $month);
$month_2 = month_calendar($year, $month + 1);
$month_3 = month_calendar($year, $month + 2);
$month_4 = month_calendar($year, $month + 3);
$max_weeks = max(
count($month_1),
count($month_2),
count($month_3),
count($month_4)
);
$empty_week = '';
for($i = 1; $i <= 8; $i++) // 7 days + a cell for the week number
$empty_week .= '<td class="day"> </td>';
$output = '';
for($i = 0; $i < $max_weeks; $i++)
{
$output .= '<tr>';
$output .= $month_1[$i] != '' ? $month_1[$i] : $empty_week;
$output .= $month_2[$i] != '' ? $month_2[$i] : $empty_week;
$output .= $month_3[$i] != '' ? $month_3[$i] : $empty_week;
$output .= $month_4[$i] != '' ? $month_4[$i] : $empty_week;
$output .= '</tr>';
}
return $output;
}
if($template = #file_get_contents('/tempates/calendar.html'))
{
// show calendar
$cal_year = 2020;
$template = str_replace('<tr><td>{SECTION_1}</td></tr>',section($cal_year,1),$template);
$template = str_replace('<tr><td>{SECTION_2}</td></tr>',section($cal_year,5),$template);
$template = str_replace('<tr><td>{SECTION_3}</td></tr>',section($cal_year,9),$template);
echo $template;
}
else die('Could not find template - calendar.html');
?>

Related

Generating dynamic data for html table with both vertical and horizontal header

It's pretty simple to create a dynamic table with horizontal headers OR vertical headers alone. But how can I generate dynamic data for a table with BOTH vertical AND horizontal headers? Is this even possible?
Table:
<table>
<tr>
<th></th>
<th scope="col">Monday</th>
<th scope="col">Tuesday</th>
<th scope="col">Wednesday</th>
<th scope="col">Thursday</th>
<th scope="col">Friday</th>
<th scope="col">Saturday</th>
<th scope="col">Sunday</th>
</tr>
<tr>
<th scope="row">Week 1</th>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<th scope="row">Week 2</th>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<th scope="row">Week 3</th>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
</tr>
<tr>
<th scope="row">Week 4</th>
<td>4</td>
<td>4</td>
<td>4</td>
<td>4</td>
<td>4</td>
<td>4</td>
<td>4</td>
</tr>
</table>
Yes it can be easily done in PHP. I've done a small example using a for-loop to give you an easier idea of how this might be accomplished
<table>
<tr>
<th></th>
<th scope="col">Monday</th>
<th scope="col">Tuesday</th>
<th scope="col">Wednesday</th>
<th scope="col">Thursday</th>
<th scope="col">Friday</th>
<th scope="col">Saturday</th>
<th scope="col">Sunday</th>
</tr>
<?php
// Create week row
for ($week = 0; $week < 10; $week++) {
echo " <tr>";
echo " <th scope='row'>Week " . $week . "</th>";
// Create day cells
for ($day = 0; $day <= 7; $day++) {
echo " <td>" . $day . "</td>";
}
echo " </tr>";
}
?>
</table>
To dynamically generate a table horizontally and vertically, you will need 2 loops, the first one being for the amount of rows and the one inside of it for the cols.
<?php
$rows = 10;
$cols = 20;
echo '<table>';
for($r=0; $r <= $rows; $c++){
echo "<tr>";
for($c=0; $c <= $cols; $r++){
echo "<td>$r</td>";
}
echo "</tr>";
}
echo '</table>';
?>

php while loop table repeating fix

I have following do while loop be it keep on repeating the table for each record how to fix it? full table repeat for each record.
Also for every row fetch can I add
<table width="1510" border="1" align="center" cellpadding="2" cellspacing="2" class="table table-bordered" >
<tbody>
<form name="f1">
<? $counter = 1;
$total_marks = 0;
$total_obtain = 0;
while($row_rsDept = mysql_fetch_array($rsDept))
{
if($counter === 1)
{
?>
<tr>
<th width="71" rowspan="3" align="center" valign="middle" scope="col"><h4>Sr. No</h4></th>
<th width="229" align="right" valign="top" scope="col"> </th>
<th colspan="8" align="center" valign="middle" scope="col"><h3>Detail of Marks</h3></th>
</tr>
<tr>
<th rowspan="2" align="left" scope="row"><h4>Subject</h4></th>
<td colspan="2" align="center"><h4>Thoery</h4></td>
<td colspan="2" align="center"><h4>Practical</h4></td>
<td width="134" rowspan="2" align="center" valign="middle"><h4>Marks Obtain</h4></td>
<td width="144" rowspan="2" align="center" valign="middle"><h4>Max Marks</h4></td>
<td width="137" rowspan="2" align="center" valign="middle"><h4>Remarks</h4></td>
<td width="137" rowspan="2" align="center" valign="middle"><h4>Grace Marks</h4></td>
</tr>
<tr>
<td width="134">Obtained Marks</td>
<td width="144">Total Marks</td>
<td width="143">Obtained Marks</td>
<td width="153">Total Marks</td>
</tr>
<? } ?>
<tr>
<th align="left" scope="row"> </th>
<th align="left" scope="row"><?php echo $row_rsDept['SUBJECTS']; ?></th>
<td><?php echo $row_rsDept['THEORYOBTAINEDMARKS']; ?></td>
<td><?php echo $row_rsDept['THEORYTOTALMARKS']; ?></td>
<td><?php echo $row_rsDept['PRACTICALOBATINEDMARKS']; ?></td>
<td><?php echo $row_rsDept['PRACTICALTOTALMARKS']; ?></td>
<td align="center" valign="middle"><?php echo $row_rsDept['MARKSOBTAINED']; ?></td>
<td align="center" valign="middle"><?php echo $row_rsDept['MAXMARKS']; ?></td>
<td align="center" valign="middle"><span class="style8"><?php echo $row_rsDept['REMARKS']; ?></span></td>
<td align="center" valign="middle"><?php echo $row_rsDept['GRACEMARKS']; ?></td>
</tr>
<tr>
<th colspan="6" align="right" valign="middle" scope="row"><h4>Total</h4></th>
<td align="center" valign="middle"><span class="style8"><?php echo $row_rsDept['TOTALMARKS']; ?></span></td>
<td align="center" valign="middle">=total of above ( )</td>
<td align="center" valign="middle"> </td>
<td align="center" valign="middle"> </td>
</tr>
<?php
} ?>
<tr>
<th colspan="10" align="left" valign="middle" scope="row"> </th>
</tr>
<tr>
<th colspan="8" align="left" valign="middle" scope="row"> </th>
<th align="left" valign="middle" scope="row"> </th>
<th align="left" valign="middle" scope="row"> </th>
</tr>
<tr>
<th colspan="8" align="left" valign="middle" scope="row"><br></th>
<th align="left" valign="middle" scope="row"> </th>
<th align="left" valign="middle" scope="row"> </th>
</tr>
</form>
</table>
I tried to fix but not working for me
Inside loop you need to increment counter variable
Inside loop add this line
$counter++;

Unable to Display Data from database in Table

I have been trying to output the result via .$result['name']. but of no use.
Below is my code:
<?php
mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
mysql_select_db("amityada_admission") or die(mysql_error());
?>
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<title>Search Inquiry</title>
</head>
<body>
<div class="container">
<h3>Search Result</h3>
<p>
<?php
$query = $_POST['query'];
$min_length = 5;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM student_admission
WHERE (`mobile` LIKE '%".$query."%') OR (`name` LIKE '%".$query."%') OR (`university` LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
echo "<table>";
while ($results = mysql_fetch_assoc($raw_results)) {
echo <<<EOD
<h2 style="background-color:#009; color:#FFF; padding: 10px; alignment-adjust:baseline">Student Admission Form</h2>
<div align="center">
<table width="90%" border="1">
<tr>
<th colspan="4" scope="row"><h3 align="left" style="background-color:#F39; color:#FFF; padding: 10px">Admission Form for | $name | Session 2015-2016</h3></th>
<td colspan="2" rowspan="7">$file</td>
</tr>
<tr>
<th colspan="4" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif" ><div align="left"><strong>Personal Details</strong></div></th>
</tr>
<tr>
<th width="29%" scope="row"><div align="left">Student Name</div></th>
<td width="9%"><div align="left">$name</div></td>
<td width="25%"><div align="left"><strong>Fathers Name</strong></div></td>
<td width="13%"><div align="left">$fname</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Mothers Name</div></th>
<td><div align="left">$mname</div></td>
<td><div align="left"><strong>Date of Birth</strong></div></td>
<td><div align="left">$dob</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Mobile Number</div></th>
<td><div align="left">$mobile</div></td>
<td><div align="left"><strong>Email ID</strong></div></td>
<td><div align="left">$email</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Gender</div></th>
<td><div align="left">$gender</div></td>
<td><div align="left"><strong>Marital Status</strong></div></td>
<td><div align="left">$maritalstatus</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Employed</div></th>
<td><div align="left">$employed</div></td>
<td><div align="left"><strong>Course Type</strong></div></td>
<td><div align="left">$coursetype</div></td>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif"><div align="left">Educational Details</div></th>
</tr>
<tr>
<th scope="row"><div align="left"><strong>Current Education</strong></div></th>
<td><div align="left">$current_educational_details</div></td>
<td><div align="left"><strong>Course Applied For</strong></div></td>
<td><div align="left">$course</div></td>
<td width="11%"><div align="left"><strong>Specialization</strong></div></td>
<td width="13%"><div align="left">$specialization</div></td>
</tr>
<tr>
<th scope="row"><div align="left">Lateral Entry</div></th>
<td><div align="left">$lateralentry</div></td>
<td><div align="left"><strong>Lateral Entry In</strong></div></td>
<td><div align="left">$lateral_entry_in</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif"><div align="left">Correspondence Address</div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Address</div></th>
<td colspan="5"><div align="left">$corr_add</div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Country</div></th>
<td><div align="left">$countryId</div></td>
<td><div align="left"><strong>State</strong></div></td>
<td><div align="left">$stateId</div></td>
<td><div align="left"><strong>City</strong></div></td>
<td><div align="left">$cityId</div></td>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif"><div align="left">Payment Option</div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Payment Mode</div></th>
<td><div align="left">$payment_method</div></td>
<td><div align="left"><strong>Payment Option</strong></div></td>
<td><div align="left">$feesinfull</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Complete Fees</div></th>
<td><div align="left">$coursefees</div></td>
<td><div align="left"><strong>Full Fees Paid</strong></div></td>
<td><div align="left">$fullfees</div></td>
<td><div align="left"><strong>Discount</strong></div></td>
<td><div align="left">$discount</div></td>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:#009; color:#FFF; padding:4px; font-family:Georgia, 'Times New Roman', Times, serif"><div align="left">Installment Options</div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div> <div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 1</div></th>
<td><div align="left">$installment1</div></td>
<td><div align="left"><strong>Paid On</strong></div></td>
<td><div align="left">$ins1</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Installment 2</div></th>
<td><div align="left">$installment2</div></td>
<td><div align="left"><strong>Paid On</strong></div></td>
<td><div align="left">$ins2</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Installment 3</div></th>
<td><div align="left">$installment3</div></td>
<td><div align="left"><strong>Paid On</strong></div></td>
<td><div align="left">$ins3</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Installment 4</div></th>
<td><div align="left">$installment4</div></td>
<td><div align="left"><strong>Paid On</strong></div></td>
<td><div align="left">$ins4</div></td>
<td><div align="left"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<th scope="row"><div align="left">Installment 5</div></th>
<th scope="row"><div align="left">$installment5</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins5</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 6</div></th>
<th scope="row"><div align="left">$installment6</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins6</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 7</div></th>
<th scope="row"><div align="left">$installment7</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins7</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 8</div></th>
<th scope="row"><div align="left">$installment8</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins8</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 9</div></th>
<th scope="row"><div align="left">$installment9</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$ins9</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left">Installment 10</div></th>
<th scope="row"><div align="left">$installment10</div></th>
<th scope="row"><div align="left"><strong>Paid On</strong></div></th>
<th scope="row"><div align="left">$installment10</div></th>
<th scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th colspan="6" scope="row"><div align="left">
<p>This is Just an Admission Form filled for the purpose of Applying for the University. This is not an University Admission Form and Should only be traeted for Pune Institute Admission Purpose. Any Changes or Request for Updation of Student Details of Change of University has to be Submitted to the IT Admin through mail on <strong>info#puneinstitute.org</strong></p>
</div></th>
</tr>
<tr>
<th colspan="6" scope="row" style="background-color:grey; color:white; padding: 7px">© Ankit 2003-2015 | Powered By © Diaphram 2011-2015 </th>
</tr>
</table>
</div>
EOD;
}
echo "</table>";
}
else{
echo "No Results Found";
}
}
else{
echo "Oops !! You Pressed Refresh Button or Minimum Input Value is $min_length";
}
?>
</table>
</body>
</html>
You're setting row data to $results, but never using it.
(In here: while ($results = mysql_fetch_assoc($raw_results)) { )
Either use extract($results) after the above code to use column names as variables like in your code or use variables as $results['name'].
Try mysql_fetch_array() instead of mysql_fetch_assoc() then print the result with the index no of column like the following
$result[0]
For Example if the name column is the 1st column in your table then use $result[0] similarly if it is 2nd, then use $result[1]
Try this and let me know
You should have:
$name here should be $results['name']
$file here should be $results['file']
$fname here should be $results['fname']
$mname here should be $results['mname']
$mobile here should be $results['mobile']
and so on with the other data on your table.
And also delete one of your </table> cause in your code you have 2 of it.

Problems scraping all data within a table

I'm having some issues getting all the data I need from two specific html tables. Tables at the bottom of this post.
The code above states html table id "table1". I also need to grab values from a table called "table2" in the exact same format. I have tried this code and can extract the td values but not the few values that are within the span specifiers within the td. I've tried multiple ways to do this but I'm just not getting it. My code looks something like:
$dom = file_get_html("internets.html);
//not sure how to specify the table exactly!? because this code didn't work.
//$tds = $dom->find('table[id=table1]',0)->find('tr');
foreach($dom->find('tr') as $key => $tr)
{
$td = $tr->find('td');
echo $td[0]->innertext . "</br>";
}
Any assistance much appreciated. I have done some searching here and also used the simple php dom manual.
Here is the format of a table:
<table id="table1">
<tbody>
<tr>
<th width="48%" scope="row">
Prev Close:
</th>
<td class="yfnc_tabledata1">
0.02
</td>
</tr>
<tr>
<th width="48%" scope="row">
Open:
</th>
<td class="yfnc_tabledata1">
0.02
</td>
</tr>
<tr>
<th width="48%" scope="row">
Bid:
</th>
<td class="yfnc_tabledata1">
<span id="yfs_b00_pgo.ax">
0.0180
</span>
</td>
</tr>
<tr>
<th width="48%" scope="row"></th>
<td class="yfnc_tabledata1"></td>
</tr>
<tr>
<th width="48%" scope="row">
1y Target Est:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
<tr>
<th width="48%" scope="row">
Beta:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
<tr>
<th width="54%" scope="row">
Next Earnings Date:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
</tbody>
</table>
<?php
$html=<<<XHTML
<table id="table1">
<tbody>
<tr>
<th width="48%" scope="row">
Prev Close:
</th>
<td class="yfnc_tabledata1">
0.02
</td>
</tr>
<tr>
<th width="48%" scope="row">
Open:
</th>
<td class="yfnc_tabledata1">
0.02
</td>
</tr>
<tr>
<th width="48%" scope="row">
Bid:
</th>
<td class="yfnc_tabledata1">
<span id="yfs_b00_pgo.ax">
0.0180
</span>
</td>
</tr>
<tr>
<th width="48%" scope="row"></th>
<td class="yfnc_tabledata1"></td>
</tr>
<tr>
<th width="48%" scope="row">
1y Target Est:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
<tr>
<th width="48%" scope="row">
Beta:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
<tr>
<th width="54%" scope="row">
Next Earnings Date:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
</tbody>
</table>
XHTML;
$dom = new DOMDocument;
$dom->loadHTML($html);
$xp = new DOMXPath($dom);
foreach ($xp->query("/*//table[#id='table1'//*/td") as $i=>$node) {
echo $node->nodeValue;
}
?>

Data in table not displaying the way I want it to

I have a spinner and what happens is that whatever number is in the spinner, when the form is submitted, it should display the word "quest" as many times as the number in the spinner.. E.g if number in spinner is 3, then it will display "quest" 3 times in the table.
The problem is displaying it in the table.
At the moment with my current code it is displaying it like this:
quest
quest
quest
Question Id, Option Type, Duration .... These are table headings
It is displaying the words quest outside the table
Instead I want the word "quest" to be displayed in the Question Id column like this:
Question Id, Option Type, Duration...
quest
quest
quest
How can I get it to display it like the example above?
Below is code
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) {
echo "<tr>quest";
}
}
?>
<td class='qid'></td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
</table>
I did try echo "<td class='qid'></td>"; but this completely failed as well
Try this:
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) {
?>
<tr>
<td class='qid'><?php echo $quest; ?></td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
<?php
} // For
} // If
?>
</table>
Is this what you want to do? Display "quest" in the first column?
<table border=1 id="qandatbl" align="center">
<tr>
<th class="col1">Question No</th>
<th class="col2">Option Type</th>
<th class="col1">Duration</th>
<th class="col2">Weight(%)</th>
<th class="col1">Answer</th>
<th class="col2">Video</th>
<th class="col1">Audio</th>
<th class="col2">Image</th>
</tr>
<?php
$spinnerCount = $_POST['txtQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) { ?>
<tr>
<td class='qid'>quest</td>
<td class="options"></td>
<td class="duration"></td>
<td class="weight"></td>
<td class="answer"></td>
<td class="video"></td>
<td class="audio"></td>
<td class="image"></td>
</tr>
<?php
}
}
?></table>
?>

Categories