
works under mysql 5 but not under Oracle 11g1
//construct a global variable for the form profile
$fields = array("fdate", "actype", "acid", "nlandings", "nhours");
problem down in while loop
... . . . . .
function displayDeleteForm(){
//get $fields into the function namespace
global $fields;
global $conn;
/* Create and execute query. */
// $query = "select * from log_book_id";
// $result = mysql_query($query);
// Loop through each row, outputting the actype and name
echo <<<HTML
Pilots Logbook entries stored in mySQL Relational Database
under Redhat Fedora 8 Linux
<form action="{$_SERVER['PHP_SELF']}" method="post">
<table width="50%" align="center" border="1">
<tr>
<th>checked</th>
<th>rowID</th>
<th>fdate</th>
<th>actype</th>
<th>acid</th>
<th>nlandings</th>
<th>nhours</th>
</tr>
HTML;
//get log_book_id table information
$user = "select * from log_book_id";
$result = oci_parse($conn, $user);
$r = oci_execute($result);
//display log_book_id information
$count = 0;
while ($newArray = oci_fetch_assoc($result)) {
foreach ($fields as $field){
${$field} = $newArray[$field]; // values not making it into variable
}
$rowID = $newArray['rowID'];
//note that we do not rely on the checkbox value as not all browsers submit it
//instead we rely on the name of the checkbox.
echo <<<HTML
<TR>
<td>
<input type="checkbox" name="checkbox[$rowID]" value="$rowID">Check to delete record
</td>
<TD>$rowID</TD>
<TD>$fdate</TD>
<TD>$actype</TD>
<TD>$acid</TD>
<TD>$nlandings</TD>
<TD>$nhours</TD>
</TR>
HTML;
} // while
echo <<<HTML
<tr>
<td colspan="7">
<input type="submit" name="delete" value="delete checked items"/>
<input type="submit" name="new" value="New Log Entry" />
<input type="reset" name="reset" value="Reset Form" />
</td>
</tr>
</table>
</form>
HTML;
} //close function
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
Fred Silsbee wrote:
> while ($newArray = oci_fetch_assoc($result)) {
> foreach ($fields as $field){
> ${$field} = $newArray[$field]; // values not making it into variable
>
> }
print_r($newArray);
what is here?
Oracle uppercases all fields, tablenames by default (per sql spec).
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
--- On Mon, 11/24/08, Chris <dmagick [at] gmail.com> wrote:
> From: Chris <dmagick [at] gmail.com>
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: fredsilsbee [at] yahoo.com
> Cc: php-db [at] lists.php.net
> Date: Monday, November 24, 2008, 6:41 AM
> Fred Silsbee wrote:
>
> > while ($newArray = oci_fetch_assoc($result)) {
> > foreach ($fields as $field){
> ${$field} = $newArray[$field]; // values not
> making it into variable
> > }
>
>
> print_r($newArray);
>
> what is here?
>
> Oracle uppercases all fields, tablenames by default (per
> sql spec).
>
> -- Postgresql & php tutorials
> http://www.designmagick.com/
I am new to PHP and I was wondering if an array can contain dissimilar types
while ($newArray = oci_fetch_assoc($result)) {
surely a DB row might contain :
create table log_book_id ( log_id number primary key, fdate date, actype varchar2(16), acid varchar(16), nlandings number, nhours number);
insert into log_book_id values (logid.nextval, TO_DATE('08/12/1973','MM/dd/YYYY'),'C150','N5787G',1,1.8);
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
--- On Mon, 11/24/08, Chris <dmagick [at] gmail.com> wrote:
> From: Chris <dmagick [at] gmail.com>
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: fredsilsbee [at] yahoo.com
> Cc: php-db [at] lists.php.net
> Date: Monday, November 24, 2008, 6:41 AM
> Fred Silsbee wrote:
>
> > while ($newArray = oci_fetch_assoc($result)) {
> > foreach ($fields as $field){
> ${$field} = $newArray[$field]; // values not
> making it into variable
> > }
>
>
> print_r($newArray);
>
> what is here?
>
> Oracle uppercases all fields, tablenames by default (per
> sql spec).
>
> -- Postgresql & php tutorials
> http://www.designmagick.com/
here is the whole thing:
<?php
$db = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = LMKIIIGDNSID)
)
)";
// oci_internal_debug(1); // turn on tracing
// $conn = oci_connect("/", "", null, null, OCI_SYSDBA);
// if ($conn=oci_connect('hr', 'hr','LMKIIIGDNSID'))
if ($conn=oci_connect('landon', 'rumprocella',$db))
{
echo "Successfully connected to Oracle.\n";
// OCILogoff($conn);
}
else
{
$err = OCIError();
echo "Oracle Connect Error " . $err['message'];
}
//construct a global variable for the form profile
$fields = array("fdate", "actype", "acid", "nlandings", "nhours");
///
// If the submit button has been pressed
if (isset($_POST['select'])){
displayDeleteForm();
}elseif(isset($_POST['delete'])){
deleteRecords();
} elseif(isset($_POST['insert'])){
insertRecord();
} elseif (isset($_POST['new'])){
displayEntryForm();
} else {
//default action
displayEntryForm();
}
function displayDeleteForm(){
//get $fields into the function namespace
global $fields;
global $conn;
/* Create and execute query. */
// $query = "select * from log_book_id";
// $result = mysql_query($query);
// Loop through each row, outputting the actype and name
echo <<<HTML
Pilots Logbook entries stored in mySQL Relational Database
under Redhat Fedora 8 Linux
<form action="{$_SERVER['PHP_SELF']}" method="post">
<table width="50%" align="center" border="1">
<tr>
<th>checked</th>
<th>log_id</th>
<th>fdate</th>
<th>actype</th>
<th>acid</th>
<th>nlandings</th>
<th>nhours</th>
</tr>
HTML;
//get log_book_id table information
$user = "select * from log_book_id";
$result = oci_parse($conn, $user);
$r = oci_execute($result);
//display log_book_id information
$count = 0;
while ($newArray = oci_fetch_assoc($result)) {
foreach ($fields as $field){
${$field} = $newArray[$field];
// print("$field<BR>");
}
// echo $newArray['actype'] . "<br>";
$log_id = $newArray['rowID'];
// $log_id = $newArray['LOG_ID'];
// print($log_id);
//note that we do not rely on the checkbox value as not all browsers submit it
//instead we rely on the name of the checkbox.
echo <<<HTML
<TR>
<td>
<input type="checkbox" name="checkbox[$log_id]" value="$rowID">Check to delete record
</td>
<TD>$log_id</TD>
<TD>$fdate</TD>
<TD>$actype</TD>
<TD>$acid</TD>
<TD>$nlandings</TD>
<TD>$nhours</TD>
</TR>
HTML;
} // while
echo <<<HTML
<tr>
<td colspan="7">
<input type="submit" name="delete" value="delete checked items"/>
<input type="submit" name="new" value="New Log Entry" />
<input type="reset" name="reset" value="Reset Form" />
</td>
</tr>
</table>
</form>
HTML;
} //close function
// ............................................................ ..... DELETE
// code from a book "Beg PHP and MySQL 5" by Gilmore
function deleteRecords(){
// Loop through each log_book_id with an enabled checkbox
if (!isset($_POST['checkbox'])){
return true;
}
//else
foreach($_POST['checkbox'] as $key=>$val){
$toDelete[] = $key;
}
//expand the array for an IN query
$where = implode(',', $toDelete);
$query = "DELETE FROM log_book_id WHERE log_id IN ($where)";
$result = oci_parse($query);
// Should have one affected row
if ((mysql_affected_rows() === 0) || !$result) {
echo "<p>There was a problem deleting some of the selected items.</p><p>".mysql_error().'</p>';
exit();
} else {
echo "<p>The selected items were successfully deleted.</p>";
}
//direct the user back to the delete form
displayDeleteForm();
} //end function
function insertRecord(){
// Retrieve the posted log book information.
global $fields;
//add some very crude validation
foreach ($fields as $field){
if (empty($_POST[$field])){
$messages[] = "You must complete the field $field \r\n";
} else {
$dFields[$field] = mysql_real_escape_string(trim($_POST[$field]));
}
}
if (count($messages)>0) {
displayEntryForm($messages, $dFields);
exit();
}
//end validation
//get variables into the namespace
extract($dFields);
// Insert the log book information into the log book table
$query = "INSERT INTO log_book_id SET fdate='$fdate', actype='$actype',
acid='$acid', nlandings='$nlandings', nhours = '$nhours'";
$result = oci_query($query);
// Display an appropriate message
if ($result) {
echo "<p>Product successfully inserted!</p>";
}else {
echo "<p>There was a problem inserting the log book!</p>";
}
//direct the user back to the entry form
displayEntryForm();
}
function displayEntryForm($errorMessages=null, $dFields=null){
if (!empty($errorMessages)){
echo "<ul><li>".explode('</li><li>', $errorMessages) . "</li></ul>";
}
//sort out field values
global $fields;
foreach ($fields as $field){
if (isset($dFields[$field])){
${$field} = $dFields[$field];
} else {
${$field} = '';
}
}
echo <<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="post">
<p>
Flight Date:
<input type="text" size="20" maxlength="40" name="fdate"
value="$fdate" />
</p>
<p>
Aircraft Type:
<input type="text" size="20" maxlength="40" name="actype"
value="$actype" />
</p>
<p>
Aircraft ID:
<input type="text" size="20" maxlength="40" name="acid"
value="$acid" />
</p>
<p>
Number Landings:
<input type="text" size="20" maxlength="40" name="nlandings"
value="$nlandings" />
</p>
<p>
Number Hours:
<input type="text" size="20" maxlength="40" name="nhours"
value="$nhours" />
</p>
<button type="submit" name = "insert" value="Insert Row!"
style="color:maroon font:18pt Courier; font-weight:bold ">Insert Row
</button>
<button type="submit" name = "select" value="Show All!"
style="color:red font:18pt Courier; font-weight:bold ">Show All
</button>
<button type="submit" name = "delete" value="Delete Row!"
style="color:red font:18pt Courier; font-weight:bold ">Delete Row!
</button>
</form>
HTML;
} //end display function
?>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
--- On Mon, 11/24/08, Chris <dmagick [at] gmail.com> wrote:
> From: Chris <dmagick [at] gmail.com>
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: fredsilsbee [at] yahoo.com
> Cc: php-db [at] lists.php.net
> Date: Monday, November 24, 2008, 6:41 AM
> Fred Silsbee wrote:
>
> > while ($newArray = oci_fetch_assoc($result)) {
> > foreach ($fields as $field){
> ${$field} = $newArray[$field]; // values not
> making it into variable
> > }
>
>
> print_r($newArray);
>
> what is here?
>
> Oracle uppercases all fields, tablenames by default (per
> sql spec).
>
> -- Postgresql & php tutorials
> http://www.designmagick.com/
That code showed all...THANKS!
The data is being extracted but not making it to the variables.
while ($newArray = oci_fetch_assoc($result)) {
print_r($newArray); // everything!!! is there
foreach ($fields as $field){
${$field} = $newArray[$field]; // here...works under MySQL
}
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
--- On Mon, 11/24/08, Fred Silsbee <fredsilsbee [at] yahoo.com> wrote:
> From: Fred Silsbee <fredsilsbee [at] yahoo.com>
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: "Chris" <dmagick [at] gmail.com>
> Cc: php-db [at] lists.php.net
> Date: Monday, November 24, 2008, 2:44 PM
> --- On Mon, 11/24/08, Chris <dmagick [at] gmail.com> wrote:
>
> > From: Chris <dmagick [at] gmail.com>
> > Subject: Re: [PHP-DB] works under mysql 5 but not
> under Oracle 11g1
> > To: fredsilsbee [at] yahoo.com
> > Cc: php-db [at] lists.php.net
> > Date: Monday, November 24, 2008, 6:41 AM
> > Fred Silsbee wrote:
> >
> > > while ($newArray = oci_fetch_assoc($result))
> {
> > > foreach ($fields as $field){
>
> > ${$field} = $newArray[$field]; // values
> not
> > making it into variable
> > > }
>
> >
> >
> > print_r($newArray);
> >
> > what is here?
> >
> > Oracle uppercases all fields, tablenames by default
> (per
> > sql spec).
> >
> > -- Postgresql & php tutorials
> > http://www.designmagick.com/
>
>
> That code showed all...THANKS!
>
> The data is being extracted but not making it to the
> variables.
>
> while ($newArray = oci_fetch_assoc($result)) {
> print_r($newArray); //
> everything!!! is there
> foreach ($fields as $field){
> ${$field} = $newArray[$field]; //
> here...works under MySQL
> }
fixed the problem but am not fully sure of the optimum code one should use!
I like the association idea but must change the $fields array
There is a better way than using count!
67 //get log_book_id table information
68 $user = "select * from log_book_id";
69 $result = oci_parse($conn, $user);
70 $r = oci_execute($result);
71
72 //display log_book_id information
73
74 while ($newArray = oci_fetch_row($result)) {
75 // print_r($newArray);
76 $count = 1;
77 foreach ($fields as $field){
78 ${$field} = $newArray[$count];
79 $count = $count +1;
80 // print_r(${$field});
81 // print_r($newArray[$field]);
82 }
83 $rowID = $newArray[0];
84
85 //note that we do not rely on the checkbox value as not all browsers submit it
86 //instead we rely on the name of the checkbox.
87 echo <<<HTML
88 <TR>
89 <td>
90 <input type="checkbox" name="checkbox[$rowID]" value="$rowID">Check to delete record
91 </td>
92 <TD>$rowID</TD>
93 <TD>$fdate</TD>
94 <TD>$actype</TD>
95 <TD>$acid</TD>
96 <TD>$nlandings</TD>
97 <TD>$nhours</TD>
98 </TR>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
> fixed the problem but am not fully sure of the optimum code one should use!
>
> I like the association idea but must change the $fields array
>
> There is a better way than using count!
>
> 67 //get log_book_id table information
> 68 $user = "select * from log_book_id";
> 69 $result = oci_parse($conn, $user);
> 70 $r = oci_execute($result);
> 71
> 72 //display log_book_id information
> 73
> 74 while ($newArray = oci_fetch_row($result)) {
> 75 // print_r($newArray);
What does line 75 show and what do you expect it to show?
> 85 //note that we do not rely on the checkbox value as not all browsers submit it
> 86 //instead we rely on the name of the checkbox.
Well, that's wrong. The value is submitted IF the checkbox is ticked. If
it is not ticked, it is not submitted (this is the same in any language,
it's not a php specific thing).
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
--- On Mon, 11/24/08, Chris <dmagick [at] gmail.com> wrote:
> From: Chris <dmagick [at] gmail.com>
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: fredsilsbee [at] yahoo.com
> Cc: php-db [at] lists.php.net
> Date: Monday, November 24, 2008, 10:00 PM
> > fixed the problem but am not fully sure of the optimum
> code one should use!
> >
> > I like the association idea but must change the
> $fields array
> >
> > There is a better way than using count!
> >
> > 67 //get log_book_id table information
> > 68 $user = "select * from
> log_book_id";
> > 69 $result = oci_parse($conn, $user);
> > 70 $r = oci_execute($result);
> > 71
> > 72 //display log_book_id information
> > 73
> > 74 while ($newArray = oci_fetch_row($result))
> {
> > 75 // print_r($newArray);
>
> What does line 75 show and what do you expect it to show?
>
>
> > 85 //note that we do not rely on the
> checkbox value as not all browsers submit it
> > 86 //instead we rely on the name of the
> checkbox.
>
> Well, that's wrong. The value is submitted IF the
> checkbox is ticked. If it is not ticked, it is not submitted
> (this is the same in any language, it's not a php
> specific thing).
>
> -- Postgresql & php tutorials
> http://www.designmagick.com/
Array ( [LOG_ID] => 405 [FDATE] => 15-JUL-01 [ACTYPE] => C172 [ACID] => N17SJ [NLANDINGS] => 1 [NHOURS] => 1.2 )
thanks for the print_r tip!
I need to fix
${$field} = $newArray[$field]; ?? i need to properly use the association
I have seen no mention of the syntax ${$field} even though it looks reasonable!
I have two 900 pages books on "MySQL and PHP 5" one is 2 years old and the other is 2 years old
The check mark doesn't come into play until delete rows is selected.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
--- On Mon, 11/24/08, Fred Silsbee <fredsilsbee [at] yahoo.com> wrote:
> From: Fred Silsbee <fredsilsbee [at] yahoo.com>
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: "Chris" <dmagick [at] gmail.com>
> Cc: php-db [at] lists.php.net
> Date: Monday, November 24, 2008, 10:31 PM
> --- On Mon, 11/24/08, Chris <dmagick [at] gmail.com> wrote:
>
> > From: Chris <dmagick [at] gmail.com>
> > Subject: Re: [PHP-DB] works under mysql 5 but not
> under Oracle 11g1
> > To: fredsilsbee [at] yahoo.com
> > Cc: php-db [at] lists.php.net
> > Date: Monday, November 24, 2008, 10:00 PM
> > > fixed the problem but am not fully sure of the
> optimum
> > code one should use!
> > >
> > > I like the association idea but must change the
> > $fields array
> > >
> > > There is a better way than using count!
> > >
> > > 67 //get log_book_id table information
> > > 68 $user = "select * from
> > log_book_id";
> > > 69 $result = oci_parse($conn, $user);
> > > 70 $r = oci_execute($result);
> > > 71
> > > 72 //display log_book_id information
> > > 73
> > > 74 while ($newArray =
> oci_fetch_row($result))
> > {
> > > 75 // print_r($newArray);
> >
> > What does line 75 show and what do you expect it to
> show?
> >
> >
> > > 85 //note that we do not rely on the
> > checkbox value as not all browsers submit it
> > > 86 //instead we rely on the name of
> the
> > checkbox.
> >
> > Well, that's wrong. The value is submitted IF the
> > checkbox is ticked. If it is not ticked, it is not
> submitted
> > (this is the same in any language, it's not a php
> > specific thing).
> >
> > -- Postgresql & php tutorials
> > http://www.designmagick.com/
>
> Array ( [LOG_ID] => 405 [FDATE] => 15-JUL-01 [ACTYPE]
> => C172 [ACID] => N17SJ [NLANDINGS] => 1 [NHOURS]
> => 1.2 )
>
You will not beleiev this!
That great print_rt tip you gave me showed upper case keys in the association.....so
74 $count = 0;
75 while ($newArray = oci_fetch_assoc($result)) {
76 if ($count == 0) print_r($newArray);
77 $count = 1;
78 foreach ($fields as $field){
79 $fieldx = strtoupper($field); fixed <<<<<<<<<<<<<
80 ${$field} = $newArray[$fieldx];
81 $count = $count +1;
82 // print($field);
83 // print_r($newArray[$field]);
84 }
Not using count!
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: works under mysql 5 but not under Oracle 11g1
> Array ( [LOG_ID] => 405 [FDATE] => 15-JUL-01 [ACTYPE] => C172 [ACID] => N17SJ [NLANDINGS] => 1 [NHOURS] => 1.2 )
So everything is uppercase where you're expecting lower case.
while ($newArray = oci_fetch_assoc($result))
{
foreach ($fields as $field){
$field = strtoupper($field);
echo $newArray[$field] . "\n";
not an ideal solution but it'll work.
> thanks for the print_r tip!
>
> I need to fix
>
> ${$field} = $newArray[$field]; ?? i need to properly use the association
>
> I have seen no mention of the syntax ${$field} even though it looks reasonable!
Variable variables
(http://www.php.net/manual/en/language.variables.variable.ph p).
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php