0

I have a table my_entity_data in that i have a column parentproduct_id

I want to get all values of that column in side one array

<?php
    $result = mysql_query("SELECT parentproduct_id FROM my_entity_data");
    $storeArray = Array();
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         $storeArray[] =  $row['parentproduct_id'];  
    }
    for ($i=0; $i < 10; $i++) { 
    echo $storeArray[i];
    }
?>

But no use Any thing wrong i did here ?

And i am running this code in Magento CE 1.7

Any ideas ? I

3
  • 1
    Do not use mysql_** functions. They are deprecated. Commented Sep 7, 2013 at 10:07
  • what does "no use" mean? It does not have a correct format as you want or the array is empty, or ... Commented Sep 7, 2013 at 10:10
  • its displaying nothing Commented Sep 7, 2013 at 10:11

3 Answers 3

1

Thanks to every one finally i got it

<?php
    // 1. Enter Database details
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'password';
    $dbname = 'DB Name';

    $connection = mysql_connect($dbhost,$dbuser,$dbpass);
   // Check connection
    if (!$connection) {
        die("Database connection failed: " . mysql_error());
    }

    $db_select = mysql_select_db($dbname,$connection);

    $result = mysql_query("SELECT parentproduct_id FROM my_entity_data");

    $storeArray = array();

    while ($row = mysql_fetch_array($result)) {
          array_push($storeArray,$row['parentproduct_id']);
    }

    for ($i=0; $i < 10; $i++) { 
        echo $storeArray[i];
    }

    //echo sizeof($storeArray);
    print_r($storeArray); //to see array data
?>
Sign up to request clarification or add additional context in comments.

1 Comment

your problem was with ($row = mysql_fetch_array($result, MYSQL_ASSOC)) if you want to get column name then only you can go for this.
0

you can use

Try mysql_fetch_assoc($result);

Below note from: php.net

 while ($row = mysql_fetch_assoc($result)) {
        foreach ($row as $key => $value) {
            $storeArray[$i][$key] = $value;
            }
        $i++;
        }

for ($i=0; $i < 10; $i++) { 
    echo $storeArray[i];
    }

hope this will sure work for you.

3 Comments

Thank for the reply... yeah this one also displaying empty array I mean array is empty
SELECT parentproduct_id FROM my_entity_data is given any row ? at php my admin
yeah i have 4 rows & that is also displaying
-1

Try this

<?php
    $result = mysql_query("SELECT parentproduct_id FROM my_entity_data");
    $storeArray = array();
    while ($row = mysql_fetch_array($result)) {
          array_push($storeArray,$row['parentproduct_id']);
    }


print_r($storeArray); //to see array data
?>

2 Comments

like this also its displaying empty array
thy this $result = mysql_query("SELECT parentproduct_id FROM my_entity_data",$connection_variable) or die("Error"); while( $row = mysql_fect_array($result) ){}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.