2

I want to display the values of my array. but instead of displaying:

1509 1510 1511 it display ArrayArrayArray. What does it mean?

include("db_PSIS.php");
$sql_dc = "SELECT Child, Datecode 
                    FROM traveller_merging15
                    WHERE Parent='" . $_REQUEST["txt_traveller_no"] . "'
                    ORDER BY Merge_ID ASC";
$res_dc = mysql_query($sql_dc);

$dcode1 = $row_dc['Datecode'];
$storeArray = array();

if (!$res_dc) {
    echo "No data fetched!";
} else {
    while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
        $storeArray[] = $dcode1;
        echo "{$storeArray} <br>";
    }
    //$str_dc=implode(",",$storeArray);
    //echo $str_dc;
}
4
  • It means you are trying to echo an array. var_dump($storeArray) and check the value of it!! Commented Nov 23, 2015 at 6:25
  • Your this ` $storeArray[] = $dcode1; ` statement says you are storing $dcode1 value in array and you are printing $storeArray variable. As it is array it will display ArrayArrayArray only. Use print_r($storeArray) Commented Nov 23, 2015 at 6:27
  • Hi @Saty, i tried to put var_dump($storeArray); And I'm getting this line: array(1) { [0]=> NULL } array(2) { [0]=> NULL [1]=> NULL } array(3) { [0]=> NULL [1]=> NULL [2]=> NULL } Commented Nov 23, 2015 at 6:55
  • Check my answer below because you are trying to read data before retrieve it from database Commented Nov 23, 2015 at 6:57

4 Answers 4

1

You are assign the value of $row_dc['Datecode']; before fetch data from database. You need to do fetch data inside while loop and echo it

$res_dc = mysql_query($sql_dc);
if (!$res_dc) {
    echo "No data fetched!";
} else {
    while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
        echo $row_dc['Datecode'];
    }  
 }

Note:- mysql is deprecated instead use mysqli or PDO

Sign up to request clarification or add additional context in comments.

Comments

0
   else {
        while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
        $storeArray[] =  $dcode1; 
        echo "{$storeArray} <br>";
        }

instead try

   else {
        while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
        $storeArray[] =  $dcode1; 
        echo "{$storeArray[0]} <br>";
        }

Comments

0

Try this,

else {
  while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
  $child =  $row_dc['Child']; 
  $Datecode =  $row_dc['Datecode']; 
  echo "$child <br> $Datecode";
}

if you are getting more that 1 row, use for() loop

else {
  while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
  $count = count($row_dc);
  for($i = 0; $i < $count; $i ++){
      $child =  $row_dc[$i]['Child']; 
      $Datecode =  $row_dc[$i]['Datecode']; 
      echo "$child <br> $Datecode";
  }

}

Comments

0

-first array don't print value using echo

-use print_r($array) to print key value pair(print a array)

your solution is

 $i = 0;
 while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
          $storeArray[$i] =  $dcode1; 
          echo $storeArray[$i].'<br>';
          $i++;
  }

NOTE::-- Use single Quote instead of double Quote and mysql is deprecated instead use mysqli or PDO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.