Jump to content

[SOLVED] How to get a value in the first row in an Ms Access db with php?


erdomester

Recommended Posts

My program is like this: there is a database with tables of bus_stops and minutes (how many minutes does the bus arrives to the stop from the terminus in). All bus-stops are pushed in a dropdown box. Tables of buses are in an array ($stops_array) like Bus_205, Bus_35 etc.

 

E.g.

Bus 205 table:

STOPS  MINS

Stop.1  0

Stop.2  1

Stop.3  3

...and so on and for all bus tables.

 

Program works this way:

1. User selects one from the dropdown box ($selected)

2. Program goes thru all the bus tables (for loop)

3. and searches for the selected stop in the table (while loop)

4. If there is a match, it writes out that e.g. bus No. X arrives in Y minutes from TERMINUS.

 

First part of the result is ok, but  how can i write out the terminus, which is the first row of the tables?  I use Ms Access and haven't found a solution, however there is a command for MySQL...

 

My code is:

  for ($i=0; $i<sizeof($stops_array); $i++)
  {
        $sqlt="SELECT * FROM $stops_array[$i]"; 
        $rst=odbc_exec($conn,$sqlt); 
         if (!$rst) 
        {exit("Error in SQL");} 
         while (odbc_fetch_row($rst)) 
         { 
            $stops=odbc_result($rst,"STOPS");          
            $mins=odbc_result($rst,"MINS");          

             if ($selected == $stops)   
             {
                  echo: " ";
              }
           }
  }

Well, i turned out to be an idiot. I was just studying for my complex exam at the uni when it stroke to me that i don't have to fill the array up, I just need the first element. So my code is like:

 

1. start filling up array

2. if there is a match, write out the 0.th element.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.