i have a timetable application which needs to generate timetables for all teachers in one go based on the semester. i am querying teacher id(s) and inside the while loop i am using the same code used to generate an individual teacher's timetable. according to mysql logs, query is firing for every teacher id but same timetable is being generated for all teachers.
i checked every line of code but its somehow not working.
I am so stuck on this, please help.
my php code:
<?php
include ("includes/functions.php");
$timespan = mysql_real_escape_string($_GET['timespan']);
$q11 = "select * from teachers order by teacher";
$r11 = mysql_query($q11) or die(mysql_error());
while($rows11 = mysql_fetch_array($r11)){
$teacher = $rows11['id'];
$array_day=array('Mon' => 0, 'Tue' => 1, 'Wed' => 2, 'Thu' => 3, 'Fri' => 4, 'Sat' => 5);
if($timespan=="BS"){
$qs="";
}
else if ($timespan=="MS"){
$qs=" and (partno='1' or partno='3' or partno='5' or partno='9') ";
}
else if ($timespan=="WS"){
$qs=" and (partno='2' or partno='4' or partno='6' or partno='9') ";
}
else if ($timespan=="1"){
$qs=" and partno='1' ";
}
else if ($timespan=="2"){
$qs=" and partno='2' ";
}
else if ($timespan=="3"){
$qs=" and partno='3' ";
}
else if ($timespan=="4"){
$qs=" and partno='4' ";
}
else if ($timespan=="5"){
$qs=" and partno='5' ";
}
else if ($timespan=="6"){
$qs=" and partno='6' ";
}
else if ($timespan=="7"){
$qs=" and partno='7' ";
}
else if ($timespan=="8"){
$qs=" and partno='8' ";
}
else if ($timespan=="10"){
$qs=" and partno='1' ";
}
else if ($timespan=="11"){
$qs=" and partno='2' ";
}
else if ($timespan=="9"){
$qs=" and partno='9' ";
}
if($qs==""){
$q1="SELECT tt.day as day, tt.period as period, tt.egstatus as egstat, tt.resp_id as id, tt.sub_group, tt.filter, c.shortname as c_s, p.shortname as p_s, tt.teacherid, tt.subjectid as subject, r.room as room, t.apd1 as apd1, t.apd2 as apd2, g.groupname as class, t.teacher as teacher, p.courseid as course, p.partno as part FROM course c, papers p, ttresponsibility tt, teachers t, groups g, rooms r where c.id=p.courseid and p.paperid = tt.subjectid and tt.teacherid= t.id and tt.room=r.room_id and tt.groupname=g.group_id and tt.teacherid = '$teacher' order by tt.day,tt.period,p.partno ASC";
}else{
$q1="SELECT tt.day as day, tt.period as period, tt.egstatus as egstat, tt.resp_id as id, tt.sub_group, tt.filter, c.shortname as c_s, p.shortname as p_s, tt.teacherid, tt.subjectid as subject, r.room as room, t.apd1 as apd1, t.apd2 as apd2, g.groupname as class, t.teacher as teacher, p.courseid as course, p.partno as part FROM course c, papers p, ttresponsibility tt, teachers t, groups g, rooms r where c.id=p.courseid and p.paperid = tt.subjectid and tt.teacherid= t.id and tt.room=r.room_id and tt.groupname=g.group_id and tt.teacherid = '$teacher'" .$qs. " order by tt.day,tt.period,p.partno ASC";
}
$r1 = mysql_query($q1) or die ("responsibility fetch error:" .mysql_error());
if(mysql_num_rows($r1) > 0){
$q2 = "select teacher,name2,type from teachers where id = '$teacher'";
$r2 = mysql_query($q2) or die("teacher fetch error:" .mysql_error());
$rows1 = mysql_fetch_array($r2);
//$num = mysql_num_rows($r1);
echo "<table width=100% style='border:0px ;font-family:arial;font-size:10px; border- collapse:collapse;cellspacing:0;padding:0px;'><tr><td width=50% align=left border=0 style='border:0px ;font-family:arial;font-size:10px; border-collapse:collapse;cellspacing:0;padding:0px;'>Dated: 31st July 2012</td><td style='border:0px ;font-family:arial;font-size:10px; border-collapse:collapse;cellspacing:0;padding:0px;' width=50% align=right border=0>Version 2.0</td></tr></table>";
echo "<center><font size=5><strong>Shri Ram College of Commerce</strong></font></center>";
echo "<br>";
echo "<table width=100%><tr><td align=left style='border:0px ;font-family:arial;font-size:10px; border-collapse:collapse;cellspacing:0;padding:0px;' ><font size=4><strong>Teacher: ";
if($rows1['type']==1){
echo "".$rows1['name2']."";
}else{
echo "".$rows1['teacher']."";
}
echo "</strong></h3></font></b></td>";
if ($timespan=="MS"){
echo "<td align=right style='border:0px ;font-family:arial;font-size:10px; border-collapse:collapse;cellspacing:0;padding:0px;'><font size=4><strong>Time Span: Monsoon Term</strong></font></br></td></tr></table>";
}
else if ($timespan=="WS"){
echo "<td align=right style='border:0px ;font-family:arial;font-size:10px; border- collapse:collapse;cellspacing:0;padding:0px;'><font size=4><strong>Time Span: Winter Term</strong></font></br></td></tr></table>";
}
echo "<br>";
echo "<table width='100%' border='1' class='tt'>";
echo "<tr class='heads'>";
echo "<td rowspan='2' style='padding:0;text-align:center; width:1%;'> <b>Period<br>Time</b></td>";
echo "<td style='padding:0;text-align:center; '><b>I</b></td>";
echo "<td style='padding:0;text-align:center; '><b>II</b></td>";
echo "<td style='padding:0;text-align:center; '><b>III</b></td>";
echo "<td style='padding:0;text-align:center; '><b>IV</b></td>";
echo "<td style='padding:0;text-align:center; '><b>V</b></td>";
echo "<td style='padding:0;text-align:center; width:1%;' ><b>Break</b></td>";
echo "<td style='padding:0;text-align:center; '><b>VI</b></td>";
echo "<td style='padding:0;text-align:center; '><b>VII</b></td>";
echo "<td style='padding:0;text-align:center; '><b>VIII</b></td>";
echo "<td style='padding:0;text-align:center; '><b>IX</b></td>";
echo "</tr>";
echo "<tr class='heads'>";
echo "<td style='padding:0;text-align:center; '><b>8:40 AM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>9:35 AM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>10:30 AM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>11:25 AM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>12:20 PM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>1:15 PM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>2:00 PM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>2:55 PM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>3:50 PM</b></td>";
echo "<td style='padding:0;text-align:center; '><b>4:45 PM</b></td>";
echo "</tr>";
$k="ToFetchNextRow";
$l = 0;
$rowToProcess=0;
$toRepeat=1;
$num=mysql_num_rows($r1);
$num1=$num-1;
for($i=0;$i<=5;$i++){
$day = array_search($i, $array_day);
echo "<tr class='period'><td style='padding:0;text-align:center;'>
<b>".$day."</b></td>";
for($j=0;$j<=8;$j++){
if($i==0 and $j==5){
echo "<td style='xycell' rowspan=6 > </td>";
}
$noOfEntriesAddedInThisCell=0;
$toRepeat=1;
while($toRepeat==1){
$rows = mysql_fetch_array($r1);
$data[] = $rows; // creating multidimensional array
$dt = $data[$rowToProcess]['day'];
$period = $data[$rowToProcess]['period'];
$paper = $data[$rowToProcess]['p_s'];
$course = $data[$rowToProcess]['c_s'];
$room = $data[$rowToProcess]['room'];
$class = $data[$rowToProcess]['class'];
$id = $data[$rowToProcess]['id'];
$part = $data[$rowToProcess]['part'];
$subgroup = $data[$rowToProcess]['sub_group'];
$weekselector = $data[$rowToProcess]['filter'];
$egstatus = $data[$rowToProcess]['egstat'];
//process the row to be processed
//add the cell entry if it is of interest
if(($i+1) == $dt and ($j+1) == $period){
// check if the slot is busy
if($egstatus == 1){
echo "<td style='xycell' valign=center align=center class='tt'><b><div style='border- bottom:0px solid #bbb;padding:0;font-family:arial;font-size:11px'> <center>Contact<br>Hour</center></td>";
}
elseif($egstatus == 2){
echo "<td style='xycell' valign=center align=center><b><div style='border-bottom:0px solid #bbb;padding:0;font-family:arial;'><a class='slot' style='border-bottom:0px solid #ccc;' href='#' id='status".$dt."+".$period."' onclick='editSlot(".$dt.','.$period.','.$teacher.','.$id."); return false'>Busy</td>";
}
elseif($egstatus == 0){
$e = $i + 1;
$f = $j + 1;
if($noOfEntriesAddedInThisCell==0){
echo "<td valign=center align=center style='border:2px solid #000;padding:0;font-family:arial;'";
if($subgroup!=0){
echo "class='orangeBlock'";
}else{
echo "class='yellowBlock'";
}
echo "><b>";
}
echo "<table class='' style='border:0px solid #000;font-family:arial;border-collapse:collapse;cellspacing:0;padding:0px;'>";
echo "<tr>";
echo "<td style='border-collapse:collapse;border:0px ;font-size:11px; font-family: arial, arial,helvetica, sans-serif;' valign='top'><b> ".$course."-".$part." ".$class."";
if($subgroup!=0){
echo "".$subgroup." ";
}
echo "".$paper." ".$room."";
if($weekselector==1){
echo "(O)</td>";
}
if($weekselector==2){
echo "(E)</td>";
}
echo "</td></tr></table>";
}
$noOfEntriesAddedInThisCell = $noOfEntriesAddedInThisCell+1;
if($rowToProcess < $num1){
$rowToProcess=$rowToProcess+1;
}else{
$toRepeat=0;
}
}else{
if($noOfEntriesAddedInThisCell !=0){
//close the internal table cell
echo "</td>";
}else{
//fill the empty cell
$r = $i + 1;
$s = $j + 1;
echo "<td valign='top' class='tt'><br><br><br></td>";
}
$toRepeat=0;
}
}//while closing
}//jloop closing
}// closing i
echo "</tr>";
echo "</table>";
echo "<br><br><br><br>";
echo "<table width=100% style='border:0px ;font-family:arial;font-size:11px; border-collapse:collapse;cellspacing:0;padding:0px;'>";
echo "<tr><td style='border:0px ;font-family:arial;font-size:11px; border-collapse:collapse;cellspacing:0;padding:0px;' align=left style=font-size:11px> Convenor</td> <td style='border:0px ;font-family:arial;font-size:11px; border-collapse:collapse;cellspacing:0;padding:0px;' align=center style=font-size:11px>Teacher Incharge</td><td style='border:0px ;font-family:arial;font-size:11px; border-collapse:collapse;cellspacing:0;padding:0px;' align=right style=font-size:11px>Principal</td></tr>";
echo "<tr><td style='border:0px ;font-family:arial;font-size:11px; border-collapse:collapse;cellspacing:0;padding:0px;' align=left style=font-size:11px style='border-collapse:collapse;border:0px solid #000;'> Vikas Madan</td><td style='border:0px ;font-family:arial;font-size:11px; border-collapse:collapse;cellspacing:0;padding:0px;' align=center style=font-size:11px>Amit Sachdeva</td><td style='border:0px ;font-family:arial;font-size:11px; border-collapse:collapse;cellspacing:0;padding:0px;' align=right style=font-size:11px>P. C. Jain</td></tr>";
echo "</table>";
}
else{
echo "";
}
}
?>
edited code snippet:
while($toRepeat==1){
while($rows = mysql_fetch_array($r1)){
$data[] = $rows; // creating multidimensional array
$dt = $data[$rowToProcess]['day'];
$period = $data[$rowToProcess]['period'];
$paper = $data[$rowToProcess]['p_s'];
$course = $data[$rowToProcess]['c_s'];
$room = $data[$rowToProcess]['room'];
$class = $data[$rowToProcess]['class'];
$id = $data[$rowToProcess]['id'];
$part = $data[$rowToProcess]['part'];
$subgroup = $data[$rowToProcess]['sub_group'];
$weekselector = $data[$rowToProcess]['filter'];
$egstatus = $data[$rowToProcess]['egstat'];
}
and the output afterwards.
You need to create another while loop while ($rows = mysql_fetch_array($r1)) { } You currently don't have this in a loop thus the repeating value.
Take this out of the loop:
$array_day=array('Mon' => 0, 'Tue' => 1, 'Wed' => 2, 'Thu' => 3, 'Fri' => 4, 'Sat' => 5);
I am not quite sure what you are asking. What do you mean it results of only one variable. Do you mean the first variable in the loop is the only one being returned correctly or on the second loop no variables are being returned correctly?
Related
I am new to PHP, iam trying to color the cells of column4,column7,column9 based on condition which you can see in the IF block,below is my code what i tried,kindly help me to understand how to achieve this. i am using array because i have got more than 80 columns,in below example iam showing only 10 for explaining.
<?php
$con=mysqli_connect("server","user","password","db");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM table1");
echo "<table id='table_id' class='mytable'>
<thead>
<tr>
<th class='heading'>Column1</th>
<th class='heading'>Column2</th>
<th class='heading'>Column3</th>
<th class='heading'>Column4</th>
<th class='heading'>Column5</th>
<th class='heading'>Column6</th>
<th class='heading'>Column7</th>
<th class='heading'>Column8</th>
<th class='heading'>Column9</th>
<th class='heading'>Column10</th>
</tr>
</thead>";
echo "<tbody>";
while ($row = mysqli_fetch_array($result))
{
$colorfields = array($row['Column4'],$row['Column7'],$row['Column9']);
if ($colorfields < 195 && $colorfields !='')
$classname = "red";
else if($colorfields >= 195 && $colorfields < 199.99)
$classname = "yellow";
else if($colorfields >= 199.99)
$classname = "green";
echo "<tr>";
echo "<td class='normal_cell'>" . $row['Column1']."</td>";
echo "<td class='normal_cell'>" . $row['Column2']."</td>";
echo "<td class='normal_cell'>" . $row['Column3']."</td>";
echo "<td class=".$classname.">". $row['Column4']."</td>";
echo "<td class='normal_cell'>" . $row['Column5']."</td>";
echo "<td class='normal_cell'>" . $row['Column6']."</td>";
echo "<td class=".$classname.">". $row['Column7']."</td>";
echo "<td class='normal_cell'>" . $row['Column8']."</td>";
echo "<td class=".$classname.">". $row['Column9']."</td>";
echo "<td class='normal_cell'>" . $row['Column10']."</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
mysqli_close($con);
?>
I'd write a function that returns the 'red', 'yellow' or 'green', depending the value that is passed in as an argument.
function class_from_val($val) {
$classname = '';
if( $val < 195 && $val !='' ) {
$classname = 'red';
} else if( $val >= 195 && $val < 199.99 ) {
$classname = 'yellow';
} else if( $val >= 199.99 ) {
$classname = 'green';
} else {
// ? val = ""
}
return $classname;
}
Then I'd call the function where I need the classname returned
echo "<td class='normal_cell'>" .$row['Column3']."</td>";
echo "<td class='".class_from_val($row['Column4'])."'>".$row['Column4']."</td>";
echo "<td class='normal_cell'>" .$row['Column5']."</td>";
echo "<td class='normal_cell'>" .$row['Column6']."</td>";
echo "<td class='".class_from_val($row['Column7'])."'>".$row['Column7']."</td>";
Follow these general principles:
indent the code and space it
choose carefully your variable names
divide and rule (use functions)
example:
function getClassName($col, $field) {
if ( !in_array($col, [ 'Column4', 'Column7', 'Column9' ]) || empty($field) )
return 'normal_cell';
if ( $field >= 199.99 )
return 'green';
if ( $field >= 195 )
return 'yellow';
return 'red';
}
$cellFormat = '<td class="%s">%s</td>';
while ($row = mysqli_fetch_array($result)) {
echo '<tr>';
foreach ($row as $col => $field) {
printf($cellFormat, getClassName($col, $field), $field);
}
echo '</tr>';
}
Please be lenient on me as I am yet to learn the intricacies of PHP coding. Still at baby steps.
I am trying to practice my PHP coding skills and started with trying to create a Marks aggregation system wherein school teachers can, visually get to know the ups and downs in student's performance, based on academic scores.
Scenario: Student's Marks are stored in MySQL table and the teacher needs to look at 30(assume) students' records. My thought is to show the marks by 'coloring the individual marks(foreground-only: the color of digits are to stand out for easier reference' based on a coloring system.
That is, for UT1(unit test 1), if a student has scored:
Greater than 81, score should displayed in green color.
Greater than 60 but below 80, score should displayed in orange color.
Simply put
Marks >= 81 and <=100 should be green in color(100 marks is the benchmark)
Marks >=61 and <=80 should be orange in color
Marks >=41 and <=60 should be red in color
My code trials until now have come up to here:
<?php
// color code function
function color_marks($marks) {
$color_code = "";
// echo "Marks: " .$marks;
/* if($marks>=0 && $marks<=40) { return $color_code = "FF0000";}
elseif($marks>=41 && $marks<=60) { return $color_code = "FF4444";}
elseif($marks>=61 && $marks<=80) { return $color_code = "FF8800";}
elseif($marks>=81 && $marks<=100) { return $color_code = "00FF00";}
*/
if ($marks >= 81) {
$color_code = "00FF00";
echo "<br />Returning color:".$color_code;
return $color_code = "00FF00";
}
elseif ($marks >= 61) {
return $color_code = "FF8800";
}
elseif ($marks >= 41) {
return $color_code = "FF4444";
}
else {
return $color_code = "FF0000";
}
echo "<br />Returning color:".$color_code;
//if($marks<=60) { return $color_code = "GREEN";} else return $color_code = "RED";
/* if($marks>=81 && $marks<=100) { return $color_code = "338800";}
else { if($marks>=61 && $marks<=80) { return $color_code = "FF8800";}
else { if($marks>=41 && $marks<=60) { return $color_code = "FF4444";}
else { if($marks>=0 && $marks<=40) { return $color_code = "FF0000";}
} }} */
}
// START DEFAULT DATATABLE
echo "<div class='panel panel-default'>";
echo "<div class='panel-heading'>";
echo "<h3 class='panel-title'>Marks of X<sup>th</sup> A - Section</h3>";
echo "</div>";
echo "<div class=panel-body'>";
echo "<table class='table datatable'>";
echo "<thead>";
echo "<tr>";
echo "<th style='text-align:center;'>Roll No.</th>";
echo "<th>Student Name</th>";
echo "<th style='text-align:center;'>Unit 1</th>";
echo "<th style='text-align:center;'>Unit 2</th>";
echo "<th style='text-align:center;'>Quarterly</th>";
echo "<th style='text-align:center;'>Unit 3</th>";
echo "<th style='text-align:center;'>Half-Yearly</th>";
echo "<th style='text-align:center;'>Unit 4</th>";
echo "<th style='text-align:center;'>Annually</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
// Get data from the table from here
include('../config.inc.php');
$sql_query="SELECT * FROM learn_php.2015_2016_test_marks";
$result = mysqli_query($connecDB, $sql_query);
$color_code = '';
while($row = mysqli_fetch_array($result)) {
echo " ut1_marks - ".color_marks($row['ut1_marks'])." - ".$row['ut1_marks'];
echo " ut2_marks - ".color_marks($row['ut2_marks'])." - ".$row['ut2_marks'];
// lets find what color the marks are
if ($row['ut1_marks'] >0 ) { $color_code = color_marks($row['ut1_marks']); }
if ($row['ut2_marks'] >=0 ) { $color_code = color_marks($row['ut2_marks']); }
/*
if ($row['quarterly_marks'] >=0 ) { $color_code = color_marks($row['quarterly_marks']); }
if ($row['ut3_marks'] >=0 ) { $color_code = color_marks($row['ut3_marks']); }
if ($row['half_yearly_marks'] >=0 ) { $color_code = color_marks($row['half_yearly_marks']); }
if ($row['ut4_marks'] >=0 ) { $color_code = color_marks($row['ut4_marks']); }
if ($row['annual_marks'] >=0 ) { $color_code = color_marks($row['annual_marks']); }
*/
// echo "<font color='#".$color_code."'>". $row['ut1_marks'] . "</font>";
// Ok, got the color codes - lets show the magic in the table
echo "<tr>";
echo "<td style='text-align:center;'>" . $row['student_uid'] . "</td>";
echo "<td>" . $row['student_name'] . "</td>";
echo "<td style='text-align:center;'>" . "<font color='#".$color_code."'>". $row['ut1_marks'] . "</font>"."</td>";
echo "<td style='text-align:center;'>" . "<font color='#".$color_code."'>". $row['ut2_marks'] . "</font>"."</td>";
echo "<td style='text-align:center;'>" . "<font color='#".$color_code."'>". $row['quarterly_marks'] . "</font>"."</td>";
echo "<td style='text-align:center;'>" . "<font color='#".$color_code."'>". $row['ut3_marks'] . "</font>"."</td>";
echo "<td style='text-align:center;'>" . "<font color='#".$color_code."'>". $row['half_yearly_marks'] . "</font>"."</td>";
echo "<td style='text-align:center;'>" . "<font color='#".$color_code."'>". $row['ut4_marks'] . "</font>"."</td>";
echo "<td style='text-align:center;'>" . "<font color='#".$color_code."'>". $row['annual_marks'] . "</font>"."</td>";
echo "</tr>";
}
echo "</table>";
?>
Present scenario: Every field value is taking the color-input from the function. But, the color_code value is turning out be constant.
I've been trying to crack this for the past few days, but unable to do so.
Please, if someone can give me a second thought on what I had done wrong, that would be an enormous leap.
Thanks a ton in advance.
I have table that contains information on classes like CPR, First Aid, etc...I would like to sort and display this information into a table for each class type. So all of the CPR classes would be in a table then a new table for the first aid classes, etc...
The code below currently puts each class into it's own table...I need to group them together by className if possible.
Thanks in advance for any help.
Scott
<?php
$result = mysql_query("SELECT * FROM providerClasses WHERE clientId = '$clientId' ORDER BY className");
$i = 0; // Start count for BG color
while($row = mysql_fetch_array($result)) {
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" class=\"gridTable\" width=\"975\" style=\"margin-bottom:100px;\">";
echo "<tr class=\"gridHeader\">";
echo "<td width=\"88\" class=\"grid-header-cell\">Date</td>";
echo "<td width=\"161\" class=\"grid-header-cell\">Time</td>";
echo "<td width=\"143\" class=\"grid-header-cell\">Instructor</td>";
echo "<td width=\"179\" class=\"grid-header-cell\">Location</td>";
echo "<td width=\"8\" class=\"grid-header-cell\">Price</td>";
echo "<td width=\"210\" class=\"grid-header-cell\">Class Name</td>";
echo "</tr>";
$className = "$row[className]";
$date = "$row[date]";
$time = "$row[time]";
$instructor = "$row[instructor]";
$location = "$row[location]";
$price = "$row[price]";
$comments = "$row[comments]";
$i++;
// Determine background color of row
if ( $i & 1 ) { $style = "GridRow-Even"; //even
}
else { $style = "GridRow-Odd"; //odd
}
echo "<tr class=\"$style\">";
echo "<td> $date</td>";
echo "<td> $time</td>";
echo "<td> $instructor</td>";
echo "<td> $location</td>";
echo "<td> $price</td>";
echo "<td> $className</td>";
echo "</tr>";
} // end while
echo "</table>";
?>
I am creating a PHP page where the page prints out the whole of a database I have of meat packaging. I am printing the results of the database in order of their shape (Rectangular, Oval, Square, Insert). I can happily get the database to print out the results but what I want to do for one of the columns is change the result that is printed into a HTML link.
This column is 'Imagename', it prints the name of a JPEG that is stored on the server. I want it so that when the result for 'Imagename' is printed with the JPEG on the side it isn't text but actually a link to a new tab that displays the picture for the user to view.
Here is my current PHP that loops through the database printing it in a table:
<?php
$con = mysql_connect("localhost", "horizon1", "");
mysql_select_db("horizon1_delyn", $con);
if ( ! $con)
{
die("Could not connect: " . mysql_error());
}
$rectangular = mysql_query("SELECT toolcode, description, traysize, imagename FROM range WHERE trayshape ='rectangular' ORDER BY traysize");
$oval = mysql_query("SELECT toolcode, description, traysize, imagename FROM range WHERE trayshape ='oval' ORDER BY traysize");
$square = mysql_query("SELECT toolcode, description, traysize, imagename FROM range WHERE trayshape ='square' ORDER BY traysize");
$insert = mysql_query("SELECT toolcode, description, traysize, imagename FROM range WHERE trayshape ='insert' ORDER BY traysize");
$fields_num = mysql_num_fields($rectangular);
echo "<table width='97%' border='0' cellspacing='0' cellpadding='0'><tr>";
//*RECTANGULAR*//
for ($i = 0; $i < $fields_num; $i++)
{
$field = mysql_fetch_field($rectangular);
echo "<td bgcolor='#E8CF24' style='font-family: arial;font-size: 12px;'>{$field->name}</td>";
}
echo "</tr>\n";
while ($row = mysql_fetch_row($rectangular))
{
echo "<tr>";
foreach ($row as $cell)
echo "<td style='font-family: arial;font-size:12px'>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($rectangular);
//* OVAL *//
for ($i = 0; $i < $fields_num; $i++)
{
$field = mysql_fetch_field($oval);
echo "<td bgcolor='#E8CF24' style='font-family: arial;font-size: 12px'>{$field->name}</td>";
}
echo "</tr>\n";
while ($row = mysql_fetch_row($oval))
{
echo "<tr>";
foreach ($row as $cell)
echo "<td style='font-family: arial;font-size:12px'>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($oval);
//* SQUARE *//
for ($i = 0; $i < $fields_num; $i++)
{
$field = mysql_fetch_field($square);
echo "<td bgcolor='#E8CF24' style='font-family: arial;font-size: 12px'>{$field->name}</td>";
}
echo "</tr>\n";
while ($row = mysql_fetch_row($square))
{
echo "<tr>";
foreach ($row as $cell)
echo "<td style='font-family: arial;font-size:12px'>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($square);
//* INSERT *//
for ($i = 0; $i < $fields_num; $i++)
{
$field = mysql_fetch_field($insert);
echo "<td bgcolor='#E8CF24' style='font-family: arial;font-size: 12px'>{$field->name}</td>";
}
echo "</tr>\n";
while ($row = mysql_fetch_row($insert))
{
echo "<tr>";
foreach ($row as $cell)
echo "<td style='font-family: arial;font-size:12px'>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($insert);
?>
Does anyone have any idea how I could in a sense isolate the 'Imagename' column to make the images clickable? Thanks for your help?
First of all, they are going to rip you to shreds for not escaping, but I'll let someone else tell you off for that.
At the minute you are outputting everything from the table in one go, you need to split it up, so instead of
echo "<td style='font-family: arial; font-size: 12px;'>{$cell}</td>";
You will want something like
echo '<td style="font-family: arial;font-size:12px">' . $cell['toolcode'] . '' . $cell['imagename'] . '</td>';
You need to echo the values individually, and then wrap an <a> tag around the hyperlink, with a href
I got code snippet from this site, which I used as shown below
$data = array();
while($row = mysql_fetch_assoc($num1)) {$data['row'][] = $row;}
while($row = mysql_fetch_assoc($num2)) {$data['row2'][] = $row;}
$count = count($data['row']);
echo "<table>" ;
echo "<tr>";
echo "<td width='300' bgcolor='#99CCF5' align='Left' style='padding-left:30px'><b>Country</b></td>" ;
echo "<td width='150' bgcolor='#99CCF5' align='center'><b>Mid Estimate 1</b></td>";
echo "<td width='150' bgcolor='#99CCF5' align='center'><b>Mid Estimate 2</b></td>";
echo "</tr>";
for($i=0;$i<=$count;$i++)
{
if(($i % 2) == 1)
{
echo "<tr>" ;
echo "<td align='center'>" . $data['row'][$i]['Country']."</td>";
echo "<td align='center'>" . $data['row'][$i]['MidEstimate']."</td>";
echo "<td align='center'>" . $data['row2'][$i]['MidEstimate']."</td>";
echo "</tr>" ;
}else
{
echo "<tr>" ;
echo "<td align='center'>" . $data['row'][$i]['Country'] ."</td>";
echo "<td align='center'>" . $data['row'][$i]['MidEstimate']."</td>";
echo "<td align='center'>" . $data['row2'][$i]['MidEstimate']."</td>";
echo "</tr>" ;
}
}
echo "</table>" ;
which gives a reult like below
image1 http://img4.pixa.us/8ba/19338641.jpg
where the correct result should be like this
image2 http://img4.pixa.us/c1d/19338642.jpg
that is if any value in a column is empty the next adjucent value gets that position. How can I make this correct? that is if any value is empty that column must be empty.
please help and thanks in advance.
You have to gather the data for each country. Your approach in the question messes up the listing since the keys for the array are not in sync. Let's sync your rows by 'Country':
$data = array();
while($row = mysql_fetch_assoc($num1))
{
$c = $row['Country'];
if (!isset($data[$c]))
{
$data[$c] = array('Country' => $c);
}
$data[$c]['MidEstimate1'] = $row['MidEstimate'];
}
while($row = mysql_fetch_assoc($num2))
{
$c = $row['Country'];
if (!isset($data[$c]))
{
$data[$c] = array('Country' => $c);
}
$data[$c]['MidEstimate2'] = $row['MidEstimate'];
}
Now you have a row in your array for every Country, with their data from each query.
$i = 0;
foreach ($data as $row)
{
echo ($i % 2) ? "<tr class='odd'>" : "<tr class='even'>" ;
echo "<td align='center'>" . $row['Country']."</td>";
echo "<td align='center'>" . $row['MidEstimate1']."</td>";
echo "<td align='center'>" . $row['MidEstimate2']."</td>";
echo "</tr>" ;
}
Note: this only works in 'Country' field is present in both SQL query.