
ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
How can I achieve this in OOP PHP the right way?
ignace replied to mds1256's topic in Application Design
I agree with AyKay. There is NEVER a good reason to use global, EVER! -
http://www.iconfinder.com/search/?q=hand There are other websites like this one out there. Good luck.
-
How can I achieve this in OOP PHP the right way?
ignace replied to mds1256's topic in Application Design
No, you don't. Compare the below versus your code. class NewsArticles { private $db; public function __construct(PDO $db) { $this->db = $db; } public function listLatest() { return $this->db->query('SELECT * FROM news LIMIT 5'); } } $articles = new NewsArticles($pdoInstance); foreach ($articles->listLatest() as $article) { echo $article['title']; } And ALWAYS separate your presentation (HTML) from your business logic. $smarty = new MySmarty; $articles = new NewsArticles($pdoInstance); $smarty->assign('articles', $articles->listLatest()); $smarty->render('template.tpl'); template.tpl <html> <body> {foreach $articles as $article} {$article.title} {/foreach} </body> </html> Or using PHP as a template engine: <html> <body> <?php foreach ($articles as $article): ?> <?=$article; ?> <?php endforeach; ?> </body> </html> The above is much cleaner then: <html> <?php require_once('functions.php'); require_once('news.php'); ?> <body> <?php functions::dbConnect(); $news = new news(); $newsresultset = $news->getNews(); while($row = mysql_fetch_assoc($newsresultset)) { echo $row['title']."<br />"; } ?> </body> </html> -
LOL. So true. Thx Philip.
-
MySQL will do just fine. Just be sure to define proper indexes.
-
I agree with RobertP, use a database. Optimize your queries with indexes.
-
Can you describe what you are trying to do? Why are you looping over 15 -> 600 and what do you mean by "all the way up to 600$ or if the max_Stars get's up to 80?"
-
You don't need the count_words function just use str_word_count like i showed you earlier.
-
Post your code. Why did you set the topic to solved if you are still having an issue?
-
No need to remove the punctuation, str_word_count is intelligent enough to know that punctuation is not a word. echo str_word_count($description);
-
I've heard phpfreaks.com to be quite good. Speedy responses! Overall friendly folks! Best not to feed .josh though Only after midnight, and keep him away from water ..in a bottle, with an alcohol percentage at the bottom.
-
I've heard phpfreaks.com to be quite good. Speedy responses! Overall friendly folks! Best not to feed .josh though
-
Using MySQL to create a High School Demerits Points System
ignace replied to ishvir's topic in MySQL Help
This topic is continued here: http://www.phpfreaks.com/forums/index.php?topic=354599.msg1675366 Please let this topic die! -
The table structure could be something like (not all fields are included): student (s_id, s_fname, s_lname) student_action (sa_id, sa_name, sa_demerits, sa_merits) student_log (sl_id, s_id, sa_id, sl_attributed_at) Where student, student_action, and student_log are all tables. s_id, sa_id, and sl_id are primary keys. Example rows would be: student table (s_id, s_fname, s_lname) 1, Foo, Bar 2, Baz, Bat student_action table (sa_id, sa_name, sa_demerits, sa_merits) 1, Late Sign In, 1, 0 2, Late Assignment, 2, 0 3, 3 month Merit earned, 0, 1 student_log table (sl_id, s_id, sa_id, sl_attributed_at) 1, 1, 1, 2012-02-27 2, 1, 2, 2012-02-27 3, 1, 3, 2012-02-27 As you can see, changing the number of merits/demerits an action accrues will be reflected in the student_log table. Thus changing the number of demerits for Late Sign In from 1 to 2 will increase the total for each line (for that particular action) in the student_log for a certain student. To easily create mysql tables you could use HeidiSQL or possibly your webhost already has PHPMyAdmin installed, which can be used aswell to create the tables. The query would be something like: SELECT s_id, sl_attributed_at, sa_name, sa_demerits, sa_merits FROM student_log JOIN student_action USING(sa_id) WHERE s_id = ? You would use PHP to total each line. This should be enough to get you started. Possibly you may want to add years (2012-2013) to the design. When a student is in his last year, you probably don't want to count the demerits/merits he caught his first year. Post any questions that you may have.
-
How did you make fire? The very fear of not being able to light up their cig forced them to invent the lighter.. no need for sticks.
-
What do you want help with? Do you have written any code? Please keep your question to one forum http://www.phpfreaks.com/forums/index.php/topic,354598.html Since it's probably about PHP keep it to this one.
-
Using MySQL to create a High School Demerits Points System
ignace replied to ishvir's topic in MySQL Help
What do you want help with? Do you have written any code? -
Kids these days aren't happy if it isn't an iPhone.. In my time we had sticks and stones, and we made chess pieces out of it. And then beat the crap out of the other kids with them, since none of us was smart enough to figure out what the pieces were for anyway.. Good times.
-
Prizes? Who needs prizes? I am in it for the glory! Something like a badge with the ratio of solved problems beneath my name will suffice That said, the challenges have to be open enough that everyone has a chance of solving it or are we really going to discriminate as a community and create A, B, and C groups? And it has to be done in any language supported on this forum. So Fizzbuzz in Python or Perl is a no-go. This should have a thread on it's own.
-
Want to learn OOP? Looking for some PHP Buddies
ignace replied to ChemicalBliss's topic in Miscellaneous
LOL. All you want to do is team up. And everyone here is advicing you to read books and tutorials... Me thinks people want to increase their post count.. You can always PM me if you have any OO related issue you want to discuss. Keep in mind though that, although I may sound like one, I am not an OO expert -
From Wikipedia: You are still using the PHP implementation for sessions (ie, the filesystem) also options like cache lifetime and such are missing. It's thus misleading.
-
http://bugs.mysql.com/bug.php?id=34665 See the response by "[4 Mar 2008 11:24] Martin Hansson" A viable alternative is: CREATE TEMPORARY TABLE temp ENGINE=MEMORY ( SELECT foo FROM bar WHERE bat = baz ) UNION ( SELECT foo FROM bar WHERE bat = baz ) Then SELECT * FROM temp INTO OUTFILE ... DROP TABLE temp; EDIT: SELECT * FROM ( (SELECT foo FROM bar) UNION (SELECT baz FROM bat) ) as dummy INTO OUTFILE 'foo.csv' Works equally.
-
Also the class name implies it's something it's not and your class actually violates SRP and the OCP principle. Since your class is responsible for both _SESSION and encryption of the data. Everytime the encryption of your session changes you have to go in the sessioncache class and change it, which is more prone to break existing code.
-
Now you made me curious, link?
-
Symfony2, Zend framework 2.0, .. Look for a framework that does not constrain your modeling in any way. To give an example in CI & CI2 you need to extend Model and call it through their Loader interface for it to work. That's a BIG no-no