Jump to content

[SOLVED] need alternative to oci_fetch_array for PHP 4


Recommended Posts

What is the OCI equivalent to mysql_fetch_array in SQL+? I am using PHP 4 and so oci_ fetch_ array does not work for me.

 

<?php
$queryHall = "
SELECT hall
FROM user.hall
";
$hallResults = ociparse($connect, $queryHall);
ociexecute($hallResults);

echo "<select name='hallDrop'>";
echo "<option value=' '> </option>";

while( $hall = ocifetch($hallResults) )
{
  echo " \n\t<option value = '" . $hall . "'";
  if (isset($_SESSION['hallDrop']) && $_SESSION['hallDrop'] == $hallList) 
  { 
    echo " selected='selected' "; 
  } 
  echo ">" . $hall . "</option>";
}
echo "</select>";
?>

 

My droplist is not populated.  :-\ Inserting $hallList = ociresult($hall,"HALL"); is of no help either.

I should say that I usually program in mySQL and am learning SQL+/Oracle. I had read that when you use ocifetch, you must also use ociresult. That's why I had mentioned the $hallList = ociresult($hall,"HALL"); and using $hallList as the record set.

 

I did try the field referencing and it did not work:

 

<?php
$hallResults = ociparse($connect, $queryHall);
ociexecute($hallResults);

echo "<select name='hallDrop'>";
echo "<option value=' '> </option>";

while( $hall = ocifetch($hallResults) )
{
  echo " \n\t<option value = '" . $hall['HALL'] . "'";
  if (isset($_SESSION['hallDrop']) && $_SESSION['hallDrop'] == $hall['HALL']) 
  { 
    echo " selected='selected' "; 
  } 
  echo ">" . $hall['HALL'] . "</option>";
}
echo "</select>";
?>

try this (lots of commenting out)

 

whats displayed

 

<?php
$queryHall = "
SELECT hall
FROM user.hall
";
$hallResults = ociparse($connect, $queryHall);
ociexecute($hallResults);

//echo "<select name='hallDrop'>";
//echo "<option value=' '> </option>";

while( $hall = ocifetch($hallResults) )
{
print_r($hall);
  //echo " \n\t<option value = '" . $hall . "'";
  //if (isset($_SESSION['hallDrop']) && $_SESSION['hallDrop'] == $hallList) 
  //{ 
  //  echo " selected='selected' "; 
  //} 
  //echo ">" . $hall . "</option>";
}
echo "</select>";
?>

You should be able to use the same code you have but change your ocifetch() function to ocifetchinto(). This gets the row and puts the ocntents into an array. If it doesn't work, do a print_r() again to see what exactly is in that array.

 

EDIT: actually you have to change the syntax a little bit because ocifetchinto() accepts a pointer to an array to put the contents into: http://us2.php.net/manual/en/function.ocifetchinto.php

I did exactly that early on. As I stated above, I once tried using the ociresult function with ocifetch like this:

 

<?php
ociexecute($hallResults);
while( $hall = ocifetch($hallResults) )
{
  $hallList = ociresult($hall,"HALL");

  blah blah
}
?>

Sorry, I didn't see that. Are you also selecting the database when you connect? If so, try to do just "FROM hall". The only reason I suggest such things is that it would seem that your php can't be much different so I figure there is a chance that something is wrong with the query. Access or other programs might require the shema be included in the query, but, since you are selecting it in the connection (probably), it would seem redundant. If nothing else, it might help in debugging.

what about this

 

<?php
$queryHall = "
SELECT hall
FROM user.hall
";
$hallResults = ociparse($connect, $queryHall);
ociexecute($hallResults);

echo "<select name='hallDrop'>";
echo "<option value=' '> </option>";

while( $hall = ocifetch($hallResults) )
{
$hall = ociresult($hallResults, "HALL"); //added
  echo " \n\t<option value = '" . $hall . "'";
  if (isset($_SESSION['hallDrop']) && $_SESSION['hallDrop'] == $hallList) 
  { 
    echo " selected='selected' "; 
  } 
  echo ">" . $hall . "</option>";
}
echo "</select>";
?>

 

Thank you MadTechie! The problem was that I had:

 

$hallList = ociresult($hall,"HALL");

 

instead of:

 

$hallList = ociresult($hallResults,"HALL");  :-X

 

By the way, I also changed: while( $hall = ocifetch($hallResults) )

 

back to: while( ocifetch($hallResults) )

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.