Jump to content

TrickyInt

Members
  • Posts

    16
  • Joined

  • Last visited

  • Days Won

    1

TrickyInt last won the day on May 4 2014

TrickyInt had the most liked content!

TrickyInt's Achievements

Newbie

Newbie (1/5)

5

Reputation

  1. Then go ahead and learn it. You will have a hard time finding someone willing to program for you without paying. Besides, it's great to know a programming language - and also fun and interesting to learn.
  2. Instead of using strlen() you should use isset() because it's way faster. Use it like this: if(isset($var[11)) { echo 'String is more that 10 chars'; }
  3. Well, maybe you should go ahead and learn a little about it then? There are plenty of ressources - and it's very well worth it. http://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762
  4. Have you a way to store/save users "cart"? If not, you could save the ID of the items, in an array, which you save in the users session. Then you could go through all the ID's in the array, to quickly show everything. When deleting you could use the array search function, perhaps? <?php session_start(); // Item ID's in cart $_SESSION['cart'] = array('1', '3'); $cart = $_SESSION['cart']; // Add new item to cart array_push($cart, '4') // This adds 4 to the end of array so cart now contains 1, 3 and 4. // Remove item if(($key = array_search('3', $cart)) !== false) { unset($cart[$key]); } else { // Not found in cart } // Go through all items in cart if(count($cart) > 0) { foreach($cart as $id) { // Do something with the item id.. } } ?> I haven't tested the code above, so it's probably either not working, or just bad. But it can give an idea/starting point. Good luck
  5. Hi! It's actually pretty easy to be making such, if you know how to make a login/register system. If you can't/never made a login/register system, then learn it - and then make the other. 2 tutorials: http://www.sunnytuts.com/article/login-and-registration-with-object-oriented-php-and-pdo - Easy and short. Bad security, but great for starting out. - Great and advanced tutorial.
  6. Yeah, especially if you have no programming knowledge prior to this. It really makes life easier, when learning new languages. You would also lack in experience, if learning it so fast. If only one could cope/paste experience...
  7. Jacques1: The PDO one could also be done like this: <?php $books_stmt = $database->prepare(' SELECT title FROM books WHERE author = ? AND EXTRACT(YEAR FROM publication_date) = ? '); $books_stmt->execute(array($author_id, $publication_year)); foreach ($books_stmt as $book) { echo html_escape('The title of the book is ' . $book['title']); } ?> I'd go with PDO over MySQLi. I was too using the old Mysql_*, and just started learning PDO 2 weeks ago. I swiched to PDO, afted trying MySQLi. I found MySQLi to be harder to learn, and with less and worse tutorials. And Jacques01, this: "I think people only do it because the name sounds familiar." is very true. Did that myself
  8. Ahaha, yeah, your right. I'm tired.
  9. Couldn't you do something like: <?php while($_POST['cartquantity'] > 0) { $_POST['cartquantity']--; $_SESSION['cart']['weight'] += $row['weight']; } ?>
  10. Thank you, ignace, just what i needed!
  11. Indeed. But this approach might be efficient. Or it may not. I don't not, thats why I'm asking - I haven't got any experience. (Not talking OOP and PDO in general, just creating a DB class)
  12. Hey. Just recently got into developing with PDO and OOP, instead of the old MySQL_*, so I'm pretty new, and have some dumb questions. Right now I'm taking the first steps into making a blog (Nope, not a blogger - just need something to work on), and i came across a tutorial to create a database class. I have spend a little time on making such a class, and though I got it working just fine, I'm not really sure how useful and necessary it really is. Yeah, of course it saves you a couple of lines, but at the cost of getting used to using the class, instead of just raw PDO. Here is the class i just quickly made: <?php class database { private $host = DB_HOST; private $user = DB_USER; private $pass = DB_PASS; private $dbname = DB_NAME; public function __construct() { // Try connection or die. try { $this->db = new PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->user,$this->pass); } catch(PDOException $e) { die($e); } } public function getColumn($sql, $params) { // Get value of a single row $query = $this->db->prepare($sql); $query->execute($params); return $query->fetchColumn(); } public function fetch($sql, $params) { // Return fetch $query = $this->db->prepare($sql); $query->execute($params); return $query->fetch(); } public function update($sql, $params) { // Update $query = $this->db->prepare($sql); $query->execute($params); } public function getRows($sql, $params) { // Return number of rows $query = $this->db->prepare($sql); $query->execute($params); return($query->rowCount()); } public function insert($sql, $params) { // Insert $query = $this->db->prepare($sql); $query->execute($params); } } ?> I know it can get way more optimized, advanced and usefull, but it's just a quick example. Is it just dumb to spend time on a database class, or is it worth the time? Any advice appriciated. Thanks in advande!
  13. You haven't Session_start() on your login.php page, neither on your auth_check.php page - so it cannot access anything from it. Maybe you should just add session_start() in your common.php file, if it's included at the top of every other page/file? Good luck
  14. Your example would be pretty bad, if you just have a while to go through all posts made, and show them on for example your frontpage - then it would both show the new and old version of the post. You could add a new table, for history posts, or you could add a new column in your existing table, called something like post_history, and then only, on your frontpage, show post where post_history == 0.
  15. PDO is also viable. I personally found it easier to learn.
×
×
  • 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.