Jump to content

jamesmpollard

Members
  • Posts

    28
  • Joined

  • Last visited

Everything posted by jamesmpollard

  1. I was wondering if anyone could help! I'm pulling my hair out here. Basically I pull some data down from the DB (start & end) which are both datetime columns. What I need it to do is if the start is say 10:00AM and the end is 12:00PM I need it to add the HTML class "y" to 10,10:30, 11, 11:30 & 12. It did work in one instance, then I tested it again on another example and every TD was class "n". Could someone shed some light on what's going wrong here?[/size] -- I would like to point out here my indentation was all perfect but for some reason it's not when I post it lol.[/size] <?php function betweenTime($input, $from, $till) { $fromTime = strtotime($from); $toTime = strtotime($till); $inputTime = strtotime($input); if(($inputTime >= $fromTime && $inputTime <= $toTime)) { return true; } else { return false; } } foreach ($Appts as $APK => $APV) { $StartI = settype(date('i', strtotime($Appts[$APK]['start'])), 'integer'); $EndI = settype(date('i', strtotime($Appts[$APK]['end'])), 'integer'); $Start = date('H:', strtotime($Appts[$APK]['start'])) . ($StartI >= 30 ? '30' : '00') . date(' a', strtotime($Appts[$APK]['start'])); $End = date('H:', strtotime($Appts[$APK]['end'])) . ($EndI >= 30 ? '30' : '00') . date(' a', strtotime($Appts[$APK]['end'])); $Start_ = date('H:i a', strtotime($Appts[$APK]['start'])); $End_ = date('H:i a', strtotime($Appts[$APK]['end'])); echo ' <tr class="participant"> <td class="pname"><div class="pname">James</div></td> <td class="partTableCell' . ($Start === '08:00 am' || $End === '08:00 am' || betweenTime('08:00 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '08:30 am' || $End === '08:30 am' || betweenTime('08:30 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '09:00 am' || $End === '09:00 am' || betweenTime('09:00 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '09:30 am' || $End === '09:30 am' || betweenTime('09:30 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '10:00 am' || $End === '10:00 am' || betweenTime('10:00 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '10:30 am' || $End === '10:30 am' || betweenTime('10:30 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '11:00 am' || $End === '11:00 am' || betweenTime('11:00 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '11:30 am' || $End === '11:30 am' || betweenTime('11:30 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '12:00 pm' || $End === '12:00 pm' || betweenTime('12:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '12:30 pm' || $End === '12:30 pm' || betweenTime('12:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '01:00 pm' || $End === '01:00 pm' || betweenTime('01:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '01:30 pm' || $End === '01:30 pm' || betweenTime('01:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '02:00 pm' || $End === '02:00 pm' || betweenTime('02:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '02:30 pm' || $End === '02:30 pm' || betweenTime('02:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '03:00 pm' || $End === '03:00 pm' || betweenTime('03:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '03:30 pm' || $End === '03:30 pm' || betweenTime('03:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '04:00 pm' || $End === '04:00 pm' || betweenTime('04:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '04:30 pm' || $End === '04:30 pm' || betweenTime('04:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '05:00 pm' || $End === '05:00 pm' || betweenTime('05:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '05:30 pm' || $End === '05:30 pm' || betweenTime('05:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '06:00 pm' || $End === '06:00 pm' || betweenTime('06:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '06:30 pm' || $End === '06:30 pm' || betweenTime('06:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '07:00 pm' || $End === '07:00 pm' || betweenTime('07:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '07:30 pm' || $End === '07:30 pm' || betweenTime('07:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '08:00 pm' || $End === '08:00 pm' || betweenTime('08:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '08:30 pm' || $End === '08:30 pm' || betweenTime('08:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '09:00 pm' || $End === '09:00 pm' || betweenTime('09:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '09:30 pm' || $End === '09:30 pm' || betweenTime('09:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '10:00 pm' || $End === '10:00 pm' || betweenTime('10:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '10:30 pm' || $End === '10:30 pm' || betweenTime('10:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '11:00 pm' || $End === '11:00 pm' || betweenTime('11:00 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '11:30 pm' || $End === '11:30 pm' || betweenTime('11:30 pm', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell' . ($Start === '12:00 am' || $End === '12:00 am' || betweenTime('12:00 am', $Start_, $End_) ? ' y' : ' n') . ' dsep pok"></td> <td class="partTableCell n dsep pok"><img src="assets/images/delete.png" width="20" height="20" /></td> </tr>'; } ?>
  2. Sorry about the wrong category. Mod could you move it for me please?
  3. Glad to hear you've solved it and it's brilliant that you've posted how you did too for others to learn from but when you post code, please use the code tags to make it more pleasant on the eye.
  4. I was wondering if someone could shed some light on where I'm going wrong here. I'm trying to make it so that if a user came to my site (in dev mode at the minute so localhost) and used the url for example http://localhost/example/aquery/string. The url it would actually access it http://localhost/example.php?route=aquery/string. Is this possible? Here's what I have so far... Options All -Indexes +FollowSymLinks +MultiViews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*?)/(.*)$ $1.php?route=$2 [L] DefaultType application/x-httpd-php Any help appreciated. Many thanks James
  5. Thank you for your help! I'm going to hit the reset button and start over!
  6. That's almost what it's going to do when I'm finished, it will have a separate TPL for the header and footer and only really change the body TPL. But for ease of development, I'm trying to get it to parse all the data passed through it correctly which apparently is harder than I thought lol. Basically once the first line (settings{name} & settings{value}) has been parsed, I need it to unset the first result set, then the second and so on. But because everything is dynamic (the results, the requests, etc) I can't set in stone the order, so it's a numbers game. So in essence I need to find a way for the script to go On this line - I need to replace 2 items for the first result set. Then the line after - I need to replace 3 items from the second result set and so on. I was thinking about making it run through every line, gathering a list of replacements needed per line, then sorting them to the results set and str_replace'ing them all using arrays but that didn't seem to work well lol
  7. Excellent, is it all working okay? Or are you still facing the same problem?
  8. Could you run this and post the response please: <?php $host = "localhost"; $dbName = "project"; $dbUname = "root"; $dbPass = ""; try { $conn = new PDO("mysql: host=$host;dbname=$dbName; charset=utf8", $dbUname, $dbPass); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { exit('ERROR: ' . $e->getMessage()); } require_once 'classes.inc.php'; $project = new projecteg($conn);
  9. Using the "settings" key as an example here. What's happening is as it loop's through the system, on the first hit it find's settings{id} and replaces it with the first result set ID. When - if working right, it should be replacing it on the second hit because it's the second "request/line". I've tried making it so that the whole html is broken down line by line and processed that way but that's a massive nightmare and a benchmarking disaster
  10. I've uploaded a screenshot, that array look's ridiculous when pasted lol
  11. That last line confused me a bit lol. This is a print out of my example array: Array ( [members] => Array ( [0] => SQL [1] => 0 [RESULTS] => Array ( [0] => Array ( [id] => 1 [name] => James [email] => test@test.test ) ) ) [settings] => Array ( [0] => SQL [1] => 1 [RESULTS] => Array ( [0] => Array ( [id] => 1 [name] => skin [value] => default ) [1] => Array ( [id] => 2 [name] => sitename [value] => ATestSite ) [2] => Array ( [id] => 3 [name] => atest [value] => test ) ) ) )
  12. Scratch that, just realised.... line 18 is $e->getMessage(); Are you missing a semi colon?
  13. Please post full code for your dbconfig.inc.php or at least line 18
  14. Excellent. Thank you for getting back to me. I was considering it, but it would mean a whole re-write wouldn't it? Is there anything I could do to the existing script that could beef up security or even performance?
  15. Sorry, forgot to add. This is the output once ran: <html> <head> <title>Test</title> </head> <body> <ul> <li>skin - default</li> <li>1 - ATestSite - sitename</li> <li>test - atest</li> <li>James - test@test.test</li> <li>jamess - hi</li> <li>test11 - test22</li> </ul> </body> </html> This is what it should be <html> <head> <title>Test</title> </head> <body> <ul> <li>skin - default</li> <li>2 - ATestSite - sitename</li> <li>test - atest</li> <li>James - test@test.test</li> <li>jamess - hi</li> <li>test11 - test22</li> </ul> </body> </html>
  16. Been reading around and seen many people with outdated and depreciated DB wrappers, so I was wondering if mine is one of them? If so, is there anything I can do to change that. I want to be php7 ready and right on the front-line of it too! <?php /** * Database management and access class * This is a very basic level of abstraction */if (!defined('ND')) { exit('Direct access to this file is not permitted.');} $database_name = 'db'; class database { private $connections = array(); private $activeConnection = 0; private $queryCache = array(); private $dataCache = array(); private $last; private $QuerySTR; public function __construct() { } /** * Create a new database connection * @param String database hostname * @param String database username * @param String database password * @param String database we are using * @return int the id of the new connection */ public function newConnection($host, $user, $password, $database) { $this->connections[] = new mysqli($host, $user, $password, $database); $connection_id = count($this->connections) - 1; if (mysqli_connect_errno()) { trigger_error('Error connecting to host. ' . $this->connections[$connection_id]->connect_error, E_USER_ERROR); } return $connection_id; } /** * Close the active connection * @return void */ public function closeConnection() { $this->connections[$this->activeConnection]->close(); } /** * Change which database connection is actively used for the next operation * @param int the new connection id * @return void */ public function setActiveConnection(int $new) { $this->activeConnection = $new; } /** * Store a query in the query cache for processing later * @param String the query string * @return the pointed to the query in the cache */ public function cacheQuery($queryStr) { if (!$result = $this->connections[$this->activeConnection]->query($queryStr)) { trigger_error('Error executing and caching query: ' . $this->connections[$this->activeConnection]->error, E_USER_ERROR); return -1; } else { $this->queryCache[] = $result; return count($this->queryCache) - 1; } } /** * Get the number of rows from the cache * @param int the query cache pointer * @return int the number of rows */ public function numRowsFromCache($cache_id) { return $this->queryCache[$cache_id]->num_rows; } /** * Get the rows from a cached query * @param int the query cache pointer * @return array the row */ public function resultsFromCache($cache_id) { return $this->queryCache[$cache_id]->fetch_array(MYSQLI_ASSOC); } public function SQLCacheResultCount($CID) { return $this->queryCache[$CID]->field_count; } /** * Store some data in a cache for later * @param array the data * @return int the pointed to the array in the data cache */ public function cacheData($data) { $this->dataCache[] = $data; return count($this->dataCache) - 1; } public function DataCacheResultCount() { return count($this->dataCache); } /** * Get data from the data cache * @param int data cache pointed * @return array the data */ public function dataFromCache($cache_id) { return $this->dataCache[$cache_id]; } /** * Delete records from the database * @param String the table to remove rows from * @param String the condition for which rows are to be removed * @param int the number of rows to be removed * @return void */ public function deleteRecords($table, $condition, $limit) { $limit = ( $limit == '' ) ? '' : ' LIMIT ' . $limit; $delete = "DELETE FROM {$table} WHERE {$condition} {$limit}"; $this->executeQuery($delete); } /** * Update records in the database * @param String the table * @param array of changes field => value * @param String the condition * @return bool */ public function updateRecords($table, $changes, $condition) { $update = "UPDATE " . $table . " SET "; foreach ($changes as $field => $value) { $update .= "`" . $field . "`='{$value}',"; } $update = substr($update, 0, -1); if ($condition != '') { $update .= "WHERE " . $condition; } $this->executeQuery($update); return true; } /** * Insert records into the database * @param String the database table * @param array data to insert field => value * @return bool */ public function insertRecords($table, $data) { // setup some variables for fields and values $fields = ""; $values = ""; // populate them foreach ($data as $f => $v) { $f = $this->sanitizeData($f); $fields .= "`$f`,"; $v = $this->sanitizeData($v); $values .= ( is_numeric($v) && ( intval($v) == $v ) ) ? $v . "," : "'$v',"; } // remove our trailing , $fields = substr($fields, 0, -1); // remove our trailing , $values = substr($values, 0, -1); $insert = "INSERT INTO $table ({$fields}) VALUES({$values})"; $this->executeQuery($insert); return true; } public function selectRecords($table, $selection = '*', array $where = null, $limit = null, $orderby = null, $groupby = null, $order = null) { $q = 'SELECT '; if (is_array($selection)) { foreach ($selection as $SK) { $q .= $SK . ', '; } $q = substr($q, 0, (strlen($q) - 2)); } else if (is_string($selection)) { $q .= $selection; } else { return false; } $q .= ' FROM `' . $table . '`'; if (!is_null($where) && is_array($where)) { $q .= ' WHERE '; foreach ($where as $WK => $WV) { $q .= $WK . ' = \'' . $this->sanitizeData($WV) . '\', '; } $q = substr($q, 0, (strlen($q) - 2)); } if (!is_null($groupby)) { $q .= ' GROUP BY `' . $groupby . '`'; } if (!is_null($orderby)) { $q .= ' ORDER BY `' . $orderby . '`'; if (!is_null($order)) { $q .= ' ' . $order; } else { $q .= ' ASC'; } } if (!is_null($limit) && is_numeric($limit)) { $q .= ' LIMIT ' . $limit; } $this->executeQuery($q); return $this->getRows(); } /** * Execute a query string * @param String the query * @return void */ public function executeQuery($queryStr) { $this->QuerySTR = $queryStr; if (!$result = $this->connections[$this->activeConnection]->query($queryStr)) { trigger_error('Error executing query: ' . $this->connections[$this->activeConnection]->error, E_USER_ERROR); } else { $this->last = $result; } } /** * Get the rows from the most recently executed query, excluding cached queries * @return array */ public function getRows() { if (method_exists('mysqli_result', 'fetch_all')) { $results = $this->last->fetch_all(MYSQLI_ASSOC); } else { for ($results = array(); $tmp = $this->last->fetch_array(MYSQLI_ASSOC) $results[] = $tmp; } return $results; } /** * Gets the number of affected rows from the previous query * @return int the number of affected rows */ public function affectedRows() { return $this->connections[$this->activeConnection]->affected_rows; } /** * Sanitize data * @param String the data to be sanitized * @return String the sanitized data */ public function sanitizeData($data) { return $this->connections[$this->activeConnection]->real_escape_string($data); } /** * Deconstruct the object * close all of the database connections */ public function __deconstruct() { foreach ($this->connections as $connection) { $connection->close(); } } } ?> Many thanks James
  17. Pop this at the top of the page to get any PHP errors: ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); Also, in your dbconfig, replace $e->getMessage(); with exit $e->getMessage();
  18. Hi Ladies & Gent's I was wondering if someone could help. Basically I have built a small script that will take a template file - like this one: <html> <head> <title>Test</title> </head> <body> <ul> <li>settings{name} - settings{value}</li> <li>settings{id} - settings{value} - settings{name}</li> <li>settings{value} - settings{name}</li> <li>members{name} - members{email}</li> <li>data{name} - data{email}</li> <li>data{test1} - data{test2}</li> </ul> </body> </html> And replace the tags. "data" stands is replaced with basic data tags and the rest are SQL tags, so settings{name} would indicate to ouput the column "name" from settings. All is working except on thing that I have been trying everything to fix.... On line one we have this: <li>settings{name} - settings{value}</li> and on line two we have <li>settings{id} - settings{value} - settings{name}</li> All ouputs fine, except that because there isn't a request for an ID column on line one (which the ID would in this instance be 1 as it's the first row request), it places the ID in line two's ID column. So on the second row, for ID, it displays 1, when it should display 2. Here is my source: <?phpif (!defined('ND')) { exit('Direct access to this file is not permitted.');} $template_name = 'template'; class template { private $Contents; private $DBTags; private $DTTags; private $TemplateName; public function __construct() { } public function init($TemplateName) { $this->TemplateName = $TemplateName; $this->setTemplate(); } public function addTag($key, $data) { if ($key === 'data') { $this->DTTags[$key] = $data; } else { $this->DBTags[$key] = $data; } } private function setTemplate() { if (file_exists('skins/default/templates/' . $this->TemplateName . '.tpl.php')) { $this->Contents = file_get_contents('skins/default/templates/' . $this->TemplateName . '.tpl.php'); } else { // ERROR HERE } } private function replaceTags() { foreach ($this->DBTags as $TagKey => $TagValue) { for ($i = 0; $i < FrameworkRegistry::getObject('db')->SQLCacheResultCount($TagValue[1]); $i++) { $Value = FrameworkRegistry::getObject('db')->resultsFromCache($TagValue[1]); if (!empty($Value)) { $this->DBTags[$TagKey]['RESULTS'][] = $Value; } } } foreach ($this->DTTags as $DTagKey => $DTagValue) { for ($e = 0; $e < FrameworkRegistry::getObject('db')->DataCacheResultCount(); $e++) { $Value = FrameworkRegistry::getObject('db')->dataFromCache($e); if (!empty($Value)) { $this->DTTags[$DTagKey]['RESULTS'][] = $Value; } } } $this->replaceDBTags(); $this->replaceDataTags(); } private function RemoveCacheItem($Tag, $ID, $Item) { unset($this->DBTags[$Tag]['RESULTS'][$ID][$Item]); } private function replaceDBTags() { foreach ($this->DBTags as $DBKey => $DBValue) { foreach ($DBValue['RESULTS'] as $DBVK => $DBVV) { foreach ($DBVV as $NK => $NV) { $this->Contents = $this->str_replace_first($DBKey . '{' . $NK . '}', (string)$NV); $this->RemoveCacheItem($DBKey, $DBVK, $NK); } } } } private function replaceDataTags() { foreach($this->DTTags['data']['RESULTS'] as $DTKey => $DTValue) { foreach($DTValue as $TK => $TV) { $this->Contents = $this->str_replace_first('data{' . $TK . '}', $TV); } } } private function str_replace_first($search, $replace) { $pos = strpos($this->Contents, $search); if ($pos !== false) { $this->Contents = substr_replace($this->Contents, $replace, $pos, strlen($search)); } return $this->Contents; } public function Output() { $this->replaceTags(); //echo '<pre>' . print_r($this->DTTags, true) . '</pre>'; return $this->Contents; } public function __destruct() { } } Is there anything I can do to stop this? As you can see I've tried writing a function to remove the result set after use so that it will allow it to move to the next one but this doesn't seem to work! All get's removed, but it still doesn't output right! Any help appreciated here. Many thanks James
  19. Agreed. A crazy man would make one giant class for the whole site, benchmarking would be a disappointing result lol.
  20. Maybe a better question would be, what is the best way of using classes in a simple, easy, OOP manner? Bare in mind that many of my classes need to use functions from other classes to save cloning the same functions many times over. Interfaces, abstracts, ect. I'm not fussed, just need as simple way of doing it. EDIT: Forgot to mention, by OOP, I need the classes to be "chained". That would probably solve the problem of using functions from separate classes.
  21. Try changing $message = filter_var($_POST['message'], FILTER_SANITIZE_STRING); to $message = filter_var($_POST['message'], FILTER_SANITIZE_SPECIAL_CHARS);
  22. Check that plugins/user/jomsocialuser/jomsocialuser.php exists. If it does, change the permissions to 755.
  23. Slightly confused with that output as it doesn't show the "files" values you mentioned in your first post. Change the query to SELECT * FROM players SORT BY player and post back with that output.
  24. Sorry, I didn't really explain too well. I will be having a bootstrapper file that will include all the classes (class one, class two and so on) and the core. I would then like to use the core to use all other classes. To make life easier, simpler and to have less clutter, ect.
×
×
  • Create New...

Important Information

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