KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
Show us your code so we can see if there are any differences between it and the tutorial code.
-
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=357414.0
-
You can't mix a normal if (/*something*/) { with an endif;
-
This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=357368.0
-
Cookies can work as they're a language agnostic technology. You can set them in one language and read them in another.
-
Have you tried looking up what a tinyint is in MySQL? Seriously, it's faster for you to do 30 seconds of research on something like this than to wait for someone else to provide you the answer.
-
please could you comment on my comments OOP beginner!
KevinM1 replied to wright67uk's topic in PHP Coding Help
@wright67uk, you're on the right track. From a design standpoint, however, you'll be better off labeling your properties as private and accessing them through public methods where necessary. One of the main points of OOP is encapsulation. Data should be encapsulated within an object, accessed from the outside through clear and explicit means. Leaving properties public destroys encapsulation, allowing them to be changed at a whim. -
...what do you mean by 'PHP builder'?
-
This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=357345.0
-
Yes. You'll need to research how their db access code works, and whether or not accessing a remote db is a better option than using a small db you can bundle with the app itself. There are lightweight mobile dbs available that are used in the cases when you don't need to share the data among multiple applications (like, say, a website and a standalone app).
-
Do you actually need a standalone app, or just a mobile website? Apps require that you create an executable that can be run on the phone/tablet itself, which is written in one of three languages: Objective-C for iOS/Apple products (iPhone/iPad) Java for Android C# + .NET, and maybe Silverlight for Windows Phone 7 Now, a mobile friendly site can be written in any language(s) you want, but you'll be limited with an actual on the metal/in the CPU app.
-
How to use html form and php to delete selected values from database?
KevinM1 replied to garvit184's topic in PHP Coding Help
Go with what I bolded. There's no need to use JavaScript for this. -
You're confusing yourself because the class code is written in PHP 4 syntax (the var keyword). That leads to the $sTime member variable being public, and, since you also have an $sTime local variable in play, things are getting muddled. Use PHP 5 syntax instead: class Time { private $sTime; function GenerateCurrentTime() { $this->sTime = gmdate("d-m-Y H:i:s"); //assign the current date to the sTime variable } function ShowFutureDate($iAddDays=0) { $this->sTime = gmdate("d-m-Y H:i:s", strtotime("+" . $iAddDays . " days")); } } That might make things more clear. Also, get this book: http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X/ref=sr_1_1?s=books&ie=UTF8&qid=1333840120&sr=1-1 Finally, -> does not mean 'parent of'. I don't know where you got that idea, but it's wrong. -> is the 'to member' operator, meaning that with $oTime -> GenerateCurrentTime(), you're accessing the member function/method named GenerateCurrentTime of the Time object referenced by the variable $oTime.
-
What are you currently doing for form sanitation? Are you using mysql_real_escape_string anywhere?
-
PHP is a template engine itself. All that other engines do is add syntactical sugar on top of it. Unnecessary, IMO.
-
This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=357178.0
-
I have a feeling about where this may be going. The key to a database like MySQL is that it's a relational database. Trying to use it like a gigantic spreadsheet is exactly the wrong way to go about it. Instead, you need to create tables that model how the data is actually related. This is done by a process called 'normalizing'. A good introduction to database normalization can be found here: http://mikehillyer.com/articles/an-introduction-to-database-normalization/ You want to design your tables first, then add data to them. Your tables should remain static during that process (so, no adding actual table columns like you alluded to above). I hope this helps.
-
The point of the Singleton Pattern is to create a global that can only be created once. By now alarms should be going off. It's unfortunate that the Singleton is usually presented as the first pattern, because it's hardly ever a good idea to use it. It's really an anti-pattern - something that looks neat and beneficial, but often winds up causing some form of damage it was meant to prevent. Really, you'd be better off forgetting about the pattern and learning something useful like the Factory Method or Composite Pattern. I'd say that 8/9 times out of 10, when someone thinks that using a Singleton is the best way to solve a problem, they should actually use Dependency Injection instead.
-
First, like batwimp said, don't have a constructor and a function with the same name as your class. Second, you can't echo a mysql result directly. You need to fetch the data from the result. Rewritten class: class getData { private $name; private $email; private $text; // bad idea to just hard code these in private $host = 'localhost'; private $uname = 'root'; private $pword = '1111'; private $dbname = 'teststorage'; private $dbtable = 'userData'; function returnData($name, $email, $text){ $this->dbconnect = mysql_connect($this->host, $this->uname, $this->pword); if (!$this->dbconnect) die("Connection Unable " . mysql_error()); mysql_select_db($this->dbname); $sql_query = "SELECT * FROM $this->dbtable "; $result = mysql_query($sql_query); return $result; mysql_close($sql_query); } } $dataAccess = new getData(); $results = $dataAccess->returnData($name, $email, $text); if ($results) { while($row = mysql_fetch_assoc($results)) { // echo the results row-by-row } } else { echo "Could not retrieve data."; } Not the ideal solution, as it relies on hard coded info, but it should give you an idea of how to go about it. Note that there isn't a dedicated constructor method. I figured that since you're hard coding the db info, there wasn't a need to make a dedicated constructor for it. You'll need to do further testing on this, as I wrote it off the top of my head.
-
A discussion on style != a coding help question. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=356946.0
-
Microsoft teaches its developers to code that way. Not really. At least, not in any of the MS related material I've encountered (which is sizeable, since I've been writing more C# than PHP lately). That style, FWIW, is called Hungarian Notation. It's not very popular. As far as array names go, I'd strongly advise NOT ending them with 'List'. A list is an actual data structure in other languages, and as such, implies certain things. I tend to pluralize my array names, as they contain multiple elements of related data.
-
Suggest projects for beginner php programmer?
KevinM1 replied to christomax's topic in Miscellaneous
How about a basic comment system? It will teach you: Form handling Database creation and usage And, if you're willing to go a bit further, user registration and login -
Making a text adventure in PHP-very basic/beginner
KevinM1 replied to DeadlyAzn's topic in PHP Coding Help
Instead of using numbers for the second dimension, why not a string? $rooms[0]['name'] is a lot more descriptive than $rooms[0][0], which implies a classic 2D array setup. -
Making a text adventure in PHP-very basic/beginner
KevinM1 replied to DeadlyAzn's topic in PHP Coding Help
Exactly. Attempting to create something that works with this many moving parts (how should a room be represented? its items? its exits? player position?) when you don't know the bare bones basics of the language, and with a two week deadline, is just going to end in tears. Do something simple. Create a small guestbook or something that addresses the basics of form handling, database insertion/retrieval, and user registration/logins.