Jump to content

scootstah

Staff Alumni
  • Posts

    3,858
  • Joined

  • Last visited

  • Days Won

    29

Everything posted by scootstah

  1. The only data in the cookie is the session ID. Not sure why you would want to change that with Javascript.
  2. $_SESSION itself is an array, but its keys do not have to be arrays.
  3. PHP is loosely typed, so you do not have to cast one type to another to assign a variable.
  4. Except that yours has infinite queries, mine has one.
  5. To illustrate what AyKay said... // this is incorrect $array = 'blah'; $array[] = 'more blah'; $array[] = 'even more blah'; // this is correct $array = array(); $array[] = 'more blah'; $array[] = 'even more blah';
  6. Okay. And?
  7. It doesn't show the same time for me. The second is 24 hours after the first.
  8. Maybe this will be of some help: http://winscp.net/eng/docs/guide_automation
  9. Okay, for one level deep the following should be what you want. First, restructure your database to be one table. Two tables isn't needed. I used the following: -- -- Table structure for table `categories` -- CREATE TABLE IF NOT EXISTS `categories` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parent_id` int(10) unsigned NOT NULL DEFAULT '0', `name` varchar(100) NOT NULL, `image` varchar(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ; -- -- Dumping data for table `categories` -- INSERT INTO `categories` (`id`, `parent_id`, `name`, `image`) VALUES (1, 0, 'cars', ''), (2, 1, 'ford', ''), (3, 1, 'toyota', ''), (4, 1, 'chevrolet', ''), (5, 0, 'computers', ''), (6, 5, 'dell', ''), (7, 5, 'hp', ''), (8, 5, 'sony', ''); You can import that directly into your database if you like. Then, the following code to create the nested UL's: <?php $mysqli = new mysqli('localhost', 'root', 'root', 'test'); $query = 'SELECT id, parent_id, name, image FROM categories'; $result = $mysqli->query($query); if ($result->num_rows > 0) { $categories = array(); while($row = $result->fetch_assoc()) { if ($row['parent_id'] != 0) { $categories[$row['parent_id']]['sub'][] = $row; } else { $categories[$row['id']] = $row; } } echo '<ul>'; foreach($categories as $cat) { echo '<li>'; if ($cat['parent_id'] == 0) { echo $cat['name']; } if (isset($cat['sub']) && is_array($cat['sub'])) { echo '<ul>'; foreach($cat['sub'] as $sub) { echo '<li>' . $sub['name'] . '</li>'; } echo '</ul>'; } echo '</li>'; } echo '</ul>'; } else { echo 'There are no categories'; } EDIT: Changed if (is_array($cat['sub'])) { to if (isset($cat['sub']) && is_array($cat['sub'])) {
  10. How deep are these subcategories allowed to be?
  11. I can only imagine that this if( isset($_GET['l']) && languageIsAvailable($_GET['l']) ) is supposed to be this if( isset($_GET['lang']) && languageIsAvailable($_GET['lang']) )
  12. Instead of just value="<?php echo $fname; ?>" , do this for each one value="<?php echo isset($fname) ? $fname : ''; ?>"
  13. Or a little less ugly: <?php echo isset($fname) ? 'checked="checked"' : ''; ?>
  14. If you don't see the problem with Singletons and how they can be misused then you should stop right there and go read up on it. Most of the time, Singletons are as bad as globals. They break encapsulation and make it nearly impossible to unit test. Whilst I agree it can be over complicated for some jobs I would not remove the model. I only say this because of experience. By removing the model you are no longer object oriented and you require the controller which does a load of template stuff you don't need. It defeats the purpose. Arguably its dependant on how our using the MVC concept but the point still stands. For simpler jobs I would look into an entirely different method which better suits my requirements. Using MVC doesn't determine if something is object oriented or not. Removing Models is still object oriented, it is just a more simple pattern. What do you mean the controller is doing loads of template stuff? I have a template library, template calls are one line.
  15. Clearly, the conditions are not being met to create them. Check your $row data to make sure it is what it should be. Also, above your loop you can just set all of these variables to an empty value, like $fname = ''; so that if they aren't set to a proper value later, they will still be defined.
  16. I just wanted to point out that while MVC is a great pattern, keep in mind that you can deviate from it a bit. For small applications, strict MVC may be a little overkill. Often times for small stuff, I'll knock out the Model portion of MVC and just use my Controllers for everything, while still being able to easily break business from presentation. If you don't see the problem with Singletons and how they can be misused then you should stop right there and go read up on it. Most of the time, Singletons are as bad as globals. They break encapsulation and make it nearly impossible to unit test.
  17. Something like $query="SELECT * FROM NEW WHERE lang = '$_lang' AND visible = '1' ORDER BY sort DESC"; $result = mysql_query($query, $conexion); while ($row = mysql_fetch_array($result, $result_type = MYSQL_NUM)) { echo '<pre>' . print_r($row, true) . '</pre>'; }
  18. I was thinking using a cron job to run a PHP script with FTP commands. But, you're right, if you're going that route PHP probably isn't the best option.
  19. I've tried with IE, Firefox and Chrome (on Win7) and none of them show a news article. Perhaps the reason you can on one browser is because it is cached? I would check that you are actually getting data from the database.
  20. <hr> isn't deprecated, it's just different. Instead of a horizontal rule it is now a "paragraph-level thematic break". I never said <hr> was depreciated, just that the color attribute for it was... Ah, my bad then.
  21. Well for one, you should only have one database column for date of birth. Make it of DATE type. This way you can easily work with the data and it makes queries easier. Secondly, what does your age field look like?
  22. I'm sure you could use a cron job to do both of these tasks.
  23. <hr> isn't deprecated, it's just different. Instead of a horizontal rule it is now a "paragraph-level thematic break".
  24. I just tested a bunch of doctypes and got the following results: HTML5 Accepts both <hr> and <hr /> HTML 4.01 Transitional Throws warning with <hr /> HTML 4.01 Strict Throws error with <hr /> XHTML 1.0 Transitional, Strict, and XHTML 1.1 Throws error with <hr> Nifty. I always thought the ending tag was optional for HTML 4.01.
  25. You are supposed to close it, like this: <hr class="red" /> So what exactly is not displaying properly? Is your site live so we can see it? If not, can you post screenshots of the results and the expected results?
×
×
  • 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.