954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

combo box

hello, i was wondering if you could help me out!

i am creating a database in oracle8i (sqlplus)

i am trying to allow on one of my pages for the user to select things from the table

i.e if there is a passenger table, i want a combo box that will display the different passengers to allow me to select them to input in my booking table!

any help would be much appreciated as this is really doing my head in!

thank you :o

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

You mean that you want to create a web page to do this? You can see how to create a dropdown box here

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

thanks for your reply, but thats not exactly what i meant,

i want the options in the combo box to be taken from my oracle table

so if in my passenger table i had

passengerID | passenger
0001 lee
0002 paul
0003 dave

in my combo box 001, 002, 003 would be displayed!

but if i added passenger 0004 to my passenger table then it would be automatically read from my passenger table and inserted into the combo box!

i can find the mysql/php code to do it, but not the oracle/php way to do it, and i can not figure it out from the mysql code!

thank you, it has puzzled me for a couple of weeks!

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

Have you seen this page or this page ??

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

i havnt seen those pages no, they are very usefull indeed! I still cant find what i am after tho! :rolleyes:
but thanks for your time and help :mrgreen:

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

Have you been able to make a connection to the oracle database with php. That is the first hurdle you must pass. If not, try adapting the script on this page to work on your server.

[PHP]<?php
// script from http://us3.php.net/manual/en/function.ocilogon.php
echo "";
$db = "";

$c1 = ocilogon("scott", "tiger", $db);
$c2 = ocilogon("scott", "tiger", $db);

function create_table($conn)
{
$stmt = ociparse($conn, "create table scott.hallo (test varchar2(64))");
ociexecute($stmt);
echo $conn . " created table\n\n";
}

function drop_table($conn)
{
$stmt = ociparse($conn, "drop table scott.hallo");
ociexecute($stmt);
echo $conn . " dropped table\n\n";
}

function insert_data($conn)
{
$stmt = ociparse($conn, "insert into scott.hallo
values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY HH24:MI:SS'))");
ociexecute($stmt, OCI_DEFAULT);
echo $conn . " inserted hallo\n\n";
}

function delete_data($conn)
{
$stmt = ociparse($conn, "delete from scott.hallo");
ociexecute($stmt, OCI_DEFAULT);
echo $conn . " deleted hallo\n\n";
}

function commit($conn)
{
ocicommit($conn);
echo $conn . " committed\n\n";
}

function rollback($conn)
{
ocirollback($conn);
echo $conn . " rollback\n\n";
}

function select_data($conn)
{
$stmt = ociparse($conn, "select * from scott.hallo");
ociexecute($stmt, OCI_DEFAULT);
echo $conn."----selecting\n\n";
while (ocifetch($stmt)) {
echo $conn . " [" . ociresult($stmt, "TEST") . "]\n\n";
}
echo $conn . "----done\n\n";
}

create_table($c1);
insert_data($c1); // Insert a row using c1
insert_data($c2); // Insert a row using c2

select_data($c1); // Results of both inserts are returned
select_data($c2);

rollback($c1); // Rollback using c1

select_data($c1); // Both inserts have been rolled back
select_data($c2);

insert_data($c2); // Insert a row using c2
commit($c2); // Commit using c2

select_data($c1); // Result of c2 insert is returned

delete_data($c1); // Delete all rows in table using c1
select_data($c1); // No rows returned
select_data($c2); // No rows returned
commit($c1); // Commit using c1

select_data($c1); // No rows returned
select_data($c2); // No rows returned

drop_table($c1);
echo "";
?> [/PHP]

I suggest making a new test database for the script to use. You will need to declare the database name here:

[PHP]$db = "";
// add db name to above like so:
$db = "mydatabasename";[/PHP]

The username and pass mentioned in the script are scott and tiger. You can use those values or different ones.

Give this a shot and see what happens, we will go from there

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 


<?
// set-up data to insert
$vars=$HTTP_POST_VARS;
$BookingID =$vars[BookingID];
$PassengerID =$vars[PassengerID];
$FlightID = $vars[FlightID];
$RouteID =$vars[RouteID];
$SeatNumber = $vars[SeatNumber];
// connect to database
putenv("ORACLE_SID=area");
if ($Connection = ocilogon("u2o30", "u2o30"))
{
// assemble query
$Sql = "INSERT INTO booking (BookingID, PassengerID, FlightID, FlightDate, RouteID, Seatnumber, DateOfBooking)";
$Sql .= "VALUES ('$BookingID', '$PassengerID', '$FlightID', sysdate+1, '$RouteID', '$SeatNumber', SYSDATE)";
// parse it
$Statement = ociparse($Connection, $Sql);
if ($Statement)
{ PRINT "Editing data...

"; }
else
{ PRINT "Parse failure"; }
// execute query
if (ociexecute($Statement))
{ print ("Passenger $PassengerID Booked successfully.
\n"); }
else
{ print ("Passenger $PassengerID Did Not Book successfully
\n"); }
// log off
ocilogoff($Connection);
}
// handle failure to log on
else
{
var_dump( ocierror($Connection));
} // end of if expression


that is my insertbooking.php

Book A Flight

Booking ID (B000):

Passenger ID (0000):

Flight ID (F000):

Route ID:
East Midlands to London HeathrowEast Midlands to London GatwickEast Midlands to BrusselsEast Midlands to DublinEast Midlands to Amsterdam Schiphol
Seat Number:

 

Make sure you enter valid (existing) entries into the Foreign ID columns!



Page last modified:

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 


Book A Flight

Booking ID (B000):

Passenger ID (0000):


<?php echo($optionlist); ?>

Flight ID (F000):

Route ID:
East Midlands to London HeathrowEast Midlands to London GatwickEast Midlands to BrusselsEast Midlands to DublinEast Midlands to Amsterdam Schiphol
Seat Number:

 

Make sure you enter valid (existing) entries into the Foreign ID columns!



Page last modified:

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

thanks alot mate! its not workin at the moment haha, ill have a little fiddle with it though and see how it goes!

thanks again!!! :mrgreen:

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

ive got it sort of workin now, but in the combo box it just displays '/' 2 of them! can you see how i am getting this problem?


$optionlist.= "$row[0]/$row[1]";

i have 9 columns in my table, passengerid which is the one that i need is indeed [0]

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

Change this:
[PHP] $stuff=ocifetchstatement ($Statement, &$arr, 0, 20, OCI_FETCHSTATEMENT_BY_ROW);

foreach($arr as $key => $row)
{
$optionlist.= "$row[0]/$row[1]";
} [/PHP]

to look like this:

[PHP] $stuff=ocifetchstatement ($Statement, &$arr, 0, 20, OCI_FETCHSTATEMENT_BY_ROW);
echo('');
print_r($arr);
echo('');
foreach($arr as $key => $row)
{
$optionlist.= "$row[0]/$row[1]";
} [/PHP]

It will allow you to see what $arr looks like.

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

you are indeed a star! that has mede it much clearer and easier to understand! my page now appears like this!


Array
(
[0] => Array
(
[PASSENGERID] => 0001
[SURNAME] => Jones
[FIRSTNAME] => Lee
[ADDRESS1] => 29 Birches Head Rd
[ADDRESS2] => Birches Head
[ADDRESS3] => Stoke
[TELEPHONE] => 65656576
[NEXTOFKIN] => Carole
[KINTELEPHONE] => 767896767
)

[1] => Array
(
[PASSENGERID] => 0003
[SURNAME] => Facey
[FIRSTNAME] => Phil
[ADDRESS1] => vfvv
[ADDRESS2] => fvfvf
[ADDRESS3] => vfdvfdv
[TELEPHONE] => 234343
[NEXTOFKIN] => ewfeewf
[KINTELEPHONE] => 34232434
)

)

Book A Flight

Booking ID (B000):
Passenger ID (0000): //
Flight ID (F000):
Route ID: East Midlands to London Heathrow East Midlands to London Gatwick East Midlands to Brussels East Midlands to Dublin East Midlands to Amsterdam Schiphol
Seat Number:

Make sure you enter valid (existing) entries into the Foreign ID columns!


Page last modified: 04/25/2005 12:46:45

but the i can still not see how to select the passengerid into the combo box! sorry too be a pain! thanks again for your help! it is much appreciated!!

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

[PHP]
$stuff=ocifetchstatement ($Statement, &$arr, 0, 20, OCI_FETCHSTATEMENT_BY_ROW);

foreach($arr as $key => $row)
{
$optionlist.= "$row['PASSENGERID']/$row['FIRSTNAME'] $row['SURNAME']";
}

[/PHP]

That should do the trick.

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

still the same problem! its not readin this bit properly

$optionlist.= "$row['PASSENGERID']/$row['FIRSTNAME'] $row['SURNAME']";

i tried takin the ' out as it at first was givin me this error

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /var/www/htdocs/prin/u2o30/airports/verydifficult.php on line 26

but that didnt work either!

im sorry to hassle you!
i do appreciate this! thanks!

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

[PHP] $stuff=ocifetchstatement ($Statement, &$arr, 0, 20, OCI_FETCHSTATEMENT_BY_ROW);

foreach($arr as $key => $row)
{
$optionlist.= "{$row['PASSENGERID']}/{$row['FIRSTNAME']} {$row['SURNAME']}";
}[/PHP]

Silly me. Try this instead.

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

$stuff=ocifetchstatement ($Statement, &$arr, 0, 20, OCI_FETCHSTATEMENT_BY_ROW);

foreach($arr as $key => $row)
{
$optionlist.= "{$row['PASSENGERID']}";
}
:cheesy:
ive changed it to that as that is all i need!
Thank you so so so so so much!!!!!!!!!!!!!!!!
thanks!
you are a star!!!!
:cheesy:

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

Me again with one further question! if i may!

how would i go about finding,a most frequent flier, or most popular flight!

i obviously have to use my bookings table as this is where all of this information is stored, but how do i go about doing a count, where it counts the occurrance of passenger in the bookings table, and then displays how many times each occur?

$sql = "select count(passengerid) from Booking";

i know that that is how to get a count of the total passengers in the table, but how do i get a count of each individual one?


thank you again :cheesy:

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

$sql = "SELECT passengerid COUNT(*) FROM Booking GROUP BY passengerid";

i have tried that but it gives me these errors


Warning: ociexecute(): OCIStmtExecute: ORA-00923: FROM keyword not found where expected in /var/www/htdocs/prin/u2o30/airports/passengercount.php on line 20
All Bookings in the Database:

Warning: ocifetch(): OCIFetch: ORA-24374: define not done before fetch or execute and fetch in /var/www/htdocs/prin/u2o30/airports/passengercount.php on line 36

thank you

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

done it hahahahaha

$sql = "SELECT passengerid, COUNT(*) FROM Booking GROUP BY passengerid";

i just missed a comma out! :mrgreen:

Facey
Newbie Poster
12 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You