So i am currently on 14 day internship and my job is to redesign a webpages, however these webapges are made so they display links to a files in a folder and once you click on these files you download them.
My question is -> there a way of how I can change the style of this page with an external CSS file ? My problem is I don't know PHP at all and don't have time to learn it, so I don't know what these files exactly do, but I know that at the botom there is HTML code being passed on the site, I tried changing the CSS file in the HTML , but it didn't change anything and this is how the page was displayed.
This is the link to the image:
https://imgur.com/skjQEk6
And this is the code that was located in the same folder as the .xls files
I am sorry for long code, I don't know how to shorten it.
<?php
//
// --- Make your customizations below. All customizations set here will apply ONLY to this indexed directory --- \\
//
//
// $HomeDir - Absolute path (not url) to TotalIndex script (usually something like: /home/user/public_html/TotalIndex/
// on Linux and something like: c:/inetpub/wwwroot/TotalIndex/ on Windows systems).
// Be sure to include the ending slash in the home directory
//
$HomeDir = "/dcweb/totalindex/";
// Include config file - DO NOT REMOVE
include $HomeDir."config.php";
// To turn off any readme file descriptions (explained in the config.php file) just uncomment the next line (This will prevent a folder description from appearing at the top of the page)...
// $Allow_Readme = 0;
// To exclude a certain file name from the index listing, just add another line of code with the name of the file that
// you want to exclude from the list.
//
// EXAMPLE - If you want to exclude a file named "hidden.txt", then add the following line below:
// $Exclude_File = "hidden.txt";
//
// You can add as many of these as you wish to exclude
// - This is case sensitive -
//
$Exclude_File[] = "exclude_me.txt";
// To exclude a certain folder name from the index listing, just add another line of code with the name of the folder that
// you want to exclude from the list.
//
// EXAMPLE - If you want to exclude a folder named "hidden_folder", then add the following line below:
// $Exclude_File = "hidden_folder";
//
// You can add as many of these as you wish to exclude
// - This is case sensitive -
//
$Exclude_Folder[] = "hidden_folder";
// To exclude a files with certain extensions from the index listing, just add another line of code with the file extension that
// you want to exclude from the list.
//
// EXAMPLE - If you want to exclude file with the extension "txt", then add the following line below:
// $Exclude_Extension = "txt";
//
// You can add as many of these as you wish to exclude
// - This is case sensitive -
//
$Exclude_Extension[] = "hide_me";
//
// ***----- Do not change below this line -----*** \\
//
// include functions
include $HomeDir."functions.php";
//Path to themes folder with ending slash
$ThemeURL = $HomeURL."themes/";
// Path to icon folder with ending slash
$iconfolder = $HomeURL."icons/";
$_GLOBAL['image'] = "";
$fdir=$_GET["fdir"];
$NumSort=$_GET["NumSort"];
$SortBy=$_GET["SortBy"];
// Open folder directory
if(!isset($fdir))
{
$fdir = "./";
}
$fdir = str_replace("../", "", $fdir);
// check to see if still inside directory boundry
$check = substr($fdir, 0, 2);
if($check != "./") {
$fdir = "./";
}
// setup file properties class
class File_Properties
{
var $file_name;
// just the file name
var $file_ext;
// file extension
var $file_size;
// size of file
var $file_date;
// date modified
var $file_icon;
// icon for file type
var $file_type;
// short description for file type
// constructor method - build object
function Build($file)
{
$this->setFname($file);
$this->setFext($file);
$this->setFsize($file);
$this->setFdate($file);
$this->setFicon_type();
}
// Set file name
function setFname($file)
{
$this->file_name = basename($file);
}
// set file extension
function setFext($file)
{
$this->file_ext = array_pop(explode('.', $file));
}
// set file size
function setFsize($file)
{
$kbs = filesize($file);
$units = array(' B', ' KB', ' MB', ' GB', ' TB');
for ($i = 0; $kbs > 1024; $i++) { $kbs /= 1024; }
$this->file_size = ((int)($kbs)).$units[$i];
}
// set date modified
function setFdate($file)
{
date_default_timezone_set('Europe/Prague');
$modified = filemtime($file);
$this->file_date = date("d-M-Y H:i", $modified);
}
// set file type
function setFicon_type()
{
list($this->file_type, $this->file_icon) = split("\?", GetExt($this->file_ext), 2);
}
// setup all get/return methods for class vars
function getFname()
{
return $this->file_name;
}
function getFext()
{
return $this->file_ext;
}
function getFsize()
{
return $this->file_size;
}
function getFdate()
{
return $this->file_date;
}
function getFicon()
{
return $this->file_icon;
}
function getFtype()
{
return $this->file_type;
}
}
// setup folder properties class
class Folder_Properties
{
var $dir_name; // just the directory name
var $dir_date; // date modified
var $dir_icon = "folder.gif"; // icon for directory
var $dir_type = "File Folder"; // short description for file type
// constructor method - build object
function Build($dir)
{
$this->setFname($dir);
$this->setFdate($dir);
}
// Set file name
function setFname($dir)
{
$this->dir_name = basename($dir);
}
// set date modified
function setFdate($dir)
{
$modified = filemtime($dir);
$this->dir_date = date("d-M-Y H:i", $modified);
}
// setup all get/return methods for class vars
function getFname()
{
return $this->dir_name;
}
function getFdate()
{
return $this->dir_date;
}
function getFicon()
{
return $this->dir_icon;
}
function getFtype()
{
return $this->dir_type;
}
}
// initialize file and folder arrays
$file_array = array();
$dir_array = array();
$Fname_array = array();
$Dname_array = array();
// open directory
$dir = opendir($fdir);
// Read files into array
while(false !== ($file = readdir($dir)))
{
if($file != "." && $file != "..")
{
$type = filetype($fdir.$file);
$info = pathinfo($file);
if($type != "dir")
{
if(isset($info["extension"]))
{
$file_extension = $info["extension"];
}
}
if($type == "dir" && !in_array($file, $Exclude_Folder))
{
// setup folder object
$This_Dir = new Folder_Properties;
$This_Dir->Build($fdir.$file);
$dir_array[] = $This_Dir;
}
elseif($type == "file" && !in_array($file, $Exclude_File) && !in_array($file_extension, $Exclude_Extension))
{
// setup file object
$This_File = new File_Properties;
$This_File->Build($fdir.$file);
$file_array[] = $This_File;
}
}
}
closedir($dir);
// Set default sort by method
if(!isset($SortBy) || $SortBy != 0 && $SortBy != 1) {
$SortBy = 0;
}
// Number of the column to sort by (0-3) set default to 0
if(!isset($NumSort) || $NumSort != 0 && $NumSort != 1 && $NumSort != 2 && $NumSort != 3) {
$NumSort = 0;
}
// determin object sorting methods
switch($NumSort)
{
case 0;
$Fsort_method = "file_name";
$Dsort_method = "dir_name";
break;
case 1;
$Fsort_method = "file_size";
$Dsort_method = "dir_name";
break;
case 2;
$Fsort_method = "file_type";
$Dsort_method = "dir_name";
break;
case 3;
$Fsort_method = "file_date";
$Dsort_method = "dir_date";
break;
default:
$Fsort_method = "file_name";
$Dsort_method = "dir_name";
}
// object sorting functions
function ASC_sort_file_objects($a, $b)
{
global $Fsort_method;
$obj1 = strtolower($a->$Fsort_method);
$obj2 = strtolower($b->$Fsort_method);
if ($obj1 == $obj2) return 0;
return ($obj1 < $obj2) ? -1 : 1;
}
function ASC_sort_dir_objects($a, $b)
{
global $Dsort_method;
$obj1 = strtolower($a->$Dsort_method);
$obj2 = strtolower($b->$Dsort_method);
if ($obj1 == $obj2) return 0;
return ($obj1 < $obj2) ? -1 : 1;
}
function DESC_sort_file_objects($a, $b)
{
global $Fsort_method;
$obj1 = strtolower($a->$Fsort_method);
$obj2 = strtolower($b->$Fsort_method);
if ($obj1 == $obj2) return 0;
return ($obj1 > $obj2) ? -1 : 1;
}
function DESC_sort_dir_objects($a, $b)
{
global $Dsort_method;
$obj1 = strtolower($a->$Dsort_method);
$obj2 = strtolower($b->$Dsort_method);
if ($obj1 == $obj2) return 0;
return ($obj1 > $obj2) ? -1 : 1;
}
// sort ascending
if($SortBy == 0) {
// sort arrays (ASCENDING)
usort($file_array, 'ASC_sort_file_objects');
usort($dir_array, 'ASC_sort_dir_objects');
$arrow = "▲";
$SortBy = 1;
}
// sort descending
else {
// sort arrays (DESCENDING)
usort($file_array, 'DESC_sort_file_objects');
usort($dir_array, 'DESC_sort_dir_objects');
$arrow = "▼";
$SortBy = 0;
}
echo "<html>
<head>
<link rel=\"stylesheet\" type=\"text/css\" href=\"".$ThemeURL.$ThemeFolder."style.css\">
</head>
<body>
<table width=\"100%\" height=\"5%\" cellspacing=\"0\" cellpadding=\"5\">
<tr>
<td class=\"Horni\">
<div align=\"center\"><img src=\"/stranky/dc.GIF\" alt=\"dc\" width=\"330\" height=\"50\" border=\"0\"></div>
</td>
</TR>
</TABLE>
<table class='tbl01'>
";
echo "
<tr>
<td class='td01' valign='top'>
<div align='left'>
<table width='100%'>
<tr>
<td class='td02'> </td>
<td class='td03' width='43%' align='left'> <a href='index.php?NumSort=0&SortBy=$SortBy&fdir=$fdir' class='link01'>Name $arrow</a></td>
<td class='td04'> </td>
<td class='td02'> </td>
<td class='td03' width='13%' align='right'><a href='index.php?NumSort=1&SortBy=$SortBy&fdir=$fdir' class='link01'>Size</a></td>
<td class='td04'> </td>
<td class='td02'> </td>
<td class='td03' width='14%' align='left'><a href='index.php?NumSort=2&SortBy=$SortBy&fdir=$fdir' class='link01'>Type</a></td>
<td class='td04'> </td>
<td class='td02'> </td>
<td class='td03' width='18%' align='right'><a href='index.php?NumSort=3&SortBy=$SortBy&fdir=$fdir' class='link01'>Date Modified</a></td>
<td class='td04'> </td>
<td width='20%'> </td>
</tr>
";
// directory is not the base dir
if($fdir != "./") {
// Make every other row a color
$othernum = 1;
// Get folder one level up
$UpPath = dirname($fdir)."/";
echo "
<tr>
<td class='td05'> </td>
<td class='td06' width='43%' align='left'><a href='index.php?fdir=$UpPath' class='link01'><img src='".$iconfolder."levelup.gif' border='0'> Up One Level</a></td>
<td class='td07'> </td>
<td class='td05'> </td>
<td class='td06' width='13%'> </td>
<td class='td07'> </td>
<td class='td05'> </td>
<td class='td06' width='14%'> </td>
<td class='td07'> </td>
<td class='td05'> </td>
<td class='td06' width='18%'> </td>
<td class='td07'> </td>
<td width='20%'> </td>
</tr>";
}
else {
$othernum = 0;
}
// alternate row counter
$count = 0;
// Output folder information
for($y = 0; $y < count($dir_array); $y++)
{
// alternate row colors
if($count % 2 != $othernum) {
$special = "bgcolor='$RowColor'";
}
else {
$special = "";
}
$count++;
echo "
<tr>
<td class='td05' $special> </td>
<td class='td06' $special width='43%' align='left'><a href=\"index.php?SortBy=".$SortBy."&fdir=".$fdir.$dir_array[$y]->getFname()."/\" class=\"link01\"><img src=\"".$iconfolder.$dir_array[$y]->getFicon()."\" border=\"0\"> ".$dir_array[$y]->getFname()."</td>
<td class='td07' $special> </td>
<td class='td05' $special> </td>
<td class='td06' $special width='13%' align='right'> </td>
<td class='td07' $special> </td>
<td class='td05' $special> </td>
<td class='td06' $special width='14%' align='left'>".$dir_array[$y]->getFtype()."</td>
<td class='td07' $special> </td>
<td class='td05' $special> </td>
<td class='td06' $special width='18%' align='right'>".$dir_array[$y]->getFdate()."</td>
<td class='td07' $special> </td>
<td width='20%' $special> </td>
</tr>
";
}
// output file info
for($y = 0; $y < count($file_array); $y++)
//while (list($key, $val) = each($Fname_array))
{
// alternate row colors
if($count % 2 != 0) {
$special = "bgcolor='$RowColor'";
}
else {
$special = "";
}
$count++;
echo "
<tr>
<td class='td05' $special> </td>
<td class='td06' $special width='43%' align='left'><a href=\"".$fdir.$file_array[$y]->getFname()."\" class=\"link01\" target=\"_blank\"><img src=\"".$iconfolder.$file_array[$y]->getFicon()."\" border=\"0\"> ".$file_array[$y]->getFname()."</td>
<td class='td07' $special> </td>
<td class='td05' $special> </td>
<td class='td06' $special width='13%' align='right'>".$file_array[$y]->getFsize()."</td>
<td class='td07' $special> </td>
<td class='td05' $special> </td>
<td class='td06' $special width='14%' align='left'>".$file_array[$y]->getFtype()."</td>
<td class='td07' $special> </td>
<td class='td05' $special> </td>
<td class='td06' $special width='18%' align='right'>".$file_array[$y]->getFdate()."</td>
<td class='td07' $special> </td>
<td width='20%' $special> </td>
</tr>
";
}
echo "
</table>
</div>
</td>
</tr>
<tr>
<td width='100%'> </td>
</tr>
<tr>
<td class=\"td01\" valin=\"bottom\" align=\"center\">
<p class=\"txt02\"> Systém datového centra vyvíjí a spravuje IS.</p> </td>
</tr>
<tr>
<td class=\"td01\" valin=\"bottom\" align=\"center\"> <p class=\"txt02\"> Kontakt: Ing. Jaromír Mikulka, jaromir.mikulka#unex.cz, tel. 2526</p> </td>
</tr>
<tr>
<td class=\"td01\" valin=\"bottom\" align=\"center\"><p class=\"txt02\">Powered By: <b>TotalIndex</b></p></td>
</tr>
</table>
</body>
</html>
";
?>```
[1]: https://i.stack.imgur.com/BXm4n.png
You use double quote(") inside double quote
You must have to use single quote(') inside double quote(")
So your code should be...
....................................
....................................
echo "<html>
<head>
<link rel='stylesheet' type='text/css' href='../your-directory/style.css'>
</head>
....................................
....................................
You can also include external css file in php file
<style>
<?php include 'CSS/main.css'; ?>
</style>
Related
I have code, which take information from xml file(in xml have example 5 blocks "groupRecord", can be more ). And i want show per page 4 blocks. I already wrote this part.
$xmlDoc = new DOMDocument();
$xmlDoc->load('GetLoyalty5001.xml');
$totaldata = $xmlDoc->getElementsByTagName("groupRecord")->length;
$Pages = intval($_GET['page']);
if(!isset($Pages) || $Pages==0)
{
$Pages=1;
}
$DataPerPage=4;
$numPages = ceil($totaldata/$DataPerPage);
$shopingdata = $xmlDoc->getElementsByTagName("groupRecord");
foreach($shopingdata as $key=>$datashoping)
{
if(??)
{
?>
<tr>
<td width="156">STORE ADDRESS</td>
<td width="222">STORE ADDRESS</td>
<td width="266">STORE ADDRESS</td>
<td width="161">STORE ADDRESS</td>
<td width="156">STORE ADDRESS</td>
</tr>
<?php
}
}
?>
What must I put in place of question mark in condition?
Well, you have everything you need already, just use $numPages which yields the number of pages you have.
for ($a = 1; $a <= $numPages; $a++) {
echo '' . $a . '';
}
You were close, but the idea of how to calculate the number of items in the list seemed to go wrong. All you needed to do was use the number of elements that you fetched using $xmlDoc->getElementsByTagName("groupRecord"). I've reduced the code and this should do what your after...
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($xml);
$shopingdata = $xmlDoc->getElementsByTagName("groupRecord");
$perPage = 4;
$currentPage = intval($_GET['page']);
$numPages = ceil($shopingdata->length / $perPage);
if(!$currentPage || $currentPage > $numPages)
{
$currentPage = 0;
}
$start = $currentPage * $perPage;
$end = ($currentPage * $perPage) + $perPage;
foreach($shopingdata as $key=>$datashoping)
{
if($key >= $start && $key < $end)
{
?>
<tr>
<td width="156">STORE ADDRESS</td>
<td width="222">STORE ADDRESS</td>
<td width="266">STORE ADDRESS</td>
<td width="161">STORE ADDRESS</td>
<td width="156">STORE ADDRESS</td>
</tr>
<?php
}
}
for($a=1;$a<=$numPages;$a++)
{
echo ''.$a.'';
}
I'm trying to fill a table with the result from a certain SQL query, but I dont know why it doesnt work, heres my code:
<?
if(!ceklogin()){
header("Location:index.php");
}
?><?
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>MSystem</title>
<link rel=stylesheet type="text/css" href="style.css">
<LINK href="gaya.css" type=text/css rel=stylesheet>
</head>
<?
//$cfgProgDir = 'phpSecurePages/phpSecurePages/';
//include($cfgProgDir . "secure.php");
include_once("top4.htm");
include_once("conn.php");
$datenow = getdate();
?>
<script type="text/javascript" src="js/calendarDateInput.js">
</script>
<body class="bg">
<table align="center">
<tr>
<td><p align="center"><strong><font color="#000000" size="2">TITLE</font></strong></p></td>
</tr>
<tr>
<td><p align="center"><strong><font color="#000000" size="3"> SMALL TITLE</font></strong></p></td>
</tr>
<tr>
<td><p align="center"><strong><font color="#000000" size="2">Date: <? echo $v_date ?></font></strong></p></td>
</tr>
<tr>
<td><p align=center><strong><font color=#000000 size=2>SMALLER TITLE</font></strong></p></td>
</tr>
<tr>
<td><img src="img/batas.jpg" width="750" height="1" ></td>
</tr>
</table>
<br>
<table class=table width="750" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor=black bgcolor="#DDDDDD" BORDER-COLLAPSE"collapse">
////////// THIS IS THE TABLE
<tr>
<td bgcolor=#444444 align=center><font color=white>Date</font></td>
<td bgcolor=#444444 align=center><font color=white>Type</font></td>
<td bgcolor=#444444 align=center><font color=white>Sender</font></td>
<td bgcolor=#444444 align=center><font color=white>Description</font></td>
<td bgcolor=#444444 align=center><font color=white>Credit</font></td>
<td bgcolor=#444444 align=center><font color=white>Quantity</font></td>
<td bgcolor=#444444 align=center><font color=white>Price</font></td>
</tr>
<?
$blnto = substr($v_date,3,3);
switch($blnto)
{
case 'JAN': {$blntov = '01'; break;}
case 'FEB': {$blntov = '02'; break;}
case 'MAR': {$blntov = '03'; break;}
case 'APR': {$blntov = '04'; break;}
case 'MAY': {$blntov = '05'; break;}
case 'JUN': {$blntov = '06'; break;}
case 'JUL': {$blntov = '07'; break;}
case 'AUG': {$blntov = '08'; break;}
case 'SEP': {$blntov = '09'; break;}
case 'OCT': {$blntov = '10'; break;}
case 'NOV': {$blntov = '11'; break;}
case 'DEC': {$blntov = '12'; break;}
}
$tglto = substr($v_date,0,2);
$thnto = substr($v_date,7,4);
//////////// HERES THE QUERY
$MyQuery = "
select date, type, sender, description, credit, quantity, change
from harjunadip.REPORTENABLEREGAE
WHERE date = '".$thnto."-".$blntov."-".$tglto."'
//test with: WHERE date = '2015-10-05'
order by description
";
//echo $MyQuery;
$curs=ora_open($conn);
ora_parse($curs,$MyQuery, 0);
ora_exec($curs);
$i=1;
$tot_qty_p = 0;
$tot_sal_p = 0;
$tot_qty_v = 0;
$tot_sal_v = 0;
while(ora_fetch($curs) == 1) // WHILE THERE IS A ROW
{
$bgcolor = "";
if ($i % 2 != 1) $bgcolor = "bgcolor=#FFFFCC";
///////// THIS IS THE SUPPOSED TABLE CONTENTS
$content = "
<tr ".$bgcolor.">
<td align=\"center\">".ora_getcolumn($curs,0)."</td>
<td align=\"right\">".ora_getcolumn($curs,1)."</td>
<td align=\"right\">".ora_getcolumn($curs,2)."</td>
<td align=\"right\">".ora_getcolumn($curs,3)."</td>
<td align=\"right\">".number_format(ora_getcolumn($curs,4))."</td>
<td align=\"right\">".number_format(ora_getcolumn($curs,5))."</td>
<td align=\"right\">".number_format(ora_getcolumn($curs,6),2,'.',',')."</td>
</tr>
";
$tot_qty = $tot_qty + ora_getcolumn($curs,5);
$tot_price = $tot_price + ora_getcolumn($curs,6);;
echo $content;
$i++;
}
ora_close($curs);
?>
<tr bgcolor="#444444">
<td align="right" colspan="5"><font color="#FFFFFF">Total :</font></td>
<td align="right"><font color="#FFFFFF"><? echo number_format($tot_qty) ?></font></td>
<td align="right"><font color="#FFFFFF"><? echo number_format($tot_price,2,'.',',') ?></font></td>
</tr>
</table>
</body>
</html>
Things to consider:
The query works, Ive tried the query by replacing '".$thnto."-".$blntov."-".$tglto."' with '2015-10-05' and it gives me the result.
The table appears but only the headers (DATE, TYPE, SENDER, etc)
The connection to the database also works, so its not a connection problem
I'm using adobe.inc.php with oci8 connection if that matters
I just cant seem to put the result on the said table. Ive tried echoing some random stuff like this:
select date, type, sender, description, credit, quantity, change
from harjunadip.REPORTENABLEREGAE
WHERE date = '".$thnto."-".$blntov."-".$tglto."'
//test with: WHERE date = '2015-10-05'
order by description
";
echo 'test1';
$curs=ora_open($conn);
ora_parse($curs,$MyQuery, 0);
echo 'test2';
ora_exec($curs);
echo 'test3';
$i=1;
$tot_qty_p = 0;
$tot_sal_p = 0;
$tot_qty_v = 0;
$tot_sal_v = 0;
while(ora_fetch($curs) == 1) // WHILE THERE IS A ROW
echo 'test4';
{
$bgcolor = "";
if ($i % 2 != 1) $bgcolor = "bgcolor=#FFFFCC";
But only the 'test1' appeared, the others didnt.
Kindly help please, I'm lost, thanks in advance.
I am working on a function which selects a list of dates, and highlight the next event. I have managed to highlight all future events, however I would like to only highlight the nearest future event. How can this be done?
<?php
function racesbydate($sql) {
include 'connect.php';
$year = $_GET['year'];
$get = $year.'%';
$select = $conn->prepare($sql);
$select->bind_param('s', $get);
$select->execute();
$select->store_result();
if ($select->num_rows > 0) {
echo "<div class='races' id='$year' style='display:block'>
<table>\n<th colspan='5'>Cycling Season $year </th>\n
<tr id='information'>\n
<th id='date'>Date</th>\n
<th id='race'>Race</th>\n
<th id='route'>Route</th>\n
<th id='info'>Entry</th>\n
<th id='rizultz'>Results</th>";
$meta = $select->result_metadata();
while ($field = $meta->fetch_field()) {
$params[] = &$row[$field->name];
}
call_user_func_array(array($select, 'bind_result'), $params);
while ($select->fetch()) {
$today = date("Y-m-d");
$date = new DateTime($row['date']);
$formatted_date = $date->format('d/m/Y');
if ($row['date'] > $today) {
if ($row['infoID'] != "0") {
echo "<tr class='racedetails' id='nextrace' >\n
<td class='dark' id='date'>".$formatted_date."</td>\n
<td class='light' id='race'>".$row["title"]."</td>\n
<td class='dark' id='route'>".$row["route"]."</td>\n
<td class='light' id='info'><a href='".$row["infoID"]."'>Info</a></td>\n
<td class='dark' id='rizults'>N/A</td>\n</tr>\n";
}
} else {
if (($row['infoID'] != "0") && ($row['resultID'] !="0" )) {
echo "<tr class='racedetails' id='race' >\n
<td class='dark' id='date'>".$formatted_date."</td>\n
<td class='light' id='race'>".$row["title"]."</td>\n
<td class='dark' id='route'>".$row["route"]."</td>\n
<td class='light' id='info'><a href='".$row["infoID"]."'>Info</a></td>\n
<td class='dark' id='rizults'><a href='".$row["resultID"]."'>Results</a></td>\n</tr>\n";
}
}
}
}
echo "</table>\n</div>";
$select->close();
}
current result
<tr class='racedetails' id='nextrace' ><td class='dark' id='date'>06/01/2016</td></tr>
<tr class='racedetails' id='nextrace' ><td class='dark' id='date'>08/02/2016</td></tr>
goal results
<tr class='racedetails' id='nextrace' ><td class='dark' id='date'>06/01/2016</td></tr>
<tr class='racedetails' id='race' ><td class='dark' id='date'>08/02/2016</td></tr>
If I understood you correctly, you only need a flag to store the information whether the next race has already been seen or not:
:
call_user_func_array(array($select, 'bind_result'), $params);
$nextRace = true;
while ($select->fetch()) {
$today = date("Y-m-d");
$date = new DateTime($row['date']);
$formatted_date = $date->format('d/m/Y');
if ($row['date'] > $today) {
if ($row['infoID'] != "0") {
$cssId = $nextRace ? 'nextrace' : 'race';
$nextRace = false;
echo "<tr class='racedetails' id='".$cssId."' >\n
<td class='dark' id='date'>".$formatted_date."</td>\n
<td class='light' id='race'>".$row["title"]."</td>\n
<td class='dark' id='route'>".$row["route"]."</td>\n
<td class='light' id='info'><a href='".$row["infoID"]."'>Info</a></td>\n
<td class='dark' id='rizults'>N/A</td>\n</tr>\n";
}
} else {
:
This assumes that the order of the races is ascending by date (which your examples suggest).
I am trying to get information from my database and display it. Here is a screenshot of what the page looks like:
The page loads really slow
Is there any way to make it load and display the data faster?
Here is the code.
<table align="center" class="pTable">
<tr class="main"> <th class="pTableHeader"> ID </th> <th class="pTableHeader"> Room </th> <th class="pTableHeader"> Status</th> </tr>
<?php
gc_enable();
gc_collect_cycles();
flush();
$this->mysql = new sqli('HIDDEN','HIDDEN','HIDDEN','HIDDEN');
$bots = $this->mysql->fetch_array("SELECT `pid`,`room`,`id` from `bots`;");
foreach ($bots as $b) {
if(is_numeric($b["room"])) {
$xat = file_get_contents('http://www.xat.com/xat'.trim($b["room"]));
$name = sp($xat, '<h1> ', '</h1>');
}
else $name = $b['room'];
//$b["pid"] = isset($b["pid"])?$b["pid"]:false;
//$online = \"start.php {$b['id']} {$b['id']}\"", $output) && count($output) > 1 ? true : false;
$online = file_exists("/proc/{$b['pid']}" )?true:false;
if($online === true) $status = "<font color='green'>Online</font> <div style='float:right'><img src='http://fexbots.com/Images/Pawns/online.png'> <a href='/botinfo?botid={$b["id"]}'>More info</a></div>";
else $status = "<font color='red'>Offline</font> <div style='float:right'><img src='http://fexbots.com/Images/Pawns/offline.png'> <a href='/botinfo?botid={$b["id"]}'>More info</a></div>";
if($b["room"] === '') {
$name = "No Room";
$status = "<font color='red'>Not Setup!</font> <div style='float:right'><img src='http://fexbots.com/Images/Pawns/hang.png'> <a href='/botinfo?botid={$b["id"]}'>More info</a></div>";
echo '<tr> <td> '.$b["id"].' </td> <td> No Room <td> '.$status.'</td> </tr>';
}
else echo "<tr> <td> ".$b['id']." </td> <td> <a href='http://www.xat.com/$name'>$name</a> <td> ".$status."</td> </tr>";
}
function sp($content, $start, $end, $lower=false) {
if($lower!=false) {
$content = strtolower($content);
$start = strtolower($start);
$end = strtolower($end);
}
$content = substr($content, strpos($content,$start)+strlen($start));
$content = substr($content, 0, strpos($content,$end));
return $content;
}
?>
</table>
You seem to download the content from an URL inside the loop. Maybe that is the cause to why it is slow and not the mysql query itself.
Try to write out some timestamps or comment some code out to see what is causing it to be slow.
What I would like to do is number each row in my table. I can't manually number the table myself, as all of the info in it is retrieved from a database. Is this possible with jQuery or PHP? Here's a screen shot of the table:
I tried searching for this, and did not find anything that helped me.
Here is the PHP / HTML that is displaying the table:
<tr>
<th>Name</th>
<th>Email</th>
<th>Subject</th>
<th>Created on</th>
<th style="width:65px;">Status</th>
<th>Actions</th>
</tr>
<?php
[...]
//Display the results
while($info = mysql_fetch_assoc($result)){
//data
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
//status
if($isActive == "1") {
$status = "<span class=\"open\">Open</span>";
$status2 = "active";
}
else if($isActive == "0") {
$status = "<span class=\"closed\">Closed</span>";
$status2 = "closed";
}
else {
$status = "";
}
echo "
<tr>
<td style=\"min-width: 87px;\">$name</td>
<td style=\"min-width:248px;\" title=\"$email\">".addEllipsis($email, 33)."</td>
<td title=\"$subject\">".addEllipsis($subject, 18)."</td>
<td style=\"width: 235px;\">$created</td>
<td title=\"This ticket is $status2\">$status</td>
<td><a href='/employee/employee.php?ticket=$ticketid'>View Ticket »</a></td>
</tr>
";
}
As you can see, it's displayed with a while loop.
If anyone knows a way to number each line in my table with jQuery or PHP, please help me :)
$trCounter=0;
while($info = mysql_fetch_assoc($result)){
//data
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
//status
if($isActive == "1") {
$status = "<span class=\"open\">Open</span>";
$status2 = "active";
}
else if($isActive == "0") {
$status = "<span class=\"closed\">Closed</span>";
$status2 = "closed";
}
else {
$status = "";
}
echo "
<tr>
<td>$trCounter++</td>
<td style=\"min-width: 87px;\">$name</td>
<td style=\"min-width:248px;\" title=\"$email\">".addEllipsis($email, 33)."</td>
<td title=\"$subject\">".addEllipsis($subject, 18)."</td>
<td style=\"width: 235px;\">$created</td>
<td title=\"This ticket is $status2\">$status</td>
<td><a href='/employee/employee.php?ticket=$ticketid'>View Ticket »</a></td>
</tr>
";
}
or you could always use the :eq api in your jquery selector or its equivalent to work with the index but like I asked it depends on what you want to do with the index.
I would go with PHP solution listed by Atul Gupta.
To add more - you also can to start iteration based on which page you are.
<?php
$i = ($page-1) * $itemsPerPage;
while(....)
{
echo $i;
$i++;
}
?>
if you are on the second page of your list would get something like 11,12,13,14,....
jQuery:
$(function () {
var i = 0;
$('table thead tr').prepend('<th>#</th>');
$('table tbody tr').each(function () {
i += 1;
$(this).prepend('<td>' + i + '</td>');
});
});
PHP
<tr>
<th>Sr. No</th> // Add header for counter
<th>Name</th>
...
</tr>
...
$i=1; // add counter -----------corrected-------------
while($info = mysql_fetch_assoc($result)){
//data
...
echo "
<tr>
<td>$i</td> // include counter to table
<td style=\"min-width: 87px;\">$name</td>
...
</tr>
";
$i++; // increment counter
}
Set an auto increment property in the SQL table, which can be used as an index, and will increase automatically when a new entry is added?