Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
Try: $funcName = 'imagecreatefrom' . $this->ext; $funcName($this->file);
-
I don't know if they are going to remove the global keyword, but I hope so. Screw backwards compatibility. People will just have to learn to write better code and burn for having slacked.
-
inserting into an array at specific position
Daniel0 replied to severndigital's topic in PHP Coding Help
Has a higher space and time complexity though. Might not matter depending on the problem size. -
You really should read the manual. <?php $ble = "SELECT topic_id FROM newreplies WHERE user = 'admin' and viewed = '0' "; $res = mysqli_query($cxn,$ble) or die (mysqli_error($cxn)); // <-- read the link in my signature regarding this $list = array(); while ($row = mysqli_fetch_assoc($res)) { $list[] = $row; }
-
It depends on how you code it. A framework will always have a larger overhead that just plain code. <?php echo 'Hello World'; will for instance always be faster than the simplest ASP.NET hello world thing. Then there is the issue of configuration and hardware. It's difficult just blanket stating that either is the fastest.
-
You'll still only execute the query once even if you call the fetch function multiple times. You are passing a resource to the fetch function that already contains information about the things that the query returned. Just create an empty array before the loop and add each $row to the array.
-
inserting into an array at specific position
Daniel0 replied to severndigital's topic in PHP Coding Help
That would be the easiest. -
Would it be safe to use underscores then? How about dots? I need a seperator in addition to dashes. Guess what? Separators were already addressed once in this excruciatingly long topic. A stunning two pages! How will I ever manage to work through all that text? And on top of that, having to watch a one minute long video, which was linked to, that also explains it!
-
Well, yes it is, but did you READ the page I linked to? mysqli_fetch_assoc() returns the next row in the result set. If you only call it once, you'll only get the first one. It returns false when there are no next row. So what you want to do is to call it as long as it doesn't return false? How do we do that? Well, as you no doubt will have read in the manual, there is a control structure called a "while loop" that keeps running as long as its condition evaluates to true. So what we do is: while ($row = mysqli_fetch_assoc($res)) { // here we will keep selecting the next row and assign it to $row as long as a such next row exists // do stuff with each individual $row here } You know what? That looks surprisingly similar to what they proposed in one of the examples on the manual page for mysqli_fetch_assoc(). Reading the manual really answers a lot of questions. Who would have known that the manual tells you how to use it
-
error_reporting should at all times be set to at least E_ALL. If you don't want errors to show up on the screen you should set display_errors=Off There is a reason why I also linked to this tutorial. It covers error reporting and what you should do with it.
-
See: http://www.phpfreaks.com/tutorial/php-security http://www.phpfreaks.com/blog/or-die-must-die
-
What do you want to replace it with? You can just use str_replace
-
mysqli_fetch_assoc <-- read that
-
Copyright doesn't run out just like that no matter what the text says, does it? No, not really. It doesn't run out until 70 years after you've deceased. Writing stuff like "Copyright © 2009 me" is redundant. It's copyrighted regardless.
-
That's not necessarily a good thing in the grand scheme.
-
It depends on what you offer. If you are running a site that is graphically intensive or you offer downloads you'll obviously use more disk space and bandwidth than a site like this one, which is largely text based.
-
How can I set a cookie the first time page loads?
Daniel0 replied to smiley_kool's topic in PHP Coding Help
Cookies are only available on the next request. I suppose you can create a wrapper class around it to handle it. <?php class CookieJar implements ArrayAccess { static private $_instance; private $_cookies = array(); private function __construct() { $this->_cookies = $_COOKIE; } static public function getInstance() { if (!self::$_instance) { self::$_instance = new self(); } return self::$_instance; } public function getCookie($name) { if (!$this->offsetExists($name)) { return false; } else { return $this->_cookies[$name]; } } public function setCookie($name, $value, $expire = 0, $path = null, $domain = null, $secure = false, $httponly = false) { setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); $this->_cookies[$name] = $value; return $this; } public function offsetExists($offset) { return isset($this->_cookies[$offset]); } public function offsetSet($offset, $value) { $this->setCookie($offset, $value); } public function offsetUnset($offset) { setcookie($offset, false, time() - 3600); unset($this->_cookies[$offset]); } public function offsetGet($offset) { return $this->getCookie($offset); } } $cookies = CookieJar::getInstance(); $cookies['foo'] = 'bar'; // set a cookie unset($cookies['foo']); // remove a cookie $cookies->setCookie('bar', 'foo', time() + 3600); // set a cookie with custom parameters echo $cookies['bar']; // get a cookie Note that this is one of the very few cases where the singleton pattern is warranted. -
How can I set a cookie the first time page loads?
Daniel0 replied to smiley_kool's topic in PHP Coding Help
http://php.net/manual/en/features.cookies.php setcookie -
Well, obviously you have to manually delete it from the database somehow. There is no inherent relationship between PHP's object model and database entries. You'll have to establish that relationship yourself. However, do note that using the code you did it is impossible to store anything permanently in the database; each object is destructed during garbage collection at the end of the script execution.
-
Already solved it for him in another topic: http://www.phpfreaks.com/forums/index.php/topic,263568.msg1243201.html#msg1243201
-
Of course not. Physical access is the same thing as full access. If you want your stuff to be secure you'll have to encrypt it.
-
What's the first word of a newspaper article called? e.g. NEW YORK -
Daniel0 replied to TheFilmGod's topic in Miscellaneous
Location? -
Of course it's almost always a matter of the specific requirements of the application. That is one of the things you must consider in the design phase of software development.
-
It doesn't convert anything back. It IS an ampersand. & in the source means & in "reality" -- whether you post it or display it on the screen.
-
http://php.net/types.array Read that and then throw out your book or find a newer tutorial if that's what you're using.