0

If i echo inside the while loop i get 4,2 values and if i echo outside the while loop then i only get 2. I want to get the data from $row into the values array. is something missing in this code?

$query = oci_parse($con, "SELECT count(*) FROM Counter GROUP BY Blog_name");
oci_execute($query);

while($row = oci_fetch_array($query))
{
    $s = $row[0].',';
    $values = explode(',', $s);
    echo $values[0]; // 4
    echo $values[1]; // 2
}
echo $values[0]; // 2
echo $values[1]; // 2
0

4 Answers 4

2

Try this,

$Values = array();
 while($row = oci_fetch_array($query))
{
    $Values[] = $row[0];       
}
 echo $Values[0];
Sign up to request clarification or add additional context in comments.

Comments

2

First, $values as you're using it is just a string, and is not an array.

Try adding before the while loop.

$values = array();

Second, there's really no need to use explode here, it's an unnecessary step. If you only want the first column in the row, you can simply add that column to $values. (Currently you are overwriting the contents of $values at each iteration of the loop because you are missing the [].)

$values[] = $row[0];

If you're trying to put ALL of the columns in each row into values, try:

$values[] = $row;

If you're trying to individually put the contents of each column into it's own index in $values, try:

while($row = oci_fetch_array($query))
{
    foreach($row as $column)
    {
        $values[] = $column;
    }
}

Comments

1

Do like this:

$s = array();
while($row = oci_fetch_array($query))  {
    $s[] = $row[0];
}

echo $s[0];
print_r($s);

Comments

0
$query = oci_parse($con, "SELECT count(*) FROM Counter GROUP BY Blog_name");
oci_execute($query);

$values = array();
while($row = oci_fetch_array($query))
{
    $values[] = $row[0];
}

print_r($values);

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.