Jump to content

AdRock

Members
  • Posts

    913
  • Joined

  • Last visited

Everything posted by AdRock

  1. I have this array which has been pulled from a MySQL database (did a var_dump) array(2) { [0]=> array( { ["id"]=> string(1) "3" [0]=> string(1) "3" ["title"]=> string(23) "New Venture Coming Soon" [1]=> string(23) "New Venture Coming Soon" ["archived"]=> string(1) "y" [2]=> string(1) "y" ["postdate"]=> string(14) "7th March 2009" [3]=> string(14) "7th March 2009" } [1]=> array( { ["id"]=> string(1) "4" [0]=> string(1) "4" ["title"]=> string(22) "Visit To Headley Court" [1]=> string(22) "Visit To Headley Court" ["archived"]=> string(1) "y" [2]=> string(1) "y" ["postdate"]=> string(14) "7th March 2009" [3]=> string(14) "7th March 2009" } } I want to loop through the array and display the information but if $not_archived equals to zero then it displays a message. The problem is that it displays the message becuase $not_archived is equal to zero $z = 0; $not_archived = 0; foreach($news as $newsitem) { if($newsitem['archived'] == 'N') { if($z % 2==0) { //<tr class="yellow"> $z++; } else { //<tr class="white"> $z++ } $not_archived++; echo $newsitem['id']; echo $newsitem['title']; } } if($not_archived == 0) { //No active news in database }
  2. Why don't you join the 2 tables using a JOIN $query = 'SELECT patient.name,patient.surname,patient.id_number,medical_aid.medical_aid_scheme,medical_aid.medical_aid_number patient.name,patient.surname,patient.id_number,medical_aid.medical_aid_scheme,medical_aid.medical_aid_number FROM patient INNER JOIN medical_aid ON patient.id_number = medical_aid.id_number ORDER BY patient_id';
  3. Is this the correct format to doing a MySQL full text search using PDO? I want to search about 4 tables for the same keyword and not sure of the syntax $count = "SELECT COUNT(*) FROM (SELECT t.boardid, t.topicid, 'messages' as mytable, topicname as title, message as content, MATCH(topicname, message) AGAINST(':keywords*' IN BOOLEAN MODE) as score FROM topics t INNER JOIN messages m ON t.topicid=m.topicid WHERE MATCH(topicname, message) AGAINST(':keywords*' IN BOOLEAN MODE) UNION ALL SELECT id,'', 'news' as mytable,title, content, MATCH(title, content) AGAINST(':keywords*' IN BOOLEAN MODE) as score FROM news WHERE MATCH(title, content) AGAINST(':keywords*' IN BOOLEAN MODE) UNION ALL SELECT id,'', 'events' as mytable,title, content, MATCH(title, content) AGAINST(':keywords*' IN BOOLEAN MODE) as score FROM events WHERE MATCH(title, content) AGAINST(':keywords*' IN BOOLEAN MODE) UNION ALL SELECT id,'', 'blogs' as mytable,title, content, MATCH(title, content) AGAINST(':keywords*' IN BOOLEAN MODE) as score FROM blogs WHERE MATCH(title, content) AGAINST(':keywords*' IN BOOLEAN MODE)) a GROUP BY title"; $keywords = strtolower($_SESSION['keywords']); $sth = $dbh->prepare($count); $sth->bindValue(':keywords', $keywords, PDO::PARAM_STR); $sth->execute();
  4. Needed to implode $this->db->update('news', $postData, "`id` IN (".implode(',',$id).")");
  5. I have a function that updates a database and it works fine for one record but i have a form which shows loads of rows with checkboxes and i want to do a batch update (I suppose the principle is the same for a batch delete). When I click a load of checkboxed and call the funtion to update, i get an error about an array to string conversion and also this error message "Unknown column 'Array' in 'where clause" I know a way around it but it's not great using a foreach loop to update the database but that involves loads of queries This is my function I call to update the database /** * update * @param string $table A name of table to insert into * @param string $data An associative array * @param string $where the WHERE query part */ public function update($table, $data, $where) { ksort($data); $fieldDetails = NULL; foreach($data as $key=> $value) { $fieldDetails .= "`$key`=:$key,"; } $fieldDetails = rtrim($fieldDetails, ','); $sth = $this->prepare("UPDATE $table SET $fieldDetails WHERE $where"); foreach ($data as $key => $value) { $sth->bindValue(":$key", $value); } $sth->execute(); } This works public function newsEdit($data) { $postData = array( 'title' => $data['news_title'], 'content' => $data['news_content'], 'photo' => $data['imgname'], 'keywords' => $data['news_keywords'], 'alternate' => $data['alternate'] ); $this->db->update('news', $postData, "`id` = {$data['newsid']}"); } $data = array(); $data['news_title'] = $_POST['news_title']; $data['news_content'] = $_POST['news_content']; $data['imgname'] = $_POST['imgname']; $data['news_keywords'] = $_POST['news_keywords']; $data['alternate'] = substr($_POST['imgname'],0,strrpos($_POST['imgname'], ".")); newsEdit($data); This doesn't public function newsArchive($ids) { $postData = array( 'archived' => 'Y' ); $this->db->update('news', $postData, "`id` IN ({$ids})"); } newsArchive($_POST['id']); What have i got to change to get the update working?
  6. Don't know if this helps but this is what I used years ago function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $start_time = getmicrotime(); // do whatever like a database query $end_time = getmicrotime(); echo '<span class="bold">'.substr($end_time-$start_time,0,5).'</span> seconds';
  7. Thanks all....got it working now with your help
  8. I was trying to simplify my problem and your solutions look sound but i can't get it to work for my case so I'll explain a bit more. I've built my own MVC and in my config file I include on every page I have my array of buttons I wanted to have them as constants but seeing as it's a pain, i thought if i add it here it should be made public $buttons = array(); $buttons['back'] = array('class' => 'back', 'name' => 'backbutton', 'id' => 'back-button', 'title' => 'Go Back'); $buttons['save'] = array('class' => 'save', 'name' => 'savebutton', 'id' => 'save-button', 'title' => 'Save'); $buttons['add'] = array('class' => 'add', 'name' => 'addbutton', 'id' => 'add-button', 'title' => 'Add'); $buttons['edit'] = array('class' => 'edit', 'name' => 'editbutton', 'id' => 'edit-button', 'title' => 'Edit'); $buttons['delete'] = array('class' => 'delete', 'name' => 'deletebutton', 'id' => 'delete-button', 'title' => 'Delete'); $buttons['archive'] = array('class' => 'archive', 'name' => 'archivebutton', 'id' => 'archive-button', 'title' => 'Archive'); In my controller I add the array of buttons I want to appear in my form in my view file $this->view->buttons = array('back', 'save'); Then in my view file, I would have my foreach where in this case I want to include buttons 'back' and 'save' foreach ($this->buttons as $button) { echo '<input type="button" class="$button['class']" name="$button['name']" id="$button['id']" title="$button['title']" />'; } I think the problem I've got is looping through the foreach loop and including the right button from the config file. Would it be okay to define the array in a constant (i've read you need to serialize it first), then when i need to include it, unserialize it. I just need a way to make more code more efficient so I can use one view and add as many buttons as I need
  9. Thanks Kicken The reason I put it in an array is becuase different pages may have different buttons. Some page only need 2 buttons and not all of them. Will your code allow for that?
  10. Hopefully as easy one. I have this array of values I want to put in a form input $buttons = array(); $buttons['back'] = array('class' => 'back', 'name' => 'backbutton', 'id' => 'back-button', 'title' => 'Go Back'); $buttons['save'] = array('class' => 'save', 'name' => 'savebutton', 'id' => 'save-button', 'title' => 'Save'); $buttons['add'] = array('class' => 'add', 'name' => 'addbutton', 'id' => 'add-button', 'title' => 'Add'); $buttons['edit'] = array('class' => 'edit', 'name' => 'editbutton', 'id' => 'edit-button', 'title' => 'Edit'); $buttons['delete'] = array('class' => 'delete', 'name' => 'deletebutton', 'id' => 'delete-button', 'title' => 'Delete'); $buttons['archive'] = array('class' => 'archive', 'name' => 'archivebutton', 'id' => 'archive-button', 'title' => 'Archive'); What I want to to do is create an array like this if possible $buttons = array($buttons['back'], $buttons['save'], $buttons['add'], $buttons['edit'], $buttons['delete'], $buttons['archive']); and use a foreach loop like this foreach($buttons as $button) { echo '<input type="button" '.$button.'/>'; } so it outputs a load of buttons depending what was in the buttons array and using the elements in each array to give the buttons values I should end up with is <input type="button" class="back" name="backbutton" id="back-button" title="Go Back" /> <input type="button" class="save" name="savebutton" id="save-button" title="Save" /> <input type="button" class="add" name="addbutton" id="add-button" title="Add" /> <input type="button" class="edit" name="editbutton" id="edit-button" title="Edit" /> <input type="button" class="delete" name="deletebutton" id="delete-button" title="Delete" /> <input type="button" class="archive" name="archivebutton" id="archive-button" title="Archive" />
  11. That was it. It was in my jquery ajax. I changed it to a hardcoded address and it worked which is annoying because the constant URL is just http://localhost/mvc/ which i use throughout the site $.ajax({ url: 'http://localhost/mvc/util/events.php', dataType: 'json',
  12. Right....I've cleared the error log and the server access log and i've opened up the one page which was causing problems and these are the log results from both php error_log server access log I've got a feeling that it's to do with the last row in the access log as that is a script that in the jquery ajax to grab a list of events from the database and use it in the datepicker. At the moment the file it's looking for doesn't exist. Could that be the problem as the path is also incorrect for that file?
  13. I've been doing a bit of digging and found that if i replace $this->_url[1]; with a hard coded value, it doesn't throw the error private function _loadExistingAdminController() { $file = $this->_adminControllerPath . $this->_url[1] . '.php'; if (file_exists($file)) { require $file; $this->_adminController = new AddNews();//$this->_url[1]; $this->_adminController->loadModel('AddNews' /*$this->_url[1]*/, $this->_adminModelPath); } else { $this->_adminError(); return false; } } Ch0cu3r, this is my index with the autoloader. Where do i put that debug code? <?php require 'config.php'; require 'util/Auth.php'; // Also spl_autoload_register (Take a look at it if you like) //function __autoload($class) { // require LIBS . $class .".php"; //} ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); function application_autoloader($class) { $class = strtolower($class); $class_filename = strtolower($class).'.php'; $class_root = dirname(__FILE__); $cache_file = "{$class_root}/cache/classpaths.cache"; $path_cache = (file_exists($cache_file)) ? unserialize(file_get_contents($cache_file)) : array(); if (!is_array($path_cache)) { $path_cache = array(); } if (array_key_exists($class, $path_cache)) { /* Load class using path from cache file (if the file still exists) */ if (file_exists($path_cache[$class])) { require_once $path_cache[$class]; } } else { /* Determine the location of the file within the $class_root and, if found, load and cache it */ $directories = new RecursiveDirectoryIterator($class_root); foreach(new RecursiveIteratorIterator($directories) as $file) { if (strtolower($file->getFilename()) == $class_filename) { $full_path = $file->getRealPath(); $path_cache[$class] = $full_path; require_once $full_path; break; } } } $serialized_paths = serialize($path_cache); if ($serialized_paths != $path_cache) { file_put_contents($cache_file, serialize($path_cache)); } } spl_autoload_register('application_autoloader'); // Load the Bootstrap! $bootstrap = new Bootstrap(); // Optional Path Settings //$bootstrap->setControllerPath(); //$bootstrap->setModelPath(); //$bootstrap->setDefaultFile(); //$bootstrap->setErrorFile(); $bootstrap->init();
  14. Thanks for your suggestion ignace. I've done what you said in Firefox and i get a load of status 200 OK and a load of 304 Not Modified which is greyed out but no 404, In Chrome I get loads of 200 OK and nothing else Is there a way to turn of the error reporting on a hosted server if i can't find why this is happening? I really don't see any reason why this is coming up as it doesn't say which class can't be loaded and it seems nonsense
  15. Firstly, apologies if this is the wrong forum. I have been building my own custom MVC following these videos on YouTube http://www.youtube.com/watch?v=Aw28-krO7ZM I've got everything working just fine with no errors and it's all coming along nicely. Because the videos are a starting point, I needed to expand on it for my own needs so I edited the Bootstrap so it looks at the url and if the second paramter (array position[1]) is called 'admin', it takes another branch in the bootstrap. Basically, I've just copied a load of functions and renamed them for admin. It appears to be working fine where all the files are loaded and i see the page i want buti get that error message and i can't see why. There is no class called '<' and the right class is being loaded. If i wasn't checking my logs for errors, i wouldn't be aware of this as it doesn't stop anything running. I don't want my error_log getting bigger all the time so would like to fix this problem. The problem points to line 179 which is $this->_adminController = new $this->_url[1]; in this function private function _loadExistingAdminController() { $file = $this->_adminControllerPath . $this->_url[1] . '.php'; if (file_exists($file)) { require $file; $this->_adminController = new $this->_url[1]; $this->_adminController->loadModel($this->_url[1], $this->_adminModelPath); } else { $this->_adminError(); return false; } } I've done some var_dumps etc and can't find the problem. Here is my bootstrap file and i've included the source code from the tutorial I was builing on which has no errors <?php class Bootstrap { private $_url = null; private $_controller = null; private $_controllerPath = 'controllers/'; // Always include trailing slash private $_modelPath = 'models/'; // Always include trailing slash private $_errorFile = 'error.php'; private $_defaultFile = 'index.php'; private $_adminController = null; private $_adminControllerPath = 'controllers/admin/'; // Always include trailing slash private $_adminModelPath = 'models/admin/'; // Always include trailing slash private $_adminErrorFile = 'error.php'; private $_defaultAdminFile = 'index.php'; /** * Starts the Bootstrap * * @return boolean */ public function init() { // Sets the protected $_url $this->_getUrl(); // Load the default controller if no URL is set // eg: Visit http://localhost it loads Default Controller if (empty($this->_url[0])) { $this->_loadDefaultController(); $this->_controller->loadModel($this->_url[0], $this->_modelPath); return false; } elseif ($this->_url[0] == 'admin') { if (empty($this->_url[1])) { $this->_loadDefaultAdminController(); $this->_adminController->loadModel($this->_url[0], $this->_adminModelPath); return false; } $this->_loadExistingAdminController(); $this->_callAdminControllerMethod(); return false; } $this->_loadExistingController(); $this->_callControllerMethod(); } /** * Fetches the $_GET from 'url' */ private function _getUrl() { $url = isset($_GET['url']) ? $_GET['url'] : null; $url = rtrim($url, '/'); $url = filter_var($url, FILTER_SANITIZE_URL); $this->_url = explode('/', $url); } /** * This loads if there is no GET parameter passed */ private function _loadDefaultController() { require $this->_controllerPath . $this->_defaultFile; $this->_controller = new Index(); $this->_controller->loadModel('index', $this->_modelPath); $this->_controller->index(); } /** * Load an existing controller if there IS a GET parameter passed * * @return boolean|string */ private function _loadExistingController() { $file = $this->_controllerPath . $this->_url[0] . '.php'; if (file_exists($file)) { require $file; $this->_controller = new $this->_url[0]; $this->_controller->loadModel($this->_url[0], $this->_modelPath); } else { $this->_error(); return false; } } /** * If a method is passed in the GET url paremter * * http://localhost/controller/method/(param)/(param)/(param) * url[0] = Controller * url[1] = Method * url[2] = Param * url[3] = Param * url[4] = Param */ private function _callControllerMethod() { $length = count($this->_url); // Make sure the method we are calling exists if ($length > 1) { if (!method_exists($this->_controller, $this->_url[1])) { $this->_error(); } } // Determine what to load switch ($length) { case 5: //Controller->Method(Param1, Param2, Param3) $this->_controller->{$this->_url[1]}($this->_url[2], $this->_url[3], $this->_url[4]); break; case 4: //Controller->Method(Param1, Param2) $this->_controller->{$this->_url[1]}($this->_url[2], $this->_url[3]); break; case 3: //Controller->Method(Param1, Param2) $this->_controller->{$this->_url[1]}($this->_url[2]); break; case 2: //Controller->Method(Param1, Param2) $this->_controller->{$this->_url[1]}(); break; default: $this->_controller->index(); break; } } /** * Display an error page if nothing exists * * @return boolean */ private function _error() { require $this->_controllerPath . $this->_errorFile; $this->_controller = new Error(); $this->_controller->index(); exit; } /** * This loads if there is no GET parameter passed */ private function _loadDefaultAdminController() { require $this->_adminControllerPath . $this->_defaultAdminFile; $this->_adminController = new Index(); $this->_adminController->loadModel('index', $this->_adminModelPath); $this->_adminController->index(); } /** * Load an existing controller if there IS a GET parameter passed * * @return boolean|string */ private function _loadExistingAdminController() { $file = $this->_adminControllerPath . $this->_url[1] . '.php'; if (file_exists($file)) { require $file; $this->_adminController = new $this->_url[1]; $this->_adminController->loadModel($this->_url[1], $this->_adminModelPath); } else { $this->_adminError(); return false; } } /** * If a method is passed in the GET url paremter * * http://localhost/controller/method/(param)/(param)/(param) * url[0] = Controller * url[1] = Method * url[2] = Param * url[3] = Param * url[4] = Param */ private function _callAdminControllerMethod() { $length = count($this->_url); // Make sure the method we are calling exists if ($length > 2) { if (!method_exists($this->_adminController, $this->_url[2])) { $this->_adminError(); } } // Determine what to load switch ($length) { case 6: //Controller->Method(Param1, Param2, Param3) $this->_adminController->{$this->_url[2]}($this->_url[3], $this->_url[4], $this->_url[5]); break; case 5: //Controller->Method(Param1, Param2) $this->_adminController->{$this->_url[2]}($this->_url[3], $this->_url[4]); break; case 4: //Controller->Method(Param1, Param2) $this->_adminController->{$this->_url[2]}($this->_url[3]); break; case 3: //Controller->Method(Param1, Param2) $this->_adminController->{$this->_url[2]}(); break; default: $this->_adminController->index(); break; } } /** * Display an error page if nothing exists * * @return boolean */ private function _adminError() { require $this->_adminControllerPath . $this->_adminErrorFile; $this->_adminController = new AdminError(); $this->_adminController->index(); exit; } } mvc.tutorial.part.11.zip
  16. I have this function that creates breadcrumbs from the URL It appears to work but i get these error messages Line 13 points to $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; and line 16 is $last = end(array_keys($path)); Any ideas how i can remove these errors/warnings? here is the code public function breadcrumbs ($separator = ' ยป ', $home = 'Home') { $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; $breadcrumbs = array("<a href=\"$base_url\">$home</a>"); $last = end(array_keys($path)); foreach ($path AS $x => $crumb) { $title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb)); if ($x != $last){ $breadcrumbs[] = '<a href="'.$base_url.'/'.$crumb.'">'.$title.'</a>'; }else{ $breadcrumbs[] = $title; } } return implode($separator, $breadcrumbs); }
  17. I have an array which is pulled from a database like this: array(3) { [0]=> array(2) { ["carrier"]=> string(10) "Royal Mail" ["consignment"]=> string(2) "RM" } [1]=> array(2) { ["carrier"]=> string(5) "FedEx" ["consignment"]=> string( "31290238" } [2]=> array(2) { ["carrier"]=> string(3) "TNT" ["consignment"]=> string(11) "01549957430" [3]=> array(2) { ["carrier"]=> string(3) "TNT" ["consignment"]=> string(11) "01547847430" } } What I would like to do is sort that array so it's sorted by the 'carrier' key and the 'carrier' key should be echoed out only once if more than 1 row exists but still show the value like this: How can I achieve this with my code? $myarray = array(); foreach($rows as $row) { $consignment = $row['consignment_number']; //do something if ($consignment == 'RM') { // despatched by royal mail $myarray[] = array('carrier'=> 'Royal Mail', 'consignment' => $consignment); } elseif ( ctype_digit($consignment) && (strlen($consignment) == ) { // going by FedEx? $myarray[] = array('carrier'=> 'FedEx', 'consignment' => $consignment); } elseif ( ctype_digit($consignment) && (strlen($consignment) == 11) ) { // going by TNT? $myarray[] = array('carrier'=> 'TNT', 'consignment' => $consignment); } } echo '<pre>';var_dump($myarray);echo '</pre>'; echo 'Your order has been despatched by: <br />'; $i=0; foreach ($myarray as $key => $value) { if(in_array($myarray[0]['carrier'], $allowed)) { if(!empty($myarray[$i]['carrier'])) { echo $myarray[$i]['carrier'].': Your consignment number is: '.$myarray[$i]['consignment'].'<br />'; } $i++; } } Also what happened to the code formatting we used to have ages ago. How am i supposed to indent the code to make it readable now?
  18. Thanks Ch0cu3r . Got it sorted by making the new array as an associative array as sometimes I have more than 1 record returned
  19. I am pulling some data out of a MySQL database and echoing it out (pretty standard stuff) What is really confusing me is I have checked the query using phpMyAdmin and it returns 1 row which is what i expect. I've even double checked by using a COUNT query and i get the same result. The problem is when I run the returned array through a foreach loop to populate a new array, it appears to create 2 new array rows and i think it's to do with my IF statements. What i want to do in the IF is check is a certain value is present. If not, check that the value is a number and a certain length out of 2 conditions. If not, then do nothing. I'm looking for 3 conditions. Could the problem be that the field type in the database is a varchar and i'm checking for a number? Here is my code $allowed = array('param1', 'param2', 'param3'); //if(isset($_POST['submit'])) { //$sql = 'SELECT consignment_number FROM tracker WHERE order_number = 2893214 AND consignment_number IS NOT NULL'; $sql = 'SELECT column1, column2 FROM table WHERE column1 = :placeholder AND CHAR_LENGTH(column2) > 1'; $stmt = $db->prepare($sql); //$stmt->bindValue('order', $_POST['order']); $stmt->bindValue(':placeholder', $val); $stmt->execute(); $rows = $stmt->fetchAll(); echo count($rows).'<br />'; //echos 1 as checked in phpMyAdmin if(count($rows) != 0) { $myarray = array(); foreach($rows as $row) { $test = $row['column2']; //do something if ($test == 'RM') { // despatched by royal mail $myarray['column1'] = "param1"; $myarray['column2'] = $test; } elseif ( ctype_digit($test) && (strlen($test) == ) { // going by FedEx? $myarray['column1'] = "param2"; $myarray['column2'] = $test; } elseif ( ctype_digit($test) && (strlen($test) == 11) ) { // going by TNT? $myarray['column1'] = "param3"; $myarray['column2'] = $test; } } } else { //no rows } echo count($myarray); echo '<pre>';var_dump($myarray);echo'</pre>'; if(in_array($myarray['column1'], $allowed)) { foreach ($myarray as $array) { if(!empty($myarray['column1'])) { echo $myarray['column1'].': '.$myarray['column2'].'<br />'; } } } else { }
  20. I am importing a text/csv file and instead of importing all of the 'columns' (there are 15 columns on each line), I would like to import column number 1, 4, 15. I have the following code that will import the whole file into an array which works fine but i don't want the whole file in the array becuase I also need to do something like array_unique() where i filter out any duplicates once I have my 3 columns imported into an array. My question is: 1. How do i import the file to only read in the columns i want 2. Once I have all the data into an array , how do i get all the unique rows (so in theory the array size could be halved) Any help greatly appreciated # Open the File. if (($handle = fopen($files, "r")) !== FALSE) { # Set the parent multidimensional array key to 0. $nn = 0; while (($data = fgetcsv($handle, 1000, "|")) !== FALSE) { # Count the total keys in the row. $c = count($data); # Populate the multidimensional array. for ($x=0;$x<$c;$x++) { $csvarray[$nn][$x] = $data[$x]; } $nn++; } # Close the File. fclose($handle); //rename('imports/' . $files, 'archived/' . $files); }
  21. Many thanks to all of you for your help. I looked this morning as I wasn't convinced my foreach loop was wrong like Ch0cu3r said and I done a var_dump on the query result and saw my database array was fine and was what I expected. I knew if the query was correct and the foreach was correct it must be to do with where it's being output so I looked at my foreach loop on the display page and noticed I had <?php foreach($this->forum as $forumitem):?> <div class="eW"> <div class="e1 col_1"> <h5><a href="<?php echo URL;?>forum/board/<?php echo $this->forum[0]['boardname']; ?>"><?php echo $this->forum[0]['boardname']; ?></a></h5><p><?php echo $this->forum[0]['boarddesc']; ?></p> </div> <div class="e2 col_2"> <p><?php echo $this->forum[0]['messagecount']; ?> Posts</p><p><?php echo $this->forum[0]['topiccount']; ?> Topics</p> </div> <div class="e3 col_3"> <?php if (!empty($forumitem[0]['topicname'])):?> <p><b>Last post</b> by <?php echo $this->forum[0]['author']; ?></p><p>in <?php echo $this->forum[0]['topicname']; ?></p><p>on <?php echo $this->forum[0]['datetime']; ?></p> <?php endif; ?> </div> </div> It turned out and i could see that straight away from my var_dump that I needed to replace the 0 in the key value with $key and change the foreach to <?php foreach($this->forum as $key => $forumitem):?> As soon as I did this it worked. Again many thanks for pointing me in the right direction as it would have taken me ages to figure this out not knowing if my foreach was right.
  22. This is the code all in the same place where i execute my query and do the foreach() $sql = "SELECT b.boardid as boardno, b.*, t.topicname, m.*, (SELECT COUNT(*) FROM topics ti WHERE ti.boardid = b.boardid) AS topiccount, (SELECT COUNT(*) FROM topics ti, messages mi WHERE ti.boardid = b.boardid AND mi.topicid = ti.topicid) AS messagecount FROM boards b LEFT JOIN messages m ON m.messageid = (SELECT mii.messageid FROM topics tii, messages mii WHERE tii.boardid = b.boardid AND mii.topicid = tii.topicid ORDER BY mii.postdate DESC LIMIT 1) LEFT JOIN topics t ON t.topicid = m.topicid ORDER BY boardname ASC LIMIT $offset, $entries_per_page"; $rows = $this->db->clean($sql); foreach($rows as $row) { $rows['postdate'] = Forum::change_date(strtotime($row['postdate'])); $rows['boardname'] = ucwords($row['boardname']); $rows['topicname'] = Words::shortenText($row['topicname'],30); $rows['board'] = strtolower(str_replace(array(' ','\''), array('-',''), $row['boardname'])); } and this is the bit of the database class public function clean($sql, $fetchMode = PDO::FETCH_ASSOC) { $sth = $this->query($sql); $sth->execute(); return $sth->fetchAll(); } Hope you can helkp with this as it's driving me nuts
  23. I just looked and the array is the PDP query. With teh old mysql_query() way I would just do a while loop and do all the processing in there but while loops don't work with PDO so i need a foreach loop
×
×
  • 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.