Jump to content

jacob1986

Members
  • Posts

    37
  • Joined

  • Last visited

Everything posted by jacob1986

  1. I have made a small CSS image slider for my webpage, but have a few issues with the slider and my images. The images differ in size on the screen (although I have made sure the images were the same size before upload). I have written code for three images, the first image of the slider is too high, the second image is great, third image is lower than the second and first image... and then it shows a fourth blank image? HTML Code: <div id="slider"> <figure> <li><img src="http://xxx/jkhzmGV.jpg" /></li> <li><img src="http://xxx/49RqNB5.jpg" /></li> <li><img src="http://xxx/7nrTa5p.jpg" /></li> </figure> </div> CSS Code: @keyframes slider { 0% { left: 0; } 20% { left: 0; } 25% { left: -100%; } 45% { left: -100%; } 50% { left: -200%; } 70% { left: -200%; } 75% { left: -300%; } 95% { left: -300%; } 100% { left: -400%; } } #slider { overflow: hidden; } #slider figure img { width: 20%; float: left; } #slider figure { position: relative; width: 500%; margin: 0; left: 0; text-align: left; font-size: 0; animation: 30s slider infinite; } }
  2. I thought it would be easier for you, but here's the code below. The error show five times: Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\Work\classes\DB.php on line 37 DB.php: <?php class DB { private static $_instance = null; private $_pdo, $_query, $_error = false, $_results, $_count = 0; private function __construct() { try { $this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password')); } catch(PDOException $e) { die($e->getMessage()); } } public static function getInstance() { if(!isset(self::$_instance)) { self::$_instance = new DB(); } return self::$_instance; } public function query($sql, $params = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($params)) { foreach($params as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchALL(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); }else{ $this->_error = true; } } return $this; } public function action($action, $table, $where = array()) { if(count($where) == 3) { $operators = array('=', '>', '<', '>=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; if(!$this->query($sql, array($value))->error()) { return $this; } } } return false; } public function get($table, $where) { return $this->action('SELECT *', $table, $where); } public function delete($table, $where) { return $this->action('DELETE', $table, $where); } public function insert($table, $fields = array()) { $keys = array_keys($fields); $values = ''; $x = 1; foreach($fields as $field) { $values .= '? '; if($x < count($fields)) { $values .= ', '; } $x++; $sql = "INSERT INTO users (`" . implode('`, `', $keys) . "`) VALUES ({$values})"; if(!$this->query($sql, $fields)->error()) { return true; } } return false; } public function update($table, $id, $fields) { $set = ''; $x = 1; foreach($fields as $name => $value) { $set .= "{$name} = ?"; if($x < count($fields)) { $set .= ', '; } $x++; } $sql = "UPDATE {$table} SET {$set} WHERE id = {id}"; if(!$this->query($sql, $fields)->error()) { return true; } return false; } public function results() { return $this->_results; } public function error() { return $this->_error; } public function count() { return $this->_count; } }
  3. I keep running into the error 'Warning PDOStatment::exucute():SQLSTATE[HY093]: invalid parameter number: number of bound variables does not match number of tokens in DB.PHP line 38'. I think it's something to do with the PDO bound variables not being the same, but when I search for an error I cannot seem to find anything (I guess it would help to know what precisely I'm looking for - sorry). I have uploaded the code to a GitHub repository, which can found at https://github.com/aaron1986/OOP-Login-Register-System
  4. I have designed another (if rather crude) php calculator this time with a form - could you show me how to make the URL show: yourscript.php?n1=5$n2=7&op=m i.e. by using http_build_query? Code: index2.html <html> <form action="Calculator2.php" method="POST"> n1: <input type="text" name="num1"> <select name="operations"> <option>Select an Operation...</option> <option name="Add">Add</option> <option name="Subtract">Subtract</option> <option name="Multiply">Multiply</option> <option name="Divide">Divide</option> </select> n2: <input type="text" name ="num2"> <input type="submit" value ="Calculate"> </form> </html> Code: Calculator2.php <?php $num1 = $_POST["num1"]; $num2 = $_POST["num2"]; $operation = $_POST["operations"]; if($operation == "Add") { } $answer_Add = $num1 + $num2; echo $num1. " + ".$num2." = "; echo $answer_Add ?>
  5. Sorry to have to ask questions again... but I'm having serious hindrance in regards to an assignment. I have to create a Calculator using PHP (which I have completed - see code below), but I have to do this whilst using a query string to provide two numbers and an operator? Moreover, I have to show the URL - showing the following: yourscript.php?n1=5$n2=7&op=m It then says validate that 'n1' and 'n2' are both numbers and that 'op' contains only allowed values???? If everything validates I have to print the result of the equation? My code has two parts and shows two numbers and an operator and prints like this: 5 + 7 = 12. But... I also have to add http_build_query in my code to show the url? <?php require_once 'big.php'; $number1 = 5; $number2 = 7; $operator = "+"; $calculator = new Calculator(); $calculator->setNumbers($number1, $number2); $calculator->setOperator($operator); $calculator->calculate(); echo $number1." ". $operator." ".$number2." = ". $calculator->getOutput(); <?php class Calculator { private $number1, $number2, $operator, $output; public function setNumbers($number1, $number2) { $this->number1 = $number1; $this->number2 = $number2; } public function setOperator($operator) { $this->operator= $operator; } public function calculate() { if($this->operator == "+") $this->output = $this->number1 + $this->number2; elseif($this->operator == "-") $this->output = $this->number1 - $this->number2; elseif($this->operator == "*") $this->output = $this->number1 * $this->number2; elseif($this->operator == "/") $this->output = $this->number1 / $this->number2; else $this->output = "An Error Has Materialize!"; } public function getOutput() { return $this->output; } }
  6. I have two questions relating to each other which are regarding - both function __autoload and adding products to a class? Code for an autoload function (please see code #1), the output prints - but also gives an error message? Moreover, I also receive the notification in my php editor "class 'ooo' not found"? If I may ask a silly question I have noticed some autoload fucctions have implode and explode - how would I write one of these? The output and error: My Antonia: Willa Cather (5.99) Fatal error: Class 'ooo' not found in C:\ Code#1: <?php // we've writen this code where we need function __autoload($classname) { $filename = "./". $classname .".php"; include_once($filename); } // we've called a class *** $obj = new ooo(); ?> ------------------------------------------------------------------------------------------------------------------------------ How would I add more products to this product class? code#2: <?php class shopProduct { public $title; protected $producer = []; public $price; public function __construct($title, $producerName1, $producerName2, $price) { $this->title = $title; $this->producer[] = $producerName1; $this->producer[] = $producerName2; $this->price = $price; } public function getProducer() { return implode(' ', $this->producer); } } class ShopProductWriter { public function write ($shopProduct) { $str = "{$shopProduct ->title}: " . $shopProduct -> getProducer() . " ({$shopProduct -> price})\n"; print $str; } } $product1 = new ShopProduct("My Antonia", "Willa", "Cather", 5.99); $writer = new ShopProductWriter(); $writer -> write($product1); ?>
  7. I have to write small segment of PHP code to print the word(s) 'Hello, World!' in uppercase letters, I have thus far wrote a small section of code that prints the output 'Hello, World!'. But, I'm completely stuck on how to make the letters all uppercase?!?? Moreover; that strtoupper goes somewhere in there right? <?php class TextFunctions { public static $string = 'Hello, World!'; static public function strtoupper() { } } echo TextFunctions::$string; ?>
  8. I'm really sorry guys!!! I fervently apologise!
  9. I have rewrote the code... but this time it only prints: Author: Willa It should read: Author Willa Cather <?php class ShopProduct { public $title; public $producerMainName; public $producerFirstName; public $price = 0; function __construct ( $title, $firstName, $mainName, $price) { $this-> title = $title; $this-> producerFirstName = $firstName; $this-> produerMainName = $mainName; $this -> price = $price; } function getProducer() { return "{$this -> producerFirstName}". "{$this -> producerMainName}"; } } $product1 = new ShopProduct( "My Antonia", "Willa", "Cather", 5.99); print "Author: {$product1->getProducer()}\n"; ?>
  10. Regarding the code it [the book] does say 'this outputs the following: author: Wills Cather' Could you or maybe someone else help me to sort the code so it prints: author: Wills Cather As below? Or have done it wrong? <?php class MyClass { $myObj = new MyClass(); $myObj -> myMethod( "Harry Potter"); } public function myMethod($argument, $another) { //... } // //let's declare a method in our ShopProduct class: class ShopProduct { public $title = "default product"; public $producerMainName = "main name"; public $producerFirstName = "first name"; public $price = 0;
  11. I have typed some PHP code from a book (https://books.google.co.uk/books?id=KZoAq_mbhXAC&printsec=frontcover&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false) page 20. But keep getting an error message? Parse error: syntax error, unexpected 'public' (T_PUBLIC) PHP Code: <?php class MyClass { //class body } public function myMethod($argument, $another) { //... } $myObj = new MyClass(); $myObj -> myMethod( "Harry Potter"); // //let's declare a method in our ShopProduct class: class ShopProduct { public $title = "default product"; public $producerMainName = "main name"; public $producerFirstName = "first name"; public $price = 0; function getProducer() { return "{$this -> producerFirstName}" . "{$this -> producerMainName}"; } } $product1 = new ShopProduct(); $product1 -> title = "My Antonia"; $product1 -> producerMainName = "Cather"; $product1 -> producerFirstName = "Willa"; $product1 -> price = 5.99; print "Author: {product1 -> getProducer()}\n"; ?>
  12. No more questions on this but thank-you
  13. I have the following code (as below), but I cannot seem to make a new line (i,.e. 1: 1,2,3,4 and then make a new line with 3: 1,2,3,4). As it only prints 1: 1,2,3,4 3: 1,2,3,4 - all I need is: 1: 1,2,3,4 3: 1,2,3,4 ****************************************************** <?php $array = array( 1 => range (1, 4), 2 => range (1, 4), 3 => range (1, 4) ); $numbers = count($array); for ($i = 1; $i <= $numbers; $i += 2) { echo $i . ': ' . implode(',', $array[$i]) . PHP_EOL; } ?> ***************************************************************************
  14. <?php function getName($Christianname, $Surname, $middlename = "") { return ucwords($Surname . ", " . $Christianname . " " . $middlename) ; } echo getName('john', 'smith', 'k.'); ?>
  15. I have this code (while it works - it doesn't seem to help me with the inclusion of the string... echo getName('john', 'smith', 'k'); <?php function getName($getName = "K") { return "John Smith $getName.\n"; } echo getName(); ?> Prints: John Smith K.
  16. I have been given the problem 'write a function called getName() which has three parameters: Christian name, Surname and middle initial. Moreover, return a string in the format of "Smith, John K".' Starting code: echo getName('john', 'smith', 'k'); The only code, which I have thus been able to write - please see below... and it's pitiful! <?php $xml=<<<XML <?xml version="1.0" standalone="yes"?> <john> </john> XML; $sxe=new SimpleXMLElement($xml); echo $sxe->getName() . "<br>"; ?>
  17. I have to complete a multidimensional array, I have written PHP code but I keep getting numbers ontop of the arrays? Moreover; could you give me feedback on the multidimensional array is it anygood? <?php $customers = array( $customers =['Name' => 'Bob','id' => '587','Date' => '17/10/1015',], $customers =['Name' => 'Stu','id' => '100','Date' => '02/04/2010', ], $customers =['Name' => 'Kate','id' => '12','Date' => '09/12/2013',], ); $keys = array_keys($customers); $keys = array_keys($customers); for($i = 0; $i < count($customers); $i++) { echo $keys[$i] . "<br>"; foreach($customers[$keys[$i]] as $key => $value) { echo $key . " : " . $value . "<br>";} echo "<br>";} ?> //Ouput: 0Name : Bobid : 587Date : 17/10/1015 1Name : Stuid : 100Date : 02/04/2010 2Name : Kateid : 12Date : 09/12/2013
  18. I think this may be the correct way... sixteen cards all together - two random cards picked! <?php $input = array( "Red => 1", "Blue => 2", "Green => 3", "Yellow => 4", "Red => 5", "Blue => 6", "Green => 7", "Yellow => 8", "Red => 9", "Blue => 10", "Green => 11", "Yellow => 12", "Red => 13", "Blue => 14", "Green => 15", "Yellow => 16", ); $rand_keys = array_rand($input, 2); echo $input[$rand_keys[0]] . "\n"; echo $input[$rand_keys[1]] . "\n"; ?> //Output: Blue => 10 Yellow => 16
  19. Yes, I was a bit confused regarding the question, I need to print two cards from the deck? <?php $array = [['Red => 4'],]; foreach ($array as list($a,)) { echo "Card One: $a."; } $array = [['Blue => 2'],]; foreach ($array as list($a,)) { echo "Card Two: $a."; } ?> //Output: Card One: Red => 4.Card Two: Blue => 2.
  20. I have to complete a simple task which says 'use foreach to print the value of the sum of two cards, the deck has 16 cards and each card has one number and one colour'. Moreover; I can write four cards and four numbers, but how do I write all sixteen cards (I would prefer if they could sit abreast - parallel to each other)? The code I have so far is this: <?php $a = array( "Red" => 1, "Blue" => 2, "Green" => 3, "Yellow" => 4, ); foreach ($a as $key => $val) { echo "<h4>$key => $val.</h4>"; } ?> // Output: Red => 1. Blue => 2. Green => 3. Yellow => 4.
  21. I have an exercise which I must complete, but thus far... I'm a bit stuck and don't know if I have made the correct code array? Question: Start with the following code: $array = array ('2' => 1, 3); Without making a new array, change the above array so that the key-value pairs are: 2 => 1 3 => 3 b => 4 4 => 2 I don't think this code (as below) is correct because of the commas in the number sequence... I'm guessing it should be 21, 33, b4, 42? <?php $array = array ('2' => 1, 3 => 3, b => 4, 4 => 2); foreach($array as $key=>$val) { echo" $key, $val"; } ?> Output: 2, 1 3, 3 b, 4 4, 2.
  22. I have to declare an array which contains the sentence 'Programming in PHP is fun!' and which also contains the words of the sentence separately. I have the following code but the end sentence has a zero - how do I get rid of that, moreover, how do I put a line break in between the line 'fifth word fun! and Programming in PHP is fun! <?php $fun = [ 'First Word' => 'Programming', 'Second Word' => 'in', 'Third Word' => 'PHP', 'Fourth Word' => 'is', 'Fifth Word' => 'fun!', 'Programming in PHP is fun!' ]; foreach($fun as $key=>$val) { echo" $key, $val</br>";} ?> Output: First Word, ProgrammingSecond Word, inThird Word, PHPFourth Word, isFifth Word, fun!0, Programming in PHP is fun!
  23. I have managed to get the code to work (is my face red)... I had a typo (as you said regarding form and from), moreover; I changed the url to http://localhost/article_detail.php?id=4 and it worked.
×
×
  • 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.