Re: [PHP-DB] First letter

2004-04-28 Thread Lang Sharpe
Cornelia Boenigk wrote:

 Hi Matt
 
 You can teat a string like an Array
 $first = $string[0];
 $second = $string[1]
 and so on.

Actually this method is deprecated. The current best way is to use curly
braces.

$first = $string{0};
$second = $string{1};


Lang

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: Categories and Items query

2003-12-30 Thread Lang Sharpe

Having a Standard only, Deluxe only and Both will lead to problems in the
future. (i.e. what if you add in a Basic feature set?) What I would do is
 
1. Get rid of the Both row in feature sets.
2. Have another table called feature_set_features or something better. The
table has two columns, The Feature id and the Feature set ID. If a
feature is in one feature set, there in one row in the table. if a Feature
is in Both feature sets, then there are two rows in this table, one for
each feature set. 
3. To query this, join features and feature_set_features on feature_id and
use where feature_set_id = 'standard' or whatever if is.

Hopefully I haven't confused you too much.

Lang


Ali Van Doren wrote:

 Hello,
 I am pretty new to PHP and MySQL, and am
 struggling with this particular page I would like
 to create.
 I am building a page which lists categories of
 house features (e.g. concrete, framing,
 foundation, etc.) and then the particular features
 that fall into those categories (e.g. the concrete
 items are driveway, garage floor, sidewalk,
 basement; the framing items include manufactured
 floor joist, 1/2 OSB on roof, etc.)  The tricky
 part is that there are two lists of features I
 need to produce: standard and deluxe.  Some
 features span both types, some are particular to
 only one feature list.
 I have created 3 tables to handle this:
 - the feature_sets table has three items: both(1),
 standard(2) only and deluxe(3) only
 - the feature_categories table holds the 19
 categories of features (concrete, framing, etc.)
 - the features table holds all of the features (63
 total.)
 All tables have primary keys, and the features
 table has 2 foreign keys corresponding to
 featureset and the featurecategory.
 
 What I would like to be able to do is to have the
 category appear, and then list the corresponding
 features under it, depending on whether it's the
 deluxe of standard feature list.  Here's my code:
 
 ?php
require_once
 ('/usr/home/fahomes/mysql_connect.php');
 $query = SELECT category, feature_description
 FROM features as f, feature_categories as fc WHERE
 f.feature_category_id=fc.feature_category_id AND
 f.featureset_id = '1' OR f.featureset_id = '3'
 ORDER BY f.feature_category_id ASC;
 $result = @mysql_query ($query);
 if ($result) {
 while ($row = mysql_fetch_array($result,
 MYSQL_NUM)) {
echo tr
td align=\left\$row[0]/td
  td
 align=\left\ulli$row[1]/ul/td
/tr\n;
 }
 mysql_free_result ($result);
 } else {
 echo 'pThe features could not be displayed due
 to a system error. Please contact the a
 href=\mailto:[EMAIL PROTECTED]webmaster/a./pp'
 . mysql_error() . '/p';
 }
 mysql_close();
 ?
 
 
 What I am getting is initially it's creating a row
 for each category/feature pair, so the categories
 that have more than one feature listed appear in
 more than one row.  It works fine until record 34
 (id 33) when it starts puking out that feature for
 10 rows then the next feature for 1 row, then it
 jumps back to the feature 33 for another 12 rows,
 this time cycling through the categories.  It's
 quite bizarre:
 http://roku.pair.com/fahomes/test/homes_dlx_features.php
 
 So, I actually have two questions:
 1) Does anyone know why my query is misbehaving so
 badly?  When I copy and paste the query into
 MyPHPAdmin, it produces the same results, so I
 know it's not the php. On thing I do notice is if
 I change the query slightly (so that it looks for
 records WHERE
 f.feature_category_id=fc.feature_category_id AND
 f.featureset_id = '1' OR '3' instead of
 f.featureset_id = '1' OR f.featureset_id = '3'
 it produces equally messed up, but different results.
 
 2) Is there a way that I can display the data the
 way I want to display it (list the category once,
 then corresponding features underneath, before
 going to the next category)?  I would imagine it's
 a WHILE loop that's inside another WHILE loop -- I
 am just not sure how to go about it, and haven't
 been able to track down anything in my books.
 
 Thanks for any advice!

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] $_POST in MySQL query issue...

2003-10-21 Thread Lang Sharpe

The reason curly braces are needed are because you are putting an array 
element into a string. Consider..

$sBlah = 'blah';
echo $sBlahfoo$sBlahfoo;

PHP will attempt to echo the variable $sBlahfoo twice. if you use

echo {$sBlah}foo{$sBlah}foo;

you have told php explicitly when to look for variable substitution. so the 
result will be 

blahfooblahfoo

PHP will not look for array elements to substitute in strings, unless you 
explicitly tell it to by using curly braces. 

$aBlah['blah'] = 'foo';
echo $aBlah['blah'];
result Parse Error

echo {$aBlah['blah']};
result :
foo

Once again, try the manual for more information

http://php.net/manual/en/language.types.string.php

Hope this helps


Lang




Adam Reiswig wrote:

 A couple of days ago I placed a post regarding using the $_POST[]
 variable in an insert sql query.  Both
 
 $sql=insert into $table set Name = '.$_POST['elementName'].';
and
 $sql=insert into $table set Name = '{$_POST['elementName']}';
 
 worked perfectly.  Thanks to everyone for your help.  My question now is
 regarding the curly brackets in the 2nd example.  Can anyone describe
 why using the curly brackets works and/or how php processes them.  I
 have read quite a bit about php and never come accross thier use in this
 way.  Thanks again.
 
 -Adam Reiswig

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: $_POST in MySQL query issue...

2003-10-16 Thread Lang Sharpe
 $sql=insert into $table set Name = '$_POST[elementName]';

The problem with this is that you need to use curly braces around the 
variable being substituted in the string. Also use single quotes around the 
array index.

$sql=insert into $table set Name = '{$_POST['elementName']}';

See the manual.. (Variable parsing section)
http://php.net/manual/en/language.types.string.php

Lang

Adam Reiswig wrote:

 Greetings to all.  I am trying for the life of me to place a $_POST[]
 variable in my MySQL query.  I am running the latest stable versions of
 PHP, MySQL and Apache 2 on my Win2kPro machine.  My register_globals are
 set to off in my php.ini.  My code I am attempting create is basically
 as follows:
 
 $table=elements;
 $sql=insert into $table set Name = '$elementName';
 
 This works with register_globals set to on.  But, I want to be able to
 turn that off.  My code then, I am guessing, be something as follows:
 
 $table=elements;
 $sql=insert into $table set Name = '$_POST[elementName]';
 
 Unfortunately this and every other combination I can think of,
 combinations of quotes that is, does not work.  I believe the source of
 the problem is the quotes within quotes within quotes. I also tried:
 
 $sql='insert into $table set Name = '.$_POST[elementName];
or
 $sql=insert into $table set Name = .$_POST['elementName'];
 
 and several other variations.
 
 Can anyone give me some pointers to inserting $_POST[] statements inside
 of query statements?  I am sure there must be a way but I have spent a
 lot of time on this and am really stumped here.  Thanks for any help.
 
 -Adam Reiswig
 
 PS if anything here is not clear to you, please let me know and I'll
 clarify as I can.  Thanks again.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: PHP crashing with using Oracle

2003-07-06 Thread Lang Sharpe

I had to change ext/oci8/config.m4
Remove the line highlighted in red on this page.

http://cvs.php.net/diff.php/php-src/ext/oci8/config.m4?login=2r1=1.37.2.6r2=1.37.2.7ty=h

The line is
AC_DEFINE(HAVE_OCI8_SHARED_MODE,1,[ ])

Then do configure/make/make install again. That will get the oci8 support to 
work. I haven't tried the oracle functions.

Lang


Reuben D. Budiardja wrote:

 
 Hello,
 I installed PHP-4.3.2 with oci8 and oracle support (using --with-oci8
 --with-oracle).
 I recompile apache-1.3.27 to use the libpthread as mentioned here:
 http://ww.php.net/oci8
 
 Now, I got crashes when using oracle with php. In my apache error logs, I
 get:
 
 [Sat Jul  5 17:24:28 2003] [notice] child pid 17496 exit signal
 [Segmentation
 fault (11)
 [Sat Jul  5 17:24:29 2003] [notice] child pid 17558 exit signal
 [Segmentation
 fault (11)
 
 and the application would just do nothing (I tried reload, submit, etc).
 
 if this happens, the only way I can fix it is by restarting apache. Could
 anyone give me pointer what's going on here  and how to fix it?
 
 In case this matters, the Oracle 9i DB server is also in the same box.
 Somehow it has it's own Apache, but I don't use that.
 
 Thanks for any help.
 RDB
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: Oracle query returning values in sqlplus, but not php.

2003-07-03 Thread Lang Sharpe

Upon further investigation, I've found that this was a permissions problem. 
In oracle, a user can see everybody's 'PACKAGE', but only their own 
'PACKAGE BODY'.

Lang

Lang Sharpe wrote:

 Hi all
 
 Here is a test version of my script. It queries the data dictionary view
 ALL_SOURCE. In sqlplus it returns all souce code in the database. In php
 it returns no rows.
 
 The only odd thing about it is that ALL_SOURCE.TYPE is VARCHAR2(12), and
 'PACKAGE BODY' is twelve characters long. When I change 'PACKAGE BODY' to
 'PACKAGE', it does return rows.
 
 ?php
 error_reporting(E_ALL);
 $oradb = OCILogon('','','');
 
 $packageStmt = OCIParse($oradb,
 SELECT * FROM ALL_SOURCE WHERE TYPE = 'PACKAGE BODY');
 OCIExecute($packageStmt);
 if(OCIFetchInto($packageStmt,$aLine,OCI_ASSOC)) {
   echo Cool Bananas\n;
   var_dump($aLine);
 } else {
   echo No Bananas\n;
 }
 
 OCILogoff($oradb);
 ?
 
 Im using PHP 4.3.2 Linked to Oracle 9.2.0.1.0 libraries connecting to
 oracle 9.2.0.1.0 database on another machine. Can someone confirm it is
 only me?
 
 Lang


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Oracle query returning values in sqlplus, but not php.

2003-06-30 Thread Lang Sharpe
Hi all

Here is a test version of my script. It queries the data dictionary view 
ALL_SOURCE. In sqlplus it returns all souce code in the database. In php it 
returns no rows.

The only odd thing about it is that ALL_SOURCE.TYPE is VARCHAR2(12), and 
'PACKAGE BODY' is twelve characters long. When I change 'PACKAGE BODY' to 
'PACKAGE', it does return rows.

?php
error_reporting(E_ALL);
$oradb = OCILogon('','','');

$packageStmt = OCIParse($oradb,
SELECT * FROM ALL_SOURCE WHERE TYPE = 'PACKAGE BODY');
OCIExecute($packageStmt);
if(OCIFetchInto($packageStmt,$aLine,OCI_ASSOC)) {
  echo Cool Bananas\n;
  var_dump($aLine);
} else {
  echo No Bananas\n;
}

OCILogoff($oradb);
?

Im using PHP 4.3.2 Linked to Oracle 9.2.0.1.0 libraries connecting to oracle 
9.2.0.1.0 database on another machine. Can someone confirm it is only me?

Lang


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php