Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Mysql database class - only one connection alowed
- */
- class Database {
- private $_connection;
- private static $_instance; //The single instance
- private $_host = "localhost";
- private $_username = "yourdatabaseusername";
- private $_password = "yourdatabasepass";
- private $_database = "databasename";
- /*
- Get an instance of the Database
- @return Instance
- */
- public static function getInstance() {
- if(!self::$_instance) { // If no instance then make one
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- // Constructor
- private function __construct() {
- $this->_connection = new mysqli($this->_host, $this->_username,
- $this->_password, $this->_database);
- // Error handling
- if(mysqli_connect_error()) {
- trigger_error("Failed to conencto to MySQL: " . mysql_connect_error(),
- E_USER_ERROR);
- }
- }
- // Magic method clone is empty to prevent duplication of connection
- private function __clone() { }
- // Get mysqli connection
- public function getConnection() {
- return $this->_connection;
- }
- }
- ?>
- <?php
- include('database_connection.php');
- $db = Database::getInstance();
- $mysqli = $db->getConnection();
- $sql_query = "SELECT * FROM `eav_attribute_option` WHERE `attribute_id` =137";// 137 my size attribute id
- $result = $mysqli->query($sql_query);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- // echo "id: " . $row["option_id"]. " - Name: " . $row["attribute_id"]. "<br>";
- $sizes_value_id[]=$row["option_id"];//adding array all option_id
- }
- } else {
- echo "0 results";
- }
- //add a query all value informations
- foreach($sizes_value_id as $size){
- $sql_query = "SELECT * FROM `eav_attribute_option_value` WHERE `option_id`='.$size.'";
- $result = $mysqli->query($sql_query);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- echo "id: " . $row["option_id"]. " - Name: " . $row["value"]. "<br>";
- $sizes_value[]=$row["value"];//adding all values to an array
- }
- } else {
- echo "0 results";
- }
- }
- // for understand what we have
- echo "entity_id=".$sizes_value_id[0]."Value=".$sizes_value[0];
- // you can use same logics for other steps
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement