Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selectbox problem. No data.

Status
Not open for further replies.

TanTrazz

Programmer
Aug 18, 2001
54
NL
Hi All,

Need help by filling SELECT Box.

The problem is the data won't appear in the selectbox. It won't work. The data is in a database.

Code:
  //Database Connectie
  $conn = odbc_connect('ims',"","") or die("Couldn't connect to datasource.");

 //dropdown
  $onderwerp = "SELECT Message_Subject_Id, Name_Long FROM CODE_MESSAGE_SUBJECTS";



 //num_rows select box
  function better_odbc_num($conn,$onderwerp){
   $result = odbc_exec($conn,$onderwerp);
   $count=0;
   while($temp = odbc_fetch_into($result, &$counter)){
       $count++;
   }
   return $count;
}




<td align = left>
              <select name=onderwerp>
              <?
              if(better_odbc_num($conn,$onderwerp))
                {
                  while($x=odbc_fetch_row($onderwerp))
                  {

                     print("<option value = {$x[0]} >{$x[1]}</option>");
                   }

                }
                ?>
              </select>

Thanks in advance


TanTrazz
 
I'm not at all suprised that your script outputs no data.

Imagine an ODBC connection handle (your $conn variable) as being very similar to a file pointer (which it is). As such, your connection handle has an internal pointer which points to the "current" row from the result set. All of PHP's odbc_fetch_*() functions return the "current" row then increment the internal pointer by one row.

Your script calls a function which rolls the result set row pointer all the way to the end of the result set (the use of odbc_fetch_into() inside better_odbc_num()). Your script then attempts to fetch a row from the result set using odbc_fetch_row(), but only FALSE will be returned, as there are no more results rows to fetch.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
sleipnir214 thanks for your reply.

Do you have an example code for me?

TnQ TanTrazz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top