When I run this script , I have a error :
Warning: Invalid argument supplied for foreach() in C:\Apache\test.php on line 28

<?php
$conn =OCILogon("xxxx", "yyyy", "localhost/xe");
$query = 'SELECT *FROM TEST';
$stid = OCIParse($conn, $query);

print '</br>';
$stmt=OCIParse($conn,'SELECT *FROM TEST');


$ret=OCIExecute($stmt);
$nrows=OCIFetch($stmt,$results);


if ($nrows>0)
{
echo "<table border='1' align='left' bordercolor='gray' cellspacing='0' cellpadding='5'> \n";
echo "<tr>\n";

foreach ($results as $key => $val)
{ echo "<th bgcolor='yellow' height='20' align='left'> <font color='b' face='verdana' size='2'> $key </font> </th> \n";
}
echo "</tr>\n";


for ($i=0; $i<$nrows; $i++) {
echo "<tr>\n";

foreach ($results as $data){


if($data[$i] == null)
{
   echo "<td bgcolor='white'  align='left'> <FONT COLOR='black' FACE='verdana' align='left' SIZE='3'> &nbsp </FONT> </td>\n";
}
else
if($data[$i] == 'FAIL')
{
echo "<td bgcolor='red' > <FONT COLOR='black' FACE='verdana' SIZE='2'> $data[$i] </font>  </td>  \n";
}
else

{
echo "<td bgcolor='white' > <FONT COLOR='black' FACE='verdana' SIZE='2'> $data[$i] </font>  </td>  \n";
}

}
echo "</tr>\n";
}
echo "<table> \n"; 

}else 

{
echo '<font color="red"> missing id <br/> </font>';
}


//oci_free_statement($stmt);
  OCIFreeStatement($stmt);
  OCILogoff($conn);

I modify this code and insert (array) :

foreach ((array)$results as $key => $val)
{ echo "<th bgcolor='yellow' height='20' align='left'> <font color='b' face='verdana' size='2'> $key </font> </th> \n";
}
echo "</tr>\n";


for ($i=0; $i<$nrows; $i++) {
echo "<tr>\n";

foreach ((array)$results as $data){


if($data[$i] == null)
{
   echo "<td bgcolor='white'  align='left'> <FONT COLOR='black' FACE='verdana' align='left' SIZE='3'> &nbsp </FONT> </td>\n";
}
else
if($data[$i] == 'FAIL')
{
echo "<td bgcolor='red' > <FONT COLOR='black' FACE='verdana' SIZE='2'> $data[$i] </font>  </td>  \n";
}
else

{
echo "<td bgcolor='white' > <FONT COLOR='black' FACE='verdana' SIZE='2'> $data[$i] </font>  </td>  \n";
}

}
echo "</tr>\n";
}
echo "<table> \n"; 

}else 

{
echo '<font color="red"> Dzisiaj jeszcze nie byly uruchamiane TESTY <br/> </font>';
}

Now I have a blank page , I dont have eny errors and any value on www
anyone have any idea?

Recommended Answers

All 2 Replies

The problem is that $results is not an array. With ocifetch() you get the next row from a query into internal buffers so, you get a single part of the result set, try ocifetchinto(), you can read an example here:

Or try to use ocifetchstatement() which is the alias of the php5 function oci_fetch_all() and:

Fetches multiple rows from a query into a two-dimensional array. By default, all rows are returned.

A note: in order to count the rows use ocirowcount(): http://www.php.net/manual/en/function.ocirowcount.php

bye!

ocifetchstatement

it works !
thanx cereal ! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.