Jump to content

pollux

New Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by pollux

  1. It's a goog practice to set link_identifier of MySQL connection : mysql_select_db("agile", $dbc) OR ('coul not select db : '. mysql_error()); About your learn and write you code in oop, you have to read more about tendency and practice in PHP OOP. Everything about these things : how to declare classes, methods, members, what types exist, design patterns in OOP ... About your code you can try to organize some classes structure based on your logic and requirements. Just foe example : class Config { const DB_HOST = "localhost"; const DB_USERNAME = "username"; const DB_PASSWORD = "pass"; const DB_NAME = "dbname"; } class Cart{ public $image; public $item; public $desk; public $price; public $qu; public function read( MysqlQuery $resObj ){ if( $resObj instanceof MysqlQuery ) { while ($row = mysql_fetch_array($resObj->getResult(), MYSQL_ASSOC)) { $this->image[$row['itemId']] = $row['image']; $this->item[$row['itemId']] = $row['item']; $this->desk[$row['itemId']] = $row['description']; $this->price[$row['itemId']] = $row['price']; $this->qu[$row['itemId']] = $row['quantaty']; } } } } class DatabaseConnection extends Config { /** * A static property to hold the single instance of the class */ private static $instance; /** * The constructor is private so that outside code cannot instantiate * */ private function __construct() { $dbc = mysql_connect(parent::DB_HOST , parent::DB_USERNAME , parent::DB_PASSWORD ); mysql_select_db( parent::DB_NAME, $dbc ); if ( mysql_error() || mysql_errno()) { throw new Exception('Databse error: '.mysql_errno().' - '.mysql_error()); } } /** * All code that needs to get and instance of the class should call * this function like so: $db = Database::getInstance(); */ public function getInstance() { // If there is no instance, create one if (!isset(self::$instance)) { $class = __CLASS__; self::$instance = new $class; } return self::$instance; } /** * Disallow cloning * */ private function __clone() {} } class MysqlQuery { protected $_result; public function __construct(){ $this->_result = ""; } public function query($sql) { $this->_result = mysql_query($sql); if ( mysql_error() || mysql_errno()) { throw new Exception('Databse error: '.mysql_errno().' - '.mysql_error()); } } function setResult($value) { $this->_result = $value; } function getResult(){ return $this->_result; } /** * here you can write some your query function which you use lots of times */ } /** * index.php */ $dbc = new DatabaseConnection(); $sqlQuery = new MysqlQuery(); if ($_GET['me'] == true) { $cat = mysql_real_escape_string(trim($_GET['me'])); }else{ $cat = "price"; } $sqlQuery->query("SELECT * FROM kurtula_shop where quantaty > '0' ORDER BY $cat"); $card = new Cart(); $card->read($sqlQuery); foreach ( $card->desk as $key => $value) { print_r("For item $key - desc = $value"); } In this loop while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $this->image = $row[image]; $this->item = $row[item]; $this->desk = $row[description]; $this->price = $row[price]; $this->qu = $row[quantaty]; } you have to put values in array because, you overwrite the value in $this->desk = $row[description]; for evaryone row which query retrn. What exactly error you receive?
  2. Not necessarily to use Ajax to create a gallery! JQuery tool demo 30 Scripts For Galleries, Slideshows and Lightboxes some examples
×
×
  • Create New...