KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
This is not the case in PHP 5, which supplies the user with the __autoload() function (http://us3.php.net/manual/en/language.oop5.autoload.php).
-
Without seeing their code, I can't really comment one way or another. I mean, I'm sure you could jury-rig some sort of foreach implementation, but it'd be beneficial to see their DB class(es) to see exactly how they did it. Echoing something like $p->id looks a bit dangerous on the surface as it implies that their class grants the user direct access to its properties, which is a pretty big no-no in OOP.
-
Okay, I got mine to work: Config.php: function __autoload($className) { $path = str_replace('_', DIRECTORY_SEPARATOR, $className); require_once("$path.php5"); } DEFINE ('HOST', 'localhost'); DEFINE ('USER', 'user'); DEFINE ('PASSWORD', 'password'); DEFINE ('MYDB', 'hockey'); MySQL: class MySQL { private $host; private $user; private $pass; private $dbName; private $dbc; private $dbSelected; public function __construct($host, $user, $pass, $dbName) { $this->host = $host; $this->user = $user; $this->pass = $pass; $this->dbName = $dbName; $this->dbConnect(); } private function dbConnect() { $this->dbc = @mysql_connect($this->host, $this->user, $this->pass); if(!$this->dbc) { echo "Cannot connect to the DB!<br />"; } else { $this->dbSelected = @mysql_select_db($this->dbName, $this->dbc); if(!$this->dbSelected) { echo "Cannot select the correct DB!<br />"; } } } public function isError() { if(!($this->dbc && $this->dbSelected)) { return true; } else { return false; } } public function query($query) { if(!$this->isError()) { $result = mysql_query($query, $this->dbc); return $result; } else { echo "Cannot return records from database due to connection failure.<br />"; } } } Client code: require_once('data/config.php5'); $myDB = new MySQL(HOST, USER, PASSWORD, MYDB); $query = "SELECT * FROM goalies"; $result = $myDB->query($query); if($result) { while($row = mysql_fetch_assoc($result)) { echo "{$row['first_name']} {$row['last_name']}<br />"; } } Some things to keep in mind if you're not familiar with PHP 5: Everything is implicitly pass-by-reference, which is why I don't put '&' when creating a MySQL object, among other places. __autoload() is a function available in PHP 5 that automatically fires when code attempts to instantiate a new object. It's typically used (like it is here) to automatically (and dynamically) load the needed class files when an object of that class is trying to be created. It saves the coder from having to keep track of what class files have been included/required. PHP 5 has real data access control (public, protected, private). PHP 5 has other OOP benefits as well (interfaces, abstract classes/methods, special functions (__construct(), __destruct(), etc.)).
-
I'm running into the same issues as you with a test script I've written. I think it's some sort of hosting issue, as my version of the MySQL class is getting the login info from the included file (I verified this by echoing the values from inside the class itself), and I can access the db from phpMyAdmin just fine using the same info. I'm waiting to hear back from my host on this. In any event, you asked for some good OOP books, so here's a couple: PHP 5 Objects, Patterns, and Practice by Matt Zandstra: http://www.amazon.com/PHP-Objects-Patterns-Practice-Second/dp/1590599098/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1215888164&sr=1-1 Design Patterns: Elements of Reusable Object-Oriented Software by the Gang of Four: http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1215888192&sr=1-1
-
Hmm.... remove the '@' from your DB connect/select statements and show me the errors it reports, if any.
-
Well, no matter what you do, you're going to have to send the DB connection info to the MySQL class' constructor. There's really no getting around that as PHP has no real concept of state. The reason why the book repeats the info is to illustrate its use. In a real version, you'd probably see something like... Connection.php: $host = 'localhost'; $user = 'user'; $pass = 'pass'; $db = 'db'; Main code: require_once('connection.php'); myDB =& new MySQL($host, $user, $pass, $db);
-
Mind showing what connection.php is, if you haven't already? Because so far you've given two classes and one example, which didn't illustrate your problem. At the very least, mind writing an example with two queries so I can see this duplication? And DarkWater is right. PHP 4 isn't nearly as good as PHP 5 for OOP. It's an 8 year old version that's no longer supported by Zend. If they're not supporting it, you shouldn't want to if you have a choice about it.
-
From the code provided, I don't see why you'd need to send the DB connection info more than once (creation of the DB object). Is there something I'm just being dense about? Because I don't see why you'd need that info for each individual query.
-
You are right. Unless you're in an environment using Magic Quotes.
-
Eh, it's just another PHP-Fusion site. They all look more or less the same. Unfortunately, what custom work you did do (most notably the top-level navigation bar and login section) is pretty ugly. Big, flat gray buttons just don't look good. Another thing that caught my eye is the repeating background gradient. Very annoying. This is caused by the sheer number of news items you have on the front page. It's been a while since I used PHP-Fusion (and I used version 6.xx), but there's probably a setting you can use to limit the number of news items shown on the front page. I wouldn't show more than two, given the average size of the posts. There's no reason to force your visitors to scroll down a mile just to leave a comment, and it should fix most of the repeating background issues.
-
Hmm... wouldn't g_objName already be available to you in grab()? You're assigning the function to the onmousedown event handler of newObject. Since g_objName is a property of newObject, it should be available inside of grab() as this.g_objName.
-
Yes, it's possible. The most simple way to do it is to have an 'Edit/Delete' input button associated with each result. How this association is formed depends on how the items you want to modify are structured. Once this button is clicked, it brings the user to an editing page which puts the data in form inputs that the user can modify. Here there should be two more buttons: 'Save Modifications' and 'Delete Record'. When 'Save Modifications' is clicked, the data in the form fields is updated in the DB. When 'Delete Record' is pressed, the record is deleted from the DB. There are other ways to get at the records...I've used checkboxes to specify multiple records to be edited/deleted. It's not much harder to implement, once you get the basics down. Can you work from here, or do you need to see some code?
-
The header is okay. Just make sure that the circles don't interfere with the text. Yeah, the dashed outlines are pointless and distracting. Ditch 'em. I'm not a fan of the size of the drop-down navigation links. I have a thing for uniformity, so I think their width should be the same as the element they're stemming from.
-
I would like to see it. You may want to send it via private message, though, depending on the size of things.
-
For animation like that, I suggest using Flash. Then again, I'm hardly an animation expert, seeing as I have the artistic ability of a blind gnat. Regarding JavaScript itself, a good rule of thumb is to never rely on JavaScript in order to get your site to function. JavaScript should be used to enhance already existing functionality. The heavy lifting should be done on the server. I say it all the time, but as you're learning JavaScript, do so with an eye towards unobtrusive JavaScript. This means keep your script entirely separate from your markup. Things like: <body onload="somefunction()"> are bad, as it couples your script to your markup. Separating them increases readablity, improves maintenance, and saves you from many future headaches. It's considered to be best practice and is generally considered the professional way of doing things.
-
Page 1: <a href="page2.php?item=socks">Page 2</a> Page 2: $socks = $_GET['item']; . . . echo "<input type='hidden' value='$socks' />"; That should be the gist of it.
-
Hmm...I don't see much difference between using a decorator and doing what ID did. I mean, in Q3, each weapon has concrete properties which are modified by a power-up, or if the user is using the mission pack. They have the benefit of hard-coding these attributes directly as they only had, what, 10 weapons and a few power-ups? Since I'm making an RPG, where loot is important, I think that item/weapon creation flexibility is paramount. Modifyers/multipliers are still in play, but in order to come up with a loot algorithm, I think I'd want to be able to create new item combinations on the fly. In other words, killing Generic Goblin #1 gives the player a 45% chance of obtaining a sword. What kind of sword is calculated further...maybe a 70% chance of a short sword, and a 2% chance that it has some minor magical property. So, after my calculations, I could simply write: abstract class Sword {} abstract class SwordDeco extends Sword { protected $sword; public function __construct($sword) { $this->sword = $sword; } } class ShortSword extends Sword {} $player->attack($goblin); if(isDead($goblin)) { //calculate loot...in this case, $player receives a new short sword $player->obtain(new $loot()); } Obviously, this isn't fleshed out at all, but the general idea is there. Does this seem like the right way to go? The other (and probably more efficient) way to go would probably be to have a loot database that my script can look-up once a monster is killed. My only concern with that is having a ton of inflexible child objects that are referenced by the DB. It just seems inelegant to do that.
-
Here's a question: which package is the best for learning real-world OOP by diving into the source code? By this, I mean well documented code, with clear, concise classes? I've tried learning by dissecting CI, but it all gets a bit confusing. Being able to follow the actual process of obtaining and rendering a page in detail (i.e. index.php -> something else.php -> ... -> view.php) would be a great help. The general flow chart is good, but things get muddled (in my mind's eye, anyway) when trying to match the chart to the actual classes. I just want to be able to sit down with a nice, lightweight bit of PHP 5 framework code to dissect and learn from.
-
Hmm..doesn't emacs or vim provide highlighting? In Windows-land, I use Notepad++. It has text highlighting and indent matching (I'd insert the image directly, but it breaks h-scroll): www.nightslyr.com/notepad.jpg
-
Your if-statement doesn't have an opening brace. Use: $allowedPages = array('home', 'contact', 'about', 'artists'); for($i = 0; $i < sizeof($allowedPages); $i++) { if($_GET['where'] == $allowedPages[i]) { include $_GET['where'] . '.php'; } else { echo "Page not found or allowed."; } } Just so you know, your code will echo "Page not found or allowed." if your $_GET value is anything other than 'home.' So, if the 'artists' page is accessed, that error message will appear three times.
-
So, something along the lines of my decorators' functions? Or something (and most likely) more complex than that?
-
Thanks, looks like a few google/wiki searches for those patterns and the code you mentioned are in order! Ninja Edit: Unfortunately, neither Google nor Wikipedia have info on those two patterns you mentioned, at least, none that I can see. I am downloading the Quake III source code now.
-
Aside from the layout...issues...you should also rewrite some of the text on your site. A lot of it comes across as very amateur. Grammar errors, conversational tone, vague, bland descriptions...it's all very pedestrian. How long have you been in business? Any good press you can share? Any big-name clients in the local area you can mention? Are any of you certified? How many years of experience, combined, do you have? What Linux distros are you proficient in addressing? Can you handle Apache web servers? Can you configure Postfix? If you're offering 'World Class' service, you have to convince your potential customers that this is really the case and that you're not just blowing smoke up their asses. After all, any idiot can download Ad-Aware, AVG, etc and run a few scans. What makes you different, and worth people's hard-earned cash? I'm not trying to be harsh, but having worked for a computing-solutions company that promised puppy dogs and ice cream-farting unicorns to our customers while hardly ever actually fulfilling those promises, I tend to look at small IT maintenance companies with suspicion.
-
Problem sending form results to form owner
KevinM1 replied to jackofalltrades's topic in PHP Coding Help
Are you talking to me or the OP? Because I showed them how to do it using an array. -
Problem sending form results to form owner
KevinM1 replied to jackofalltrades's topic in PHP Coding Help
Shouldn't it be: <input type="checkbox" name="choice[]" value="choice1waschosen" />red</label> . . . $choice = $_POST['choice']; . . . $selected = ''; foreach($choice as $value) { $selected .= "$value, "; } $selected = substr($selected, 0, -2); //get rid of the trailing ", " EDIT: small syntax error