Jump to content

Pain

Members
  • Posts

    178
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    London, UK

Pain's Achievements

Regular Member

Regular Member (3/5)

1

Reputation

  1. Hello. Been programming OOP for the past year. I am very ashamed to admit that I have not learned about exceptions yet. Well actually Im not sure... Am I using them correctly? public function indexAction(Request $request) { try { if(!is_object($request)) throw new \Exception('Param msut be an object'); } catch(Exception $e) { $this->logger = $this->get('logger'); $this->logger->info("You have the following error: { $error }", array("error" => $e->getMessage())); } } I throw an exception in order for the error to appear on the screen. Then I catch the error and log it. Is this the correct usage? Or is there more? Thanks!
  2. I have implemented this slider http://kgperazim.com/test/film2 , however I'd like my header and footer to stay on screen whenever I'm scrolling horizontally. What would be the best solution to do that with css? Thx for any advice.
  3. Thanks for your effort. I have solved it by doing this: <?php $php_cities_array = array('smth', 'smth2'); function js_str($s) { return '"' . addcslashes($s, "\0..\37\"\\") . '"'; } function js_array($array) { $temp = array_map('js_str', $array); return '[' . implode(',', $temp) . ']'; } $array = 'var availableTags = ' . js_array($php_cities_array) . ';'; ?> <script> <?php echo $array; ?> </script>
  4. Not really, it is pre-populated with values
  5. It's just this one variable - var availableTags = []. it is used in a script later on.
  6. Hello. I was wondering how can I add a php array to a js array containing json values. var availableTags = [ "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ]; I want to add this to the js array: <?php $arr = array('red', 'green', 'blue'); ?> I've tried doing this, but its definitely the wrong approach as it just sums everything up into one element "redgreenblue" var availableTags = [ "<?php foreach($arr as $row) { echo $row; } ?>", "AppleScript", "Asp", "BASIC", .... Thanks for any kind of help!
  7. Hi. I am fairly new with cURL. I have a URL like example.com/index.php?something=value&somethingtwo=valuetwo How can I get those values and print them out? I've got this code, but have no idea what to do next, please help guys! <?php function get($url, $params=array()) { $url = $url.'?'.http_build_query($params, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); return $response; } // Sample call echo get('https://www.example.com/index.php', array('something'=>'value', 'somethingtwo'=>'valuetwo')); ?>
  8. Hi. I'm curious what settings/other things are people usually defining to make their lives a bit easier (i'm talking about constants)? And if possible please give an explanation (why is it useful to define a particular constant). As you can see my list is nothing special, therefore I'm looking forward to hearing what you have to say. ... define("DB_HOST", "localhost"); define("DB_USER", "user"); define("DB_PASS", "pass"); define("DB", "db_name"); define("BASE_URL", "http://www.something.com"); ... Thanx:)
  9. Thanks for the reply. It works, thank you. However this code should be inside a class and i don't want my class to echo. I want to use these variables on another page. So if I have something like this in my class: $i = 0; while ($row = $qstmt->fetch(PDO::FETCH_ASSOC)) { $email[$i] = $row['email']; $testname[$i] = $row['name']; $testlastname[$i] = $row['lastname']; $i++; } How would i echo out $lastname[5] or any other random variable. So far i've got this :/ require_once('connect.php'); require_once('class/profile.php'); $profile = new Profile($db); echo $profile->testGetAll();
  10. Thanks for the answer. When i retrieve those values from the db like this: $i = 0; foreach($profile->testGetAll() as $value[$i]) { $value[$i]; $i++; } i get a big bunch of rows. How can i assign a variable to each row? $name would be name, $lastname would be lastname etc
  11. Hello, i need some help with pdo. I'm struggling while trying to echo out all results. class Test { public $testName; public $testEmail; public $testLastname; public function testGetAll() { $query = $this->db->prepare('SELECT * FROM customers'); $query->execute(); $this->testEmail = $data['email']; $this->testName = $data['name']; $this->testLastname = $data['lastname']; } }
  12. Hi. Well since you are a beginner I recommend doing this. Retrieve info from the database. Lets say 'id'. Then your first line of the form should be something like this: <form name="form1" action="profile.php?id=<?php echo $id; ?>" method="POST" /> Then in your profile.php get that id from the URL by doing this: $id = $_GET['id']; Now you can use 'id' in WHERE clause and retrieve info from the database (that belongs to this id). Note: this is a bad practice, you should not use this in the future, however this might help you understand a bit more PHP.
  13. I have a question regarding setters and getters. Why most people use a separate setter for each property? public function setTitle($title) { $this->title = $title; } public function setDescription($description) { $this->description = $description; } public function setPostcode($postcode) { $this->postcode = $postcode; } public function setPicture($picture) { $this->picture = $picture; } public function getTitle() { return $this->title; } public function getDescription() { return $this->description; } public function getPostcode() { return $this->postcode; } public function getPicture() { return $this->picture; } Why not just do this? public function setDetails($title, $description, $postcode, $picture) { $this->title = $title; $this->description = $description; $this->postcode = $postcode; $this->picture = $picture; } public function getTitle() { return $this->title; } public function getDescription() { return $this->description; } public function getPostcode() { return $this->postcode; } public function getPicture() { return $this->picture; }
  14. I'm sorry I should've been more clear on this. Each email has to be different. Please take a look at the full version of my class. <?php class Advert { private $db; public $title; public $description; public $postcode; public $picture; public $email; public $date_posted; public $cost; public $message; public $subject; public $email_tag; public $link; public $id; public function __construct($database) { $this->db = $database; } public function setDetails($title, $description, $postcode, $picture, $email, $date_posted, $cost) { $this->title = $title; $this->description = $description; $this->postcode = $postcode; $this->picture = $picture; $this->email = $email; $this->date_posted = $date_posted; $this->cost = $cost; } public function insertAdvert() { $query = $this->db->prepare("INSERT INTO rooms (title, description, postcode, picture, email, date_posted, cost) VALUES (?, ?, ?, ?, ?, ?, ?)"); $query->bindValue(1, $this->title); $query->bindValue(2, $this->description); $query->bindValue(3, $this->postcode); $query->bindValue(4, $this->picture); $query->bindValue(5, $this->email); $query->bindValue(6, $this->date_posted); $query->bindValue(7, $this->cost); $query->execute(); } public function setAdvertLink() { $query = $this->db->prepare('SELECT id FROM rooms WHERE title = ? AND description = ? AND postcode = ? AND date_posted = ? AND email = ?'); $query->bindValue(1, $this->title); $query->bindValue(2, $this->description); $query->bindValue(3, $this->postcode); $query->bindValue(4, $this->date_posted); $query->bindValue(5, $this->email); $query->execute(); $data = $query->fetch(); $id = $data['id']; $this->link = 'http://www.home-decorators.co.uk/rooms/uk/london/'.$id; $_SESSION['last_id'] = $id; } public function retrieveConfirmationEmail() { $this->email_tag = 'Room Confirmation'; $query = $this->db->prepare('SELECT * FROM emails WHERE email_tag = ?'); $query->bindValue(1, $this->email_tag); $query->execute(); $data = $query->fetch(); $message = $data['message']; $subject = $data['subject']; $this->message = $message; $this->subject = $subject; } public function sendConfirmationEmail() { $headers = "From: admin@homelocator.com" . "\r\n"; $headers .= "Reply-To: admin@homelocator.com". "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($this->email, $this->subject, $this->message, $headers); } public function redirect() { header('location: success.php'); } } ?> As you can see I'm getting those variables from $_POST. Obviously I could just write a welcome email like this: $this->message = 'Hello ' . $this->name . ' your email is ' .$this->email; But i want to hold this in the db. Hope that's a bit more clear. Sorry I'm really bad at explaining
×
×
  • 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.