PHP - Results Are Sorted By Directory Name And Not Date
I am trying create a webpage that will automatically display new agendas as I add them to the server. I do this right now but I have to put the agendas in the agendas and the board folders. I want to simplify this by only putting the agendas in the board folder. My code kinda works but the results aren't sorted correctly. My code scans the current directory for the list of current boards. The arrary_diff removes the boards that are no longer active. It then appends the current year to the folder information. Next I glob all of the Agendas in the various directories and then I sort the resulting glob. Finally I print the results which are out of date order. I tried sort(basename($agendas)) but that is not valid syntax for sort. Then I was thinking of a 2 dimension array, the first element is the filename, the second element is the fullpath. Then I sort on the first element but I haven't figured out how to get that to work. So I went back to my first code and I am asking what did I do wrong? Am I on the right track to do what I want? The directory structure is like this: Array ( [0] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/01-17-2021_Board_of_Zoning_Appeals_Agenda.pdf [1] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/02-24-2021_Board_of_Zoning_Appeals_Agenda.pdf [2] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/03-17-2021_Board_of_Zoning_Appeals_Agenda.pdf [3] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/04-21-2021_Board_of_Zoning_Appeals_Agenda.pdf [4] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/01-24-2021_EDC_Agenda.pdf [5] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/02-21-2021_EDC_Agenda.pdf [6] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/03-21-2021_EDC_Agenda.pdf [7] => ./meeting-minutes-agendas/Park_Board/2021/01-21-2021_Park_Board_Agenda.pdf [8] => ./meeting-minutes-agendas/Park_Board/2021/02-18-2021_Park_Board_Agenda.pdf [9] => ./meeting-minutes-agendas/Park_Board/2021/03-18-2021_Park_Board_Agenda.pdf [10] => ./meeting-minutes-agendas/Park_Board/2021/03-27-2021_Park_Board_Agenda.pdf [11] => ./meeting-minutes-agendas/Park_Board/2021/04-22-2021_Park_Board_Agenda.pdf [12] => ./meeting-minutes-agendas/Plan_Commission/2021/01-07-2021_Plan_Commission_Agenda.pdf [13] => ./meeting-minutes-agendas/Plan_Commission/2021/01-21-2021_Plan_Commission_Agenda.pdf [14] => ./meeting-minutes-agendas/Plan_Commission/2021/02-04-2021_Plan_Commission_Agenda.pdf [15] => ./meeting-minutes-agendas/Plan_Commission/2021/02-18-2021_Plan_Commission_Agenda.pdf [16] => ./meeting-minutes-agendas/Plan_Commission/2021/03-04-2021_Plan_Commission_Agenda.pdf [17] => ./meeting-minutes-agendas/Plan_Commission/2021/03-18-2021_Plan_Commission_Agenda.pdf [18] => ./meeting-minutes-agendas/Plan_Commission/2021/04-08-2021_Plan_Commission_Agenda.pdf [19] => ./meeting-minutes-agendas/Plan_Commission/2021/04-22-2021_Plan_Commission_Agenda.pdf [20] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/01-17-2021_RDC_Agenda.pdf [21] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/02-14-2021_RDC_Agenda.pdf [22] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/03-14-2021_RDC_Agenda.pdf [23] => ./meeting-minutes-agendas/Safety_Board/2021/01-08-2021_Safety_Board_Agenda.pdf [24] => ./meeting-minutes-agendas/Safety_Board/2021/02-16-2021_Safety_Board_Agenda.pdf [25] => ./meeting-minutes-agendas/Safety_Board/2021/03-16-2021_Safety_Board_Agenda.pdf [26] => ./meeting-minutes-agendas/Safety_Board/2021/04-22-2021_Safety_Board_Agenda.pdf [27] => ./meeting-minutes-agendas/Sanitary_District/2021/01-19-2021_Sanitary_District_Agenda.pdf [28] => ./meeting-minutes-agendas/Sanitary_District/2021/02-16-2021_Sanitary_District_Agenda.pdf [29] => ./meeting-minutes-agendas/Sanitary_District/2021/03-16-2021_Sanitary_District_Agenda.pdf [30] => ./meeting-minutes-agendas/Sanitary_District/2021/03-23-2021_Sanitary_District_Agenda.pdf [31] => ./meeting-minutes-agendas/Sanitary_District/2021/03-31-2021_Sanitary_District_Agenda.pdf [32] => ./meeting-minutes-agendas/Sanitary_District/2021/04-20-2021_Sanitary_District_Agenda.pdf [33] => ./meeting-minutes-agendas/Town_Council/2021/01-13-2021_Town_Council_Agenda.pdf [34] => ./meeting-minutes-agendas/Town_Council/2021/01-27-2021_Town_Council_Agenda.pdf [35] => ./meeting-minutes-agendas/Town_Council/2021/02-02-2021_Town_Council_Agenda.pdf [36] => ./meeting-minutes-agendas/Town_Council/2021/02-24-2021_Town_Council_Agenda.pdf [37] => ./meeting-minutes-agendas/Town_Council/2021/03-03-2021_Town_Council_Agenda.pdf [38] => ./meeting-minutes-agendas/Town_Council/2021/03-24-2021_Town_Council_Agenda.pdf [39] => ./meeting-minutes-agendas/Town_Council/2021/04-14-2021_Town_Council_Special_Meeting_Agenda.pdf [40] => ./meeting-minutes-agendas/Town_Council/2021/04-14-2021_Town_Council_Study_Session_Agenda.pdf [41] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-07-2021_Waterwork_Board_Agenda.pdf [42] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-19-2021_Waterworks_Board_Agenda.pdf [43] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-28-2021_Waterworks_Board_Agenda.pdf [44] => ./meeting-minutes-agendas/Waterworks_Board/2021/02-16-2021_Waterworks_Board_Agenda.pdf [45] => ./meeting-minutes-agendas/Waterworks_Board/2021/03-16-2021_Waterworks_Board_Agenda.pdf [46] => ./meeting-minutes-agendas/Waterworks_Board/2021/04-20-2021_Waterworks_Board_Agenda.pdf ) What I get is
04-21-2021_Board_of_Zoning_Appeals_Agenda.pdf when it should be:
04-20-2021_Sanitary_District_Agenda.pdf <?php $files = array_diff(scandir('./meeting-minutes-agendas'), array('..', '.', 'Default.php', 'Agendas', 'Police_Commission', 'Utility_Board')); sort($files); foreach($files as &$file) { $file = $file . "/" . date("Y"); } unset($file); $agendas = array(); foreach($files as $file) { $temp = glob('./meeting-minutes-agendas/'. $file . "/*Agenda.pdf"); $agendas = array_merge($agendas, $temp); } unset($files); unset($temp); sort($file); foreach($agendas as $file) { $filedate = str_replace('-', '/',substr(basename($file),0,10)); if (strtotime($filedate) >= strtotime(date('m/d/Y'))) { echo "<a href='"; echo $file; echo "'>"; $file = str_replace('.php', '', $file); echo basename($file); echo "</a><br>\n"; } } unset($file); ?>
Similar TutorialsHello, I have a msql table that has data input every hour of every day, so each date is entered 24 times next to the hour field as seen below the PHP... How do I get the information between a daterange that comes from the datepickers (start and end date) to show values of Power, Volt, and current for each day and hour in a report ? Here is what I have written, but I think the time, or multiple of same dates is stopping it from working... <?php if(isset($_POST['start1']) && isset($_POST['end1'])){ $start = (isset($_POST['start1'])) ? date("Y-m-d",strtotime($_POST['start1'])) : date("Y-m-d"); $end = (isset($_POST['end1'])) ? date("Y-m-d",strtotime($_POST['end1'])) : date("Y-m-d"); $con = mysql_connect('xxxxxx', 'xxxxxx', 'xxxxxxxxxx'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT * FROM report WHERE date BETWEEN '$start' AND '$end'"; echo "<table border='1'> <tr> <th>Date</th> <th>Hour</th> <th>Power</th> <th>Volt</th> <th>Current</th> </tr>"; $res = mysql_query($sql) or die(__LINE__.' '.$sql.' '.mysql_error()); while($row = mysql_fetch_array($res)){ echo "<tr>"; echo "<td>" . $row['Date'] . "</td>"; echo "<td>" . $row['Time'] . "</td>"; echo "<td>" . $row['Power'] . "</td>"; echo "<td>" . $row['Volt'] . "</td>"; echo "<td>" . $row['Current'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); } ?> The DATE is a DATE, the TIME is TIME, the power,volt, current are FLOAT unit ID | Date | Time | Power | Volts | Current | 1 10/15/2010 21:00:00 0 220 100 1 10/15/2010 22:00:00 0 220 100 1 10/15/2010 23:00:00 0 220 100 1 10/16/2010 00:00:00 0 220 100 1 10/16/2010 01:00:00 0 220 100 1 10/16/2010 02:00:00 0 220 100 1 10/16/2010 03:00:00 0 220 100 1 10/16/2010 04:00:00 0 220 100 1 10/16/2010 05:00:00 245 220 100 1 10/16/2010 06:00:00 360 220 100 1 10/16/2010 07:00:00 596 220 100 1 10/16/2010 08:00:00 1567 220 100 1 10/16/2010 09:00:00 1568 220 100 1 10/16/2010 10:00:00 1598 220 100 1 10/16/2010 11:00:00 1642 220 100 1 10/16/2010 12:00:00 1658 220 100 1 10/16/2010 13:00:00 1664 220 100 1 10/16/2010 14:00:00 1598 220 100 1 10/16/2010 15:00:00 1527 220 100 1 10/16/2010 16:00:00 980 220 100 1 10/16/2010 17:00:00 410 220 100 1 10/16/2010 18:00:00 208 220 100 1 10/16/2010 19:00:00 0 220 100 1 10/16/2010 20:00:00 0 220 100 1 10/16/2010 21:00:00 0 220 100 1 10/16/2010 22:00:00 0 220 100 1 10/16/2010 23:00:00 0 220 100 1 10/17/2010 00:00:00 0 220 100 1 10/17/2010 01:00:00 0 220 100 1 10/17/2010 02:00:00 0 220 100 I am retrieving data using AJAX. I would like to sort them from newest to oldest date. Currently they show from oldest to newest. How do I do that? <div id="output"></div> <script> $(document).ready(function(){ $.ajax ({ type: 'GET', url: "https://3rdpartywebsite.com/api/getcustomers", dataType: 'json', success: function(data) { $.each(data, function(i, v) { var customerId = v.customerId; var firstName = v.firstName; var lastName = v.lastName; var createdDateTime = v.createdDateTime; $('#output').append('<ul class="output-ul">' + '<li>' + customerId + '</li>' + '<li>' + firstName + '</li>' + '<li>' + lastName + '</li>' + '<li>' + createdDateTime + '</li>' + '</ul>'); }); } }); }); </script>
I'm practising how to do date and time in PHP. I wanted to see if I can get all of the date/time variables from user submission and format them correctly. I went with ISO 8601 date... // From the Manual: // date('c', mktime(1, 2, 3, 4, 5, 2006)); // Prints something like: 2006-04-05T01:02:03+00:00 ...but my attempts always produce a slightly different result for the year, month and timezone... Code: [Select] $inputTime = date('c', mktime((int)$timeHour, (int)$timeMins, (int)$timezone, (int)$dateMonth, (int)$dateDay, (int)$dateYear)); echo $inputTime; // Should return: 2013-11-02T02:30:01+00:00 // Instead returns: 2012-12-02T02:30:01-08:00 The timezone value coming from HTML... <option value="1.0">(GMT +1:00)</option> I noticed; 1. It always picks a year less than whatever year I select. 2. It always selects 12 as the month. 3. It always adds -08:00 after the picking the correct timezone. How come? Thanks in advance. I have a table with two columns. The first is an id column, set to be my primary key, non null, unique, int, and auto increment. The second is a varchar(10) column. Very strangely, when I set the varchar(10) column to unique, and try to edit the table in workbench, the table is automatically ordered by my varchar column, and not my id (primary key column). If I mark the varchar(10) column as not unique, data is ordered by the primary key, as expected. What is going on here? I expected the primary key to be default ordering for the table. I hope to not use an ORDER BY clause.
Edited by E_Leeder, 29 November 2014 - 02:14 AM. Hi, I have switched to a unix server from a windows one and my dir.php now displays in date order which makes things very hard to find Below is the code I use, can anyone tell me what to put, and where ? to make it sort by file name, or point me to a freeware script that has already invented the wheel so to speak. <?php function humansize($size) { $kb = 1024; // Kilobyte $mb = 1024 * $kb; // Megabyte $gb = 1024 * $mb; // Gigabyte $tb = 1024 * $gb; // Terabyte if($size < $kb) return $size."B"; else if($size < $mb) return round($size/$kb,0)."KB"; else if($size < $gb) return round($size/$mb,0)."MB"; else if($size < $tb) return round($size/$gb,0)."GB"; else return round($size/$tb,2)."TB"; } $path= dirname($_SERVER['SCRIPT_FILENAME']); ?> <h3>Files in <?php print $path; ?>:</h3> <ul> <?php $d = dir($path); $icon = ''; while (false !== ($entry = $d->read())) { if ( substr($entry, 0, 1)=='.' ) continue; $size = filesize($path.'/'.$entry); $humansize = humansize($size); $dotpos = strrpos($entry, '.'); if ($dotpos) { $ext = substr($entry, $dotpos+1); if ($ext === 'jpeg' || $ext === 'gif' || $ext === 'png') { $icon = "<img src='$entry' style='width: 48px; height: auto; vertical-align: text-top;' alt='icon' title='$entry' />"; } } print "<li><a href='$entry'>$entry</a> ($humansize) $icon</li>\n"; $icon= ''; } $d->close(); ?> Please help an old fellow who should know better Regards Topshed i've been able to load up a csv file and display it as a html table but what i'm having trouble with is sorting it out with headings a to z but what i am trying to do is have 4 columns like this. Surgestions about how to do what im after i was hoping i could span the say A across all columns and centering them in the future also but thats not really the problem mainly the getting the array of the csv file and code right iguess. any help would be appreciated Code: [Select] <table> <tr> <th>A</th> </tr> <tr> <td>Apple1</td> <td>Apple2</td> <td>Apple3</td> <td>Apple4</td> <td>Apple5</td> <td>Apple6</td> </tr> <tr> <th>B</th> </tr> <td>Banana1</td> <td>Banana2</td> <td>Banana3</td> <td>Banana4</td> <td>Banana5</td> <td>Banana6</td> <tr> <th>C</th> </tr> <td>Cold1</td> <td>Cold2</td> <td>Cold3</td> <td>Cold4</td> <td>Cold5</td> <td>Cold6</td> </table> This is the code for inputting of the csv file i also have some other code i was wanting to use for the sorting of the array data from the csv file i'll past below.... Quote <?php $file = "widgets.csv"; $delimiter = ","; $enclosure = '"'; $column = array("", "", "", ""); @$fp = fopen($file, "r") or die("Could not open file for reading"); while (!feof($fp)) { $tmpstr = fgets($fp, 100); $line[] = preg_replace("/r/", "", $tmpstr); } for ($i=0; $i < count($line); $i++) { $line[$i] = explode($delimiter, $line[$i]); } ?> <html> <head> <title>Albert's Delimited Text to HTML Table Converter</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <table border="1" cellpadding="5" cellspacing="0"> <tr> <?php for ($i=0; $i<count($column); $i++) echo "<th>".$column[$i]."</th>"; ?> </tr> <?php for ($i=0; $i < count($line); $i++) { echo "<tr>"; for ($j=0; $j < count($line[$i]); $j++) { echo "<td>".$line[$i][$j]."</td>"; } echo "</tr>"; } fclose($fp); ?> </table> </body> </html> Heres the code for the sorting of the table data from the array Quote <?php echo "QUERY_STRING is ".$_SERVER['QUERY_STRING']."<p>"; $rev=1; $sortby=0; if(isset($_GET['sortby']))$sortby = $_GET['sortby']; if(isset($_GET['rev']))$rev = $_GET['rev']; //Open and read CSV file example has four columns $i=-1; $ff=fopen('widgets2.csv','r') or die("Can't open file"); while(!feof($ff)){ $i++; $Data[$i]=fgetcsv($ff,1024); } //Make columns sortable for each sortable column foreach ($Data as $key => $row) { $One[$key] = $row[0]; // could be $row['Colname'] $Two[$key] = $row[1]; //numeric example $Three[$key] = $row[2]; $Four[$key] = $row[3];} //numeric example //Case Statements for Sorting switch ($sortby){ case "0": if($rev=="1")array_multisort($One, SORT_NUMERIC, $Data); //SORT_NUMERIC optional else array_multisort($One, SORT_NUMERIC, SORT_DESC,$Data); $rev=$rev*-1; break; case "1": if($rev=="1")array_multisort($Two, $Data); else array_multisort($Two, SORT_DESC, $Data); $rev=$rev*-1; break; case "2": if($rev=="1")array_multisort($Three, SORT_NUMERIC, $Data); else array_multisort($Three, SORT_NUMERIC, SORT_DESC,$Data); $rev=$rev*-1; break; case "3": if($rev=="1")array_multisort($Four, $Data); else array_multisort($Four, SORT_DESC, $Data); $rev=$rev*-1; break;} echo ("<table border=2>"); //$rev is reverse variable echo ("<th><a href=\"SortTable.php?sortby=0&rev=$rev\" title=\"Click to Sort/Reverse sort\">One</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=1&rev=$rev\" title=\"Click to Sort/Reverse sort\">Two</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=2&rev=$rev\" title=\"Click to Sort/Reverse sort\">Three</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=3&rev=$rev\" title=\"Click to Sort/Reverse sort\">Four</a></th>"); $i=0; foreach($Data as $NewDat){ if($NewDat[0]!=""){ //error trap $str="<tr>"; foreach($NewDat as $field)$str.="<td>$field</td>"; $str.="</td>\n"; echo $str;}} fclose($ff); echo "</table>"; Hi guys, I've been working on a script for a while now, and I'm sure it doesn't look great and all, and it's probably really messed up.. But right now I've finally got it working! There's only 1 thing I'd really like to add.. Searching through & listing of remote directories! The directories I'm trying to list have directory listings enabled, and I think it *should* be possible. I just have no clue how. Here's my current code in a beautiful mix of HTML and PHP: <? $border_size = "0"; function returner($what) { $what=explode("/",$what); $tps=count($what); $what=$what[$tps-1]; return $what; } $page_url= ""; $home_url=returner(__FILE__); if(isset($_GET['q'])) { $qtext=$_GET['q']; } else { $qtext=""; } function getdirsize($directory, $format=FALSE) { $size = 0; if(substr($directory,-1) == '/') { $directory = substr($directory,0,-1); } if(!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) { return -1; } if($handle = opendir($directory)) { while(($file = readdir($handle)) !== false) { $path = $directory.'/'.$file; if($file != '.' && $file != '..') { if(is_file($path)) { $size += filesize($path); } elseif(is_dir($path)) { $handlesize = getdirsize($path); if($handlesize >= 0) { $size += $handlesize; } else { return -1; } } } } closedir($handle); } if($format == TRUE) { if($size / 1048576 > 1) { return round($size / 1048576, 1).' MB'; } elseif($size / 1024 > 1) { return round($size / 1024, 1).' KB'; } else { return round($size, 1).' bytes'; } } else { return $size; } } if(isset($_GET['type'])){ $type=$_GET['type']; } else { $type="new"; } $textures=0; $models=0; $avatars=0; $seqs=0; $sounds=0; foreach (glob("textures/*.jpg") as $texture){ $textures++; } foreach (glob("models/*.zip") as $model){ $models++; } foreach (glob("avatars/*.zip") as $avatar){ $avatars++; } foreach (glob("seqs/*.zip") as $seq){ $seqs++; } foreach (glob("sounds/*.zip") as $sound){ $sounds++; } ?> <!DOCTYPE html> <html> <head> <title>ObjectPath Search</title> <style type="text/css"> #wrapper { width: 850px; margin: 30px auto 30px auto; padding: 10px; } body { color:#C6C6C6; background:#1E1E1E; /* margin:0; padding:0; */ overflow-x:hidden; } #tabs { font: 85% "Trebuchet MS", sans-serif; } .left { float: left; } .right { float: right; } a:link, a:visited, a:active { color: #3DB015; text-decoration: none; } a:hover { color: #00E0FF; } h2 { color: #3DB015; padding-bottom: 0.2em; font-size: 110%; } ul#icon {margin: 0; padding: 0;} ul#icon li {margin: 1px; position: relative; padding: 1px 0; cursor: pointer; float: left; list-style: none;} ul#icon span.ui-icon {float: left; margin: 0 1px;} </style> <link type="text/css" href="http://objects.jk-hosting.com/search/css/black-tie/jquery-ui-1.8.2.custom.css" rel="stylesheet" /> <script type="text/javascript" src="http://objects.jk-hosting.com/search/js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="http://objects.jk-hosting.com/search/js/jquery-ui-1.8.2.custom.min.js"></script> <script type="text/javascript"> function formHandler(form){ var URL = document.form.site.options[document.form.site.selectedIndex].value; window.location.href = URL; }; $(function(){ // Tabs $('#tabs').tabs(); }); </script> </head> <body> <div id="wrapper"> <div id="tabs"> <!-- Tabs start --> <ul> <li><a href="#tab-search">Search</a></li> <li><a href="#tab-list">List Objects</a></li> <li><a href="#tab-info">OP info</a></li> </ul> <div id="tab-search"><!-- Searchtab start --> Please enter a string to search for, and choose a folder to search in. <br /><br /> <form name="Search"> <input type='hidden' value='search' name='type'> <input value='<? print $qtext; ?>' type='text' name='q'> <select name='map'> <option selected='selected' value='models'>Models</option> <option value='avatars'>Avatars</option> <option value='textures'>Textures</option> <option value='seqs'>Seqs</option> <option value='sounds'>Sounds</option></select> <input type='submit' value='Search'> </form> </div> <!-- Searchtab end --> <div id="tab-list"><!-- Listtab start --> Please pick a folder to browse. <br /><br /> <form name="form"> <select name="site" onChange="javascript:formHandler()"> <option value="#">Look in folder...</option> <option value="<? print $page_url; ?>?type=list&map=models">Models</option> <option value="<? print $page_url; ?>?type=list&map=avatars">Avatars</option> <option value="<? print $page_url; ?>?type=list&map=textures">Textures</option> <option value="<? print $page_url; ?>?type=list&map=seqs">Seqs</option> <option value="<? print $page_url; ?>?type=list&map=sounds">Sounds</option> </select> </form> </div> <!-- Listtab end --> <div id="tab-info"><!-- Info tab start --> The OP currently contains: <br /><br /> <table> <tr><td><b><? echo $models; ?></b></td> <td>Models</td></tr> <tr><td><b><? echo $avatars; ?></b></td> <td>Avatars</td></tr> <tr><td><b><? echo $textures; ?></b></td> <td>Textures</td></tr> <tr><td><b><? echo $seqs; ?></b></td> <td>Seqs</td></tr> <tr><td><b><? echo $sounds; ?></b></td> <td>Sounds</td></tr> </table> </div> <!-- Info tab end --> </div> <!-- Tabs end --> </div> <!-- Start PHP generated content --> <? if($type=="search" || $type=="list") { $M=$_GET['map']; if($type=="search") { $Q=$_GET['q']; $empty="Nothing found with <b>\"" . $Q . "\"</b> in it's name.<br />\nPlease make a more general search query, or try a different folder.\n\n"; } else { $Q=""; $empty='This folder is empty'; } if($M=="textures") { $ext="jpg"; } else { $ext="zip"; } $i=0; print "<hr>\n"; $endfile=array(); $endsize=array(); $endsize2=array(); foreach (glob($M."/*".$Q."*.".$ext) as $filename) { $filename = explode(".", $filename); $filename=$filename[0]; $filename = explode("/", $filename); $filename=$filename[1]; $i++; $endfile[$i]=$filename; if($ext=="jpg") { $endfile[$i]="<a name='".$endfile[$i]."' href='".$pageurl."?type=view&name=".$endfile[$i]."&folder=".$M."&from=".$type."&addon=".$Q."'>".$endfile[$i]."</a>"; } $endsize[$i]=$size; $endsize2[$i]=$size2; } if($i != 1) { print "<b>".$i."</b> items were found.\n<hr>\n"; } else { print "<b>".$i."</b> item was found.\n<hr>\n"; } echo("<table width='100%' border='" . $border_size . "' cellspacing='0' cellpadding='0' >\n"); if($i!=0) { for ($t = 1; $t < $i; $t++) { $thumbfile = $M."/".$endfile[$t].'.jpg'; if(file_exists($thumbfile)) { $thumbnail = "<a name='".$endfile[$t]."' href='".$page_url."?type=view&name=".$endfile[$t]."&folder=".$M."&from=".$type."&addon=".$Q."'><ul id='icon'><li class='ui-state-default ui-corner-all' title='".$endfile[$t]."'><span class='ui-icon ui-icon-image'></span></li></ul></a>"; } else { $thumbnail = ""; } if($t=="1") { echo("<tr><td width='10%'>Number</td><td width='3%'><ul id='icon'><li class='ui-state-default ui-corner-all' title='".$endfile[$t]."'><span class='ui-icon ui-icon-image'></span></li></ul></td><td width='60%'>Name</td></tr>\n"); } echo("<tr><td>" . $t . "</td><td>".$thumbnail."</td><td>" . $endfile[$t] . "</td></tr>\n"); flush(); } $thumbfile = $M."/".$endfile[$t].'.jpg'; if(file_exists($thumbfile)) { $thumbnail = "<a name='".$endfile[$t]."' href='".$page_url."?type=view&name=".$endfile[$t]."&folder=".$M."&from=".$type."&addon=".$Q."'><ul id='icon'><li class='ui-state-default ui-corner-all' title='".$endfile[$t]."'><span class='ui-icon ui-icon-image'></span></li></ul></a>"; } else { $thumbnail = ""; } echo("<tr><td>" . $t . "</td><td>".$thumbnail."</td><td>" . $endfile[$t] . "</td></tr>\n"); } print "</table>\n"; if($i=="0") { print $empty; } } elseif($type=="view") { $filename=$_GET['name']; $folder=$_GET['folder']; if($_GET['from']=="list"){ $addon="?type=list&map=".$folder."#".$filename; } if($_GET['from']=="search"){ $addon="?type=search&q=".$filename."&map=".$folder."#".$filename; } print"<center><a href='".$home_url."'>Home</a></center>"; print "<hr>\n<center><img src='".$folder."/".$filename.".jpg'></img></center>\n<hr>\n<br />\n<a href='".$page_url."".$addon."'>Previous Page</a>\n"; } $htmlshow=""; if($_GET['type']=="returnOPfile") { if(isset($_GET['split'])) { $splitter=$_GET['split']; } else { $splitter=" | "; } if(isset($_GET['html'])) { $htmlshow="<br />"; } foreach (glob("textures/*.jpg") as $texture){ if(isset($_GET['size'])) { $size=$splitter.filesize($texture); } $texture = explode("/", $texture); $texture=$texture[1]; print "textures".$splitter.$texture.$size."\n".$htmlshow; } foreach (glob("models/*.zip") as $model){ if(isset($_GET['size'])) { $size=$splitter.filesize($model); } $model = explode("/", $model); $model=$model[1]; print "models".$splitter.$model.$size."\n".$htmlshow; } foreach (glob("avatars/*.zip") as $avatar){ if(isset($_GET['size'])) { $size=$splitter.filesize($avatar); } $avatar = explode("/", $avatar); $avatar=$avatar[1]; print "avatars".$splitter.$avatar.$size."\n".$htmlshow; } foreach (glob("seqs/*.zip") as $seq){ if(isset($_GET['size'])) { $size=$splitter.filesize($seq); } $seq = explode("/", $seq); $seq=$seq[1]; print "seqs".$splitter.$seq.$size."\n".$htmlshow; } foreach (glob("sounds/*.zip") as $sound){ if(isset($_GET['size'])) { $size=$splitter.filesize($sound); } $sound = explode("/", $sound); $sound=$sound[1]; print "sounds".$splitter.$sound.$size."\n".$htmlshow; } } ?> <!-- End PHP generated content --> </body> </html> So right now my question to you PHP freaks is, can you please help me edit my script so I can search through a remote directory? *This* is one of the directories I wish to be able to search through & list.. Thanks in advance. Edit; It might help if you know what the site currently looks like. *Click* i have made an delete files script which works for only one directory but not sub directory so i want to delete files of same extention from directory and subdirectory. My current code is Code: [Select] <? $dir = 'hmm/'; function scanr($dir){ $arr = glob($dir.'/*.jpg'); foreach($arr as $vv){ //check if $vv is a file if(is_file($vv)){ //if file, get the filename $vx=explode('/',$vv); $file=$vx[count($vx)-1]; // if no extension delete the file unlink($vv); // print the deletion message echo $vv." deleted!<br>";}else{ // if $vv is a dir then scan it again for files scanr($vv); }} } scanr($dir); ?> Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack I'm trying to echo the directory and sub directory only. I am not looking to show the files contained - only folders. Hello. I'm new to pHp and I would like to know how to get my $date_posted to read as March 12, 2012, instead of 2012-12-03. Here is the code: Code: [Select] <?php $sql = " SELECT id, title, date_posted, summary FROM blog_posts ORDER BY date_posted ASC LIMIT 10 "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $title = $row['title']; $date_posted = $row['date_posted']; $summary = $row['summary']; echo "<h3>$title</h3>\n"; echo "<p>$date_posted</p>\n"; echo "<p>$summary</p>\n"; echo "<p><a href=\"post.php?id=$id\" title=\"Read More\">Read More...</a></p>\n"; } ?> I have tried the date() function but it always updates with the current time & date so I'm a little confused on how I get this to work. I have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? Hi, I have a job listing website which displays the closing date of applications using: $expired_date (This displays a date such as 31st December 2019) I am trying to show a countdown/number of days left until the closing date. I have put this together, but I can't get it to show the number of days. <?php $expired_date = get_post_meta( $post->ID, '_job_expires', true ); $hide_expiration = get_post_meta( $post->ID, '_hide_expiration', true ); if(empty($hide_expiration )) { if(!empty($expired_date)) { ?> <span><?php echo date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $post->ID, '_job_expires', true ) ) ) ?></span> <?php $datetime1 = new DateTime($expired_date); $datetime2 = date('d'); $interval = $datetime1->diff($datetime2); echo $interval->d; ?> <?php } } ?> Can anyone help me with what I have wrong? Many thanks (continuing from topic title) So if I set a date of July 7 2011 into my script, hard coded in, I would like the current date to be checked against the hard coded date, and return true if the current date is within a week leading up to the hard coded date. How could I go about doing this easily? I've been researching dates in php but I can't seem to work out the best way to achieve what I'm after. Cheers Denno Hi, Currently I am making a module for joomla. every article has an publish date, if the article was published in 7 days ago, it will displayed as "article in last week", My idea is to use today's date - publish date, if the result is greater than 7 and smaller than 14, the article will be displayed as "article in last week. Any one know how to write this code? Here is what I have got, but not working. <?php $todays_date = date("Y-m-d"); $result = mysql_query("select * from jos_content where $test between $todays_date-14 and $todays_date-7"); while($row = mysql_fetch_array($result)) { echo "$todays_date - $row[title]"; } ?> I'm getting this Time Zone error. Perhaps it's a compatibility issue with PHP 5.3. Looked all over for an answer without finding one. Here is the error message Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in /blocked.php on line 41 12/02/12 Here is the code. Line 41 is near the bottom, the one with the d,m,y. Perhaps the echo date (d/m/y") needs to be changed. Appreciate any help! Code: [Select] <table border="3" width="16%" align="center" cellspacing="0" bgcolor="#FF6600" bordercolor="red" bordercolordark="red" bordercolorlight="red"> <tr> <td width="176"> <p align="center"><?php // shows IP Number on Page echo $ip; ?> </p> </td> </tr> </table> <p align="center"><?php // Show the user agent echo 'Your user agent is: <b>'.$_SERVER['HTTP_USER_AGENT'].'</b><br />';?></p> [b]<h1 align="center"><?php echo date("d/m/y");?></h1>[/b] </td> </tr> </table [,code] i have a table that shows payments made but want to the payments only showing from a set date(06/12/14) and before this date i dont want to show
this is my sql that doesnt seem to work and is showing dates before the specified date.
.
"SELECT * FROM payments2014, signup2014, editprop2014 WHERE signup2014.userid = payments2014.payment_userid AND editprop2014.prop_id = signup2014.prop_id AND signup2014.userid !='page1' AND signup2014.userid !='page6' AND signup2014.userid !='page4' AND payments2014.payment_transaction_status !='none' AND payments2014.payment_transaction_status !='CANCELLEDa' AND payments2014.payment_type !='deposit' AND payments2014.payment_paid_timestamp NOT LIKE '%2012%' AND payments2014.payment_paid_timestamp NOT LIKE '%2011%' AND payments2014.payment_paid_timestamp >= '06/12/14' ORDER BY payments2014.payment_id DESC"i have some other parts in the statment but this one that should be filtering is host_payments2014.payment_paid_timestamp >= '06/12/14'thanks in advance Hi guys, I'm putting together a small event system where I want the user to add his own date and time into a textfield (I'll probably make this a series of drop-downs/a date picker later). This is then stored as a timestamp - "0000-00-00 00:00:00" which displays fine until I try to echo it out as a UK date in this format - jS F Y, which just gives today's date but not the inputted date. Here's the code I have right now: Code: [Select] $result = mysql_query("SELECT * FROM stuff.events ORDER BY eventdate ASC"); echo "<br />"; echo mysql_result($result, $i, 'eventvenue'); echo ", "; $dt = new DateTime($eventdate); echo $dt->format("jS F Y"); In my mysql table eventdate is set up as follows: field - eventdate type - timestamp length/values - blank default - current_timestamp collation - blank attributes - on update CURRENT_TIMESTAMP null - blank auto_increment - blank Any help as to why this could be happening would be much appreciated, thanks. |