Re: [PHP] Two ways to obtain an object property

2012-08-16 Thread phplist

On 08/15/2012 11:28 AM, phplist wrote:

This relates to a minor dilemma I come across from time and time, and
I'm looking for advice [...]

Within a site I have a User object, and within page code would like to
have
if ($crntUser-isASubscriber) {...}
[...]
if ($crntUser-isASubscriber()) {...}
[...]
Is either of these approaches preferable, or does it simply not matter?



Thanks to all who responded. Inevitably the answer is it depends but 
I've now got a much better feel about how to decide.


Roddie Grant

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



[PHP] Two ways to obtain an object property

2012-08-15 Thread phplist
This relates to a minor dilemma I come across from time and time, and 
I'm looking for advice on pros and cons and best practice. Last night I 
encountered it again.


Within a site I have a User object, and within page code would like to have
if ($crntUser-isASubscriber) {...}

There seems to be two ways to handle this:

I can have a User object method getSubscriberStatus() which sets 
$this-isASubscriber. But to use this I would have to run the method 
just before the if statement.


Or I could have a method isASubscriber() which returns the result, 
meaning the if statement should be

if ($crntUser-isASubscriber()) {...}

While this is last night's specific example, I seem to face the 
method-setting-variable or the method-returning-result-directly decision 
quite often.


Is either of these approaches preferable, or does it simply not matter?

Thanks

Roddie Grant

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



Re: [PHP] How does the Zend engine behave?

2006-10-26 Thread jeff . phplist



Jon Anderson wrote:
Take this with a grain of salt. I develop with PHP, but I am not an 
internals guy...


[EMAIL PROTECTED] wrote:
Are the include files only compiled when execution hits them, or are 
all include files compiled when the script is first compiled, which 
would mean a cascade through all statically linked include files. By 
statically linked files I mean ones like include ('bob.php') - i.e 
the filename isn't in a variable.
Compiled when execution hits them. You can prove this by trying to 
conditionally include a file with a syntax error: if (false) 
include('script_with_syntax_error.php'); won't cause an error.


Good idea.



Secondly, are include files that are referenced, but not used, loaded 
into memory? I.e Are statically included files automatically loaded 
into memory at the start of a request? (Of course those where the 
name is variable can only be loaded once the name has been 
determined.) And when are they loaded into memory? When the 
instruction pointer hits the include? Or when the script is initially 
loaded?
If your include file is actually included, it will use memory. If it 
is not included because of some condition, then it won't use memory.


I wonder if that's the same when a cache/optimiser is used. Probably. 
Maybe I'll check.


Are included files ever unloaded? For instance if I had 3 include 
files and no loops, once execution had passed from the first include 
file to the second, the engine might be able to unload the first 
file. Or at least the code, if not the data.
If you define a global variable in an included file and don't unset it 
anywhere, then it isn't automatically unloaded, nor are 
function/class definitions unloaded when execution is finished.


Once you include a file, it isn't unloaded later though - even 
included files that have just executed statements (no definitions 
saved for later) seem to eat a little memory once, but it's so minimal 
that you wouldn't run into problems unless you were including many 
thousand files. Including the same file again doesn't eat further 
memory. I assume the eaten memory is for something to do with 
compilation or caching in the ZE.
Thirdly, I understand that when a request arrives, the script it 
requests is compiled before execution. Now suppose a second request 
arrives for the same script, from a different requester, am I right 
in assuming that the uncompiled form is loaded? I.e the script is 
tokenized for each request, and the compiled version is not loaded 
unless you have engine level caching installed - e.g. MMCache or Zend 
Optimiser.
I think that's correct. If you don't have an opcode cache, the script 
is compiled again for every request, regardless of who requests it.


IMO, you're probably better off with PECL/APC or eAccelerator rather 
than MMCache or Zend Optimizer. I use APC personally, and find it 
exceptional - rock solid + fast. (eAccelerator had a slight 
performance edge for my app up until APC's most recent release, where 
APC now has a significant edge.)

Thanks - that's useful to know.


Fourthly, am I right in understanding that scripts do NOT share 
memory, even for the portions that are simply instructions? That is, 
when the second request arrives, the script is loaded again in full. 
(As opposed to each request sharing the executed/compiled code, but 
holding data separately.)

Yep, I think that's also correct.
Fifthly, if a script takes 4MB, given point 4, does the webserver 
demand 8MB if it is simultaneously servicing 2 requests?

Yep. More usually with webserver/PHP overhead.
Lastly, are there differences in these behaviors for PHP4 and PHP5? 
Significant differences between 4 and 5, but with regards to the 
above, I think they're more or less the same.


Thanks Jon. So in summary: use a cache if possible. Late load files to 
save memory. Buy more memory to handle more sessions. And it's 
conceivable that when caches are used, different rules may apply.


Jeff

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



Re: [PHP] How does the Zend engine behave?

2006-10-26 Thread jeff . phplist



Richard Lynch wrote:

On Wed, October 25, 2006 11:58 am, [EMAIL PROTECTED] wrote:
  

Are the include files only compiled when execution hits them, or are
all
include files compiled when the script is first compiled, which would
mean a cascade through all statically linked include files. By
statically linked files I mean ones like include ('bob.php') - i.e
the
filename isn't in a variable.



As far as I know, the files are only loaded as execution hits them.

If your code contains:

?php
  if (0){
require 'foo.inc';
  }
?

Then foo.inc will never ever be read from the hard drive.

You realize you could have tested this in less time than it took you
to post, right?.
:-)
  
I don't know the extent to which the engine optimises performance, and I 
know very little about how different versions of the engine deal with 
the issue, but I guessed it depended on the behaviour of the engine, 
cache and maybe optimiser, and know/knew I don't know enough...  My 
thinking: for dynamically linked files, one speed optimisation is to 
load the file before it's needed, at the expense of memory, while 
continuing execution of the loaded portions. It's easy to do if the 
filename is static. The code may never be executed, but still takes up 
space. Some data structures can also be pre-loaded in this way.



  

Are included files ever unloaded? For instance if I had 3 include
files
and no loops, once execution had passed from the first include file to
the second, the engine might be able to unload the first file. Or at
least the code, if not the data.



I doubt that the code is unloaded -- What if you called a function
from the first file while you were in the second?
  
I agree it's unlikely, but it's feasible if coded is loaded whenever 
required. Especially if data and code are separated by the engine, and 
that's quite likely because of the garbage collection.


  

Thirdly, I understand that when a request arrives, the script it
requests is compiled before execution. Now suppose a second request
arrives for the same script, from a different requester, am I right in
assuming that the uncompiled form is loaded? I.e the script is
tokenized
for each request, and the compiled version is not loaded unless you
have
engine level caching installed - e.g. MMCache or Zend Optimiser.



You are correct.

The Caching systems such as Zend Cache (not the Optimizer), MMCache,
APC, etc are expressly designed to store the tokenized version of the
PHP script to be executed.

Note that their REAL performance savings is actually in loading from
the hard drive into RAM, not actually the PHP tokenization.

Skipping a hard drive seek and read is probably at least 95% of the
savings, even in the longest real-world scripts.

The tokenizer/compiler thingie is basically easy chump change they
didn't want to leave on the table, rather than the bulk of the
performance win.

I'm sure somebody out there has perfectly reasonable million-line PHP
script for a valid reason that the tokenization is more than 5% of the
savings, but that's going to be a real rarity.

  
Thanks - that's really useful - I didn't realise that the bulk of the 
saving wasn't in tokenising.

Fourthly, am I right in understanding that scripts do NOT share
memory,
even for the portions that are simply instructions? That is, when the
second request arrives, the script is loaded again in full. (As
opposed
to each request sharing the executed/compiled code, but holding data
separately.)



Yes, without a cache, each HTTP request will load a different script.
  
Do you know if, when a cache is used, whether requests in the same 
thread use the same in-memory object. I.e. Is the script persistent in 
the thread?


  

Fifthly, if a script takes 4MB, given point 4, does the webserver
demand
8MB if it is simultaneously servicing 2 requests?



If you have a PHP script that is 4M in length, you've done something
horribly wrong. :-)
  
Sort of. I'm using Drupal with lots of modules loaded. PHP memory_limit 
is set to 20MB, and at times 20MB is used. I think that works per 
request. All the evidence points to that. So 10 concurrent requests, 
which is not unrealistic, it could use 400MB + webserver overhead. And I 
still want to combine it with another bit of software that will use 10 
to 15MB per request. It's time to think about memory usage and whether 
there are any strategies to disengage memory usage from request rate.




Of course, if it loads a 4M image file, then, yes, 2 at once needs 8M
etc.

  

Lastly, are there differences in these behaviors for PHP4 and PHP5?



I doubt it.

I think APC is maybe going to be installed by default in PHP6 or
something like that, but I dunno if it will be on by default or
not...

At any rate, not from 4 to 5.


  

Thanks.


Note that if you NEED a monster body of code to be resident, you can
prototype it in simple PHP, port it to C, and have it be a PHP
extension.
  

A good idea, but not feasible in this 

[PHP] How does the Zend engine behave?

2006-10-25 Thread jeff . phplist

Hi,

I'm using PHP 4.x and I'm trying to understand a bit about memory usage...

Firstly, when I say 'include files' below, I mean all forms, include, 
require and the _once versions.


That said, when a script runs and it's made of several include files, 
what happens?


Are the include files only compiled when execution hits them, or are all 
include files compiled when the script is first compiled, which would 
mean a cascade through all statically linked include files. By 
statically linked files I mean ones like include ('bob.php') - i.e the 
filename isn't in a variable.


Secondly, are include files that are referenced, but not used, loaded 
into memory? I.e Are statically included files automatically loaded into 
memory at the start of a request? (Of course those where the name is 
variable can only be loaded once the name has been determined.) And when 
are they loaded into memory? When the instruction pointer hits the 
include? Or when the script is initially loaded?


Are included files ever unloaded? For instance if I had 3 include files 
and no loops, once execution had passed from the first include file to 
the second, the engine might be able to unload the first file. Or at 
least the code, if not the data.


Thirdly, I understand that when a request arrives, the script it 
requests is compiled before execution. Now suppose a second request 
arrives for the same script, from a different requester, am I right in 
assuming that the uncompiled form is loaded? I.e the script is tokenized 
for each request, and the compiled version is not loaded unless you have 
engine level caching installed - e.g. MMCache or Zend Optimiser.


Fourthly, am I right in understanding that scripts do NOT share memory, 
even for the portions that are simply instructions? That is, when the 
second request arrives, the script is loaded again in full. (As opposed 
to each request sharing the executed/compiled code, but holding data 
separately.)


Fifthly, if a script takes 4MB, given point 4, does the webserver demand 
8MB if it is simultaneously servicing 2 requests?


Lastly, are there differences in these behaviors for PHP4 and PHP5?

Many thanks,

Jeff

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



[PHP] Serialize

2006-05-24 Thread phplist
Hi,

Is a serialized array a safe string to insert into a mysql text field? Or is a
function such as mysql_real_escape_string always needed?

regards
Simon.

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



[PHP] Re robi: Re:[PHP] Is there any good examples of PHPLIB?

2004-05-23 Thread phplist
Hi~robi!

Thank you,troby,my friend!
With your guidance I found first time that PEAR is a very good coding tool which 
I'd  like to learn later.But my server provider do not have it;fortunately,I overcomed 
the difficultys of PHPLIB by debugging and testing yesterday.
To respond your kindness,I provide a good website to you which you probably not 
knowed  before,that is http://www.phpclasses.org .How many PHP codes,classes and 
examples free shared here!I like the site very much.I'm from China,I'd like to make 
friends with you and any other PHP users:-)

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



[PHP] Re: Hi

2004-05-05 Thread Phplist
attachment: zqyshdiypg.bmp-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] A question about PHP-MySQL'basic operation

2004-04-20 Thread PHPLIST
php-general

I've a PHP-MySQL site now.
I've a empty database named 'dsx'.
I'd like to creat a table named 'test' and insert some data in order 
to test the database can use now.
Can any one give me some code about this,FROM connect TO query?
 Thank you in advance.





PHPLIST
[EMAIL PROTECTED]
2004-04-21

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



[PHP] Re: errorno error codes

2002-12-16 Thread phplist
Yes I know that. It returns a number. Meanwhile I found out that 11 (what is
returned in my case) means that I have to try again, something like a
temporary unavailable resource. It is weird that the same program on the
command line returns a string to stdout without a problem. When I used it
from PHP then I get the errorno 11. Most likely it is a problem with the
program, not PHP or anything else, don't you agree? Unfortunately it is not
my program, I am obliged to use it, so I'm kind of stuck.



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




[PHP] Re: Encrypt and decrypt cookie

2002-12-16 Thread phplist
I am not a specialist, but I discovered the parameter iv and the
related function create_iv. Most likely you must provide an created iv
before encryption, store the cypher and the iv together in the cookie and at
retreaval, use both in decrypt.

So in between:

/* Terminate encryption handler */
mcrypt_generic_deinit ($td);

/* Initialize encryption module for decryption */
mcrypt_generic_init ($td, $key, $iv);

you store and retreave from the cookie both $iv and $td. $key must be on
your server. $iv must be some
random stuff that changes between encryption and decryption (between
sessions). Play with it and you will find out.



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




[PHP] errorno error codes

2002-12-13 Thread phplist
In reality this is a linux question. If I use in PHP passthru or system, the
linux OS will return an error number. Somebody can provide me with a link
where they are listed and explained?

--
René
www.comunica2.net



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




[PHP] Re: Sorry if repost - more ftp problems

2002-12-13 Thread phplist
 Fatal error: Maximum execution time of 90 seconds exceeded in
:\apache\htdocs\fnusa\releases\ftp.php on line 28

This means that after entering in passive mode it has used 90 seconds of
processor time and times out. Set this timeout higher in php.ini. And I
would add this to the source just before the most time consuming statement:


.
.
.
set_time_limit();
fputs( $fp, STOR $source_file\r\n );
.
.
.

When called, set_time_limit() restarts the timeout counter from zero. Still
when the uploading takes more than 90 seconds, it will be interrupted. And
in fact you will never know how long it takes.



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




[PHP] passthru returns with errno 11

2002-12-13 Thread phplist
What could that mean errno 11 when I try to run a small program with four
parameters. From a shell prompt it works. What does it mean errno 11?

--
René
www.comunica2.net



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




[PHP] linking to secure ssl page using php and Microsoft Explorer - general error serviing up page from MSE... Netscape works fine

2002-09-01 Thread phplist

Get general MSE error when using PHP to go from a non-secure page to an ssl
page. If I use the back button and try it again it will work, so the code
seems solid. Does not fail on Netscape. I heard that there is a Microsoft
Explorer issue with secure pages and/or php. Any ideas on how to resolve?
Stan


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




[PHP] credit card auth using curl function

2002-08-29 Thread phplist

Hi, I am using the CURL command to post credit card info to a gateway .exe
program on a secure server. The code below works fine to produce the comma
delimitted credit card authorization information to the browser page
(for example: declined,Invalid form data
posted,8/29/2002,18:07,0,0 ), but I need to capture the
credit card gateway authorization string so that I can take action within my
PHP code, versus the user receiving the auth code returned on the browser
page.

Here is the code I am using:
htmlbody

?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$ch = curl_init();

curl_setopt($ch,
CURLOPT_URL,http://secure.ibill.com/cgi-win/ccard/tpcard15.exe;);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
reqtype=authorizeaccount=107036password=amount=12);

curl_exec ($ch);
curl_close ($ch);
?

/body/html

It produces:
declined,Invalid form data
posted,8/29/2002,18:07,0,0  at the browser... It is a
valid decline on the credit card, which I am no concerned with, but I don't
have this return to the user, want to parse the string and produce my own
php output based on accepted or declined status.

Any ideas?

Stan


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




FW: [PHP] Re: credit card auth using curl function

2002-08-29 Thread phplist

Thanks for the help. I made the change as follows, as I don't mind it
be transient data... but I still get the string outputted on the web page. I
can parse the string all I want, but the following code still prints out the
annoying string on the webpage. Any ideas where I am going wrong?  Stan

Here's the code I used based on suggestion:

htmlbody

?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$ch = curl_init();
curl_setopt($ch,
CURLOPT_URL,http://secure.ibill.com/cgi-win/ccard/tpcard15.exe;);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,
CURLOPT_POSTFIELDS,reqtype=authorizeaccount=107036password=amount=12
);

curl_setopt($ch, RETURNTRANSFER, 1);
$return_data = curl_exec($ch);

curl_close ($ch); ?

 /body/html



--


-Original Message-
From: phplist [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 29, 2002 7:32 PM
To: [EMAIL PROTECTED]
Subject: FW: [PHP] Re: credit card auth using curl function




-Original Message-
From: Mike Mannakee [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 29, 2002 5:45 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: credit card auth using curl function


Absolutely.  Your best bet, leaving the most visible way of tracing the
steps on any authorization, would be to save the returned string to a file.
Open the file and pass the handle to CURL_SETOPT like

curl_setopt($ch, CURLOPT_FILE, $return_data_fp);

Then have your script parse the data and output to the user appropriately.

Alternately, you can set RETURNTRANSFER and put the string in a variable,
like

curl_setopt($ch, RETURNTRANSFER, 1);
$return_data = curl_exec($ch);

but then the variable is transient and you have no record of the
transaction.  By using the first option you can retrace the steps of any
transaction if you ever need to.

HTH, Mike


Phplist [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hi, I am using the CURL command to post credit card info to a gateway .exe
 program on a secure server. The code below works fine to produce the comma
 delimitted credit card authorization information to the browser page
 (for example: declined,Invalid form data
 posted,8/29/2002,18:07,0,0 ), but I need to capture
the
 credit card gateway authorization string so that I can take action within
my
 PHP code, versus the user receiving the auth code returned on the browser
 page.

 Here is the code I am using:
 htmlbody

 ?php
 //
 // A very simple PHP example that sends a HTTP POST to a remote site
 //

 $ch = curl_init();

 curl_setopt($ch,
 CURLOPT_URL,http://secure.ibill.com/cgi-win/ccard/tpcard15.exe;);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS,
 reqtype=authorizeaccount=107036password=amount=12);

 curl_exec ($ch);
 curl_close ($ch);
 ?

 /body/html

 It produces:
 declined,Invalid form data
 posted,8/29/2002,18:07,0,0  at the browser... It is a
 valid decline on the credit card, which I am no concerned with, but I
don't
 have this return to the user, want to parse the string and produce my own
 php output based on accepted or declined status.

 Any ideas?

 Stan




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



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




[PHP] install php as CGI?

2002-06-04 Thread brian-phplist

how can i install php as CGI?







Brian Feliciano
EMC-Tech


I know that there are people in this world who do not love
their fellow man, and I hate people like that. 
  -
Tom Lehrer


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




[PHP] Fetching 1 array from either one of 2 possible columns?

2002-03-14 Thread phplist

I'm working on a query by selection type of form, where if a user
selects a subject to get information. Each database entry will have 2
subject fields, Subject 1 being the main subject and Subject 2 being the
cross-subject. A table is set up like this:

+--+--+--+--+--+-+
| ID   | Organization | URL  | SUBJECT1 | SUBJECT2 | Geographic  |
+--+--+--+--+--+-+
|  1   | Acme | www  |  Math|  English | Canada  |
|  2   | Loony Toons  | www  |  Comedy  |  Math| Brazil  |

...


The idea is that the query will check the database to see if $Subject
has a match in either Subject1 or Subject2. the geographic is an
optional selection. If I select Math as a subject, and left the
Geographic option unselected, I want it to go into either Subject1 and
Subject2 to find Math. In this case both records would be a hit.

Below is my query setup and formatting:
***
$sql = SELECT * FROM links WHERE SUBJECT1='$subject' OR
SUBJECT2='$subject' AND GEOGRAPHIC='$geographic'
 ORDER BY ORGANIZATION ASC;

$sql_result = mysql_query($sql);
if (!$sql_result) {
   echo Can't execute $sql  . mysql_error();
   exit;
}

// organizes data in an orderly manner (ie bulleted area)
while ($row = mysql_fetch_array($sql_result)) {

$esc_organization = $row[ORGANIZATION];
$esc_desc = $row[DESCRIPTION];
$esc_url = $row[URL];
$esc_subject = $row[SUBJECT1];
$esc_geographic = $row[GEOGRAPHIC];

$organization = stripslashes($esc_organization);
$description = stripslashes($esc_desc);
$url = stripslashes($esc_url);
$subject = stripslashes($esc_subject);
$geographic = stripslashes($esc_geographic);

$option_block .= 
li
a href=\http://$url\;$organization/a/libr
$descriptionbr
URL: a href=\http://$url\;$url/a/li\n;
}

Now, of course, if I were to use this, it will only use the Subject1
data. How do I tell it to use the results from either Subject 1 or
Subject 2?

Thanks in advance,

Laurie M. Landry



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




RE: [PHP] Fetching 1 array from either one of 2 possible columns?

2002-03-14 Thread phplist

I apologize if I wasn't clear in my email. The query part is fine I
think, as I tested it through the myPHPAdmin and had no problem with the
results (but brackets are good though).

It's this part I'm not too sure about. AS you can see, it's just using
[SUBJECT1] as shown. Correct me if I'm wrong, but even though I have 2
results, the final output would only show 1 because it's only showing
the match in SUBJECT1?

 while ($row = mysql_fetch_array($sql_result)) {
 
   $esc_organization = $row[ORGANIZATION];
   $esc_desc = $row[DESCRIPTION];
   $esc_url = $row[URL];
   $esc_subject = $row[SUBJECT1];
   $esc_geographic = $row[GEOGRAPHIC];


 -Original Message-
 From: Martin Towell [mailto:[EMAIL PROTECTED]] 
 Sent: Thursday, March 14, 2002 7:42 PM
 To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
 Subject: RE: [PHP] Fetching 1 array from either one of 2 
 possible columns?
 
 
 use brackets
 
 where (sub1 or sub2) and geo
 
 -Original Message-
 From: phplist [mailto:[EMAIL PROTECTED]]
 Sent: Friday, March 15, 2002 2:41 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Fetching 1 array from either one of 2 possible columns?
 
 
 I'm working on a query by selection type of form, where if a 
 user selects a subject to get information. Each database 
 entry will have 2 subject fields, Subject 1 being the main 
 subject and Subject 2 being the cross-subject. A table is set 
 up like this:
 
 +--+--+--+--+--+-+
 | ID   | Organization | URL  | SUBJECT1 | SUBJECT2 | Geographic  |
 +--+--+--+--+--+-+
 |  1   | Acme | www  |  Math|  English | Canada  |
 |  2   | Loony Toons  | www  |  Comedy  |  Math| Brazil  |
 
 ...
 
 
 The idea is that the query will check the database to see if 
 $Subject has a match in either Subject1 or Subject2. the 
 geographic is an optional selection. If I select Math as a 
 subject, and left the Geographic option unselected, I want it 
 to go into either Subject1 and Subject2 to find Math. In this 
 case both records would be a hit.
 
 Below is my query setup and formatting:
 ***
 $sql = SELECT * FROM links WHERE SUBJECT1='$subject' OR 
 SUBJECT2='$subject' AND GEOGRAPHIC='$geographic'
ORDER BY ORGANIZATION ASC;
 
 $sql_result = mysql_query($sql);
 if (!$sql_result) {
echo Can't execute $sql  . mysql_error();
exit;
   }
 
 // organizes data in an orderly manner (ie bulleted area)
 while ($row = mysql_fetch_array($sql_result)) {
 
   $esc_organization = $row[ORGANIZATION];
   $esc_desc = $row[DESCRIPTION];
   $esc_url = $row[URL];
   $esc_subject = $row[SUBJECT1];
   $esc_geographic = $row[GEOGRAPHIC];
   
   $organization = stripslashes($esc_organization);
   $description = stripslashes($esc_desc);
   $url = stripslashes($esc_url);
   $subject = stripslashes($esc_subject);
   $geographic = stripslashes($esc_geographic);
 
   $option_block .= 
   li
   a href=\http://$url\;$organization/a/libr
   $descriptionbr
   URL: a href=\http://$url\;$url/a/li\n;
 }
 
 Now, of course, if I were to use this, it will only use the 
 Subject1 data. How do I tell it to use the results from 
 either Subject 1 or Subject 2?
 
 Thanks in advance,
 
 Laurie M. Landry
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 



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




[PHP] Connecting Form result to PHP query?

2002-03-13 Thread PHPList

On first page, there is a form where

User must select choice from Subject1 (mandatory)
User may select choice from Geographic Area (optional)

When you click on Go, you go to Results page where there will be
instructions for PHP:

Search database where Subject1=$subject1 OR Subject2=$subject1 AND
Geographic=$geographic

Whenever there is a match in Subject1 OR Subject2 AND MAYBE a match in
Geographic

Then display results in an HTML-format.

Q: How do I send the results from the form on first page to the results
page?







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