Re: [PHP] showing any mysql query in a table, help!

2006-03-18 Thread Jim Lucas

[EMAIL PROTECTED] wrote:

Ok...
it has to be a way to do such a thing.
I do i get the column names?
I can get the number of columns using mysql_num_fields() right?
but what if i want to get the columns name? Wich functtion and how should i use?

the goal is to make a function that prints a table that prints the result of 
any query in a html table.

thx
Pedro

  

mysql_list_fields() should do the trick for you.

check out the function in the php documentation

the first couple examples in the user notes area should give you some 
good alternatives if this function does not work for you.


Jim

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



Re: [PHP] showing any mysql query in a table, help!

2006-03-18 Thread Chris
You could fetch the rows in an associate array. Then loop over each 
element in the array printing it out inside  tags..


print out  before the columns,  after.

To get the header just loop through the keys of the associative array. 
Whenever you want to show the header.


Unless I'm misunderstanding you that should work.

Chris

[EMAIL PROTECTED] wrote:

Ok...
it has to be a way to do such a thing.
I do i get the column names?
I can get the number of columns using mysql_num_fields() right?
but what if i want to get the columns name? Wich functtion and how should i use?

the goal is to make a function that prints a table that prints the result of 
any query in a html table.

thx
Pedro

  


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



[PHP] showing any mysql query in a table, help!

2006-03-18 Thread pgaio
Ok...
it has to be a way to do such a thing.
I do i get the column names?
I can get the number of columns using mysql_num_fields() right?
but what if i want to get the columns name? Wich functtion and how should i use?

the goal is to make a function that prints a table that prints the result of 
any query in a html table.

thx
Pedro

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



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Manuel Amador (Rudd-O) wrote:

> Just for argument's sake: the result is not identical.  Assume, for
> one second, that you have two PHP functions:
>
> function getCitiesAsHTML($countryName);
> function getCitiesAsXML($countryName);
>
> The first issues a snippet of HTML text, with s.  The second
> issues a serialized XML document.
> The first one is engineered to be used with innerHTML.  The second one
> is engineered to be processed by the client so it can do any generic
> transformation.
>
> Which one do you think has the greatest potential for reusability in
> your JS client code?  Option 1 or Option 2?
>
> 
>
> Okay, this is the end of the discussion for me.  You're stating a
> bunch of crap which does not correlate with modern accepted software
> quality practices.  You're conveniently ignoring that server-side
> errors and TCP connection errors are out there, and while they may be
> only 2% of all traffic, you need your JS application to work 100% of
> the time or give reasonable feedback as to why it cannot work.  You're
> grossly oversimplifying matters to prove your point, which flies right
> in the face of orderly, neat, structured, standards-based software
> development.

Manuel,

Your insults are not exactly convincing arguments for your case :).  If
you had even taken 1 second to investigate http://pear.php.net/HTML_AJAX
you would know that your arguments about TCP and server-side errors are
irrelevant.  Why?  I'll tell you why!

In fact, to make things easier, I will quote myself from previous
messages.  Consider this current email to be Message #4.  From Message #2:

"2) HTTP 500?

This should be handled internally by the ajax mechanism (HTML_AJAX does
handle this)"

To rephrase what I said above, HTML_AJAX handles server-side and TCP
connection errors.  I neglected to say exactly how it does so in the
message, perhaps that is the confusion.  Upon a timeout or other error,
a javascript alert() is used.  Upon a server-side error (a PHP error in
the server-side script), by default a javascript alert() is raised with
the contents of the PHP error complete with backtrace - very handy for
debugging.

So, that kills straw man argument number one, which I will quote again
for clarity: "You're conveniently ignoring that server-side errors and
TCP connection errors are out there, and while they may be only 2% of
all traffic..."

As we can see, this statement is untrue.  So, moving on:

HTML_AJAX is designed such that you register classes that simply return
regular old PHP values, and it then serializes them into JSON or any of
a number of choices (as I have said, let me quote myself from Message #1:

"I use http://pear.php.net/HTML_AJAX for the actual ajax details, and it
has several serialization options, JSON by default.")

The fact is, your example php functions miss the point by returning HTML
vs. XML.  The return value of my functions are *strings* which are then
serialized into JSON by HTML_AJAX.  If you need to do client-side
transformation, that's not a problem, as contrary to a previous post,
HTML inserted via assignment to innerHTML *is* accessible via DOM,
otherwise getElementById() wouldn't work on the .  To prove
this, you can look in Firefox's DOM inspector.  After loading HTML
inserted via innerHTML, at first it will not show any changes, but by
closing the DOM inspector and re-opening it, it will refresh with the
current page value, and all of the new innerHTMLed HTML will show up.

Also, let's remember back to the original question from Daevid Vincent,
which was (and I quote):

"I need to dynamically update a select box with results from a SQL
database using AJAX, but I can't find a single example of how to do this."

A select box is not a need to do client-side manipulation.  It is a
select box.  Should you need to re-format the data in another format,
there are several options which all boil down to one of:

1) re-factor so that you don't need to re-format on the client side (my
personal favorite)
2) return another format such as an array and manipulate the data on the
client-side

However, it is not useful to talk about some generic time down the road
- what is important is to design your application so that it is easy to
change it.  If you have a whole bunch of complicated client-side logic,
this makes it more difficult to re-factor.  After all, only one of two
things are certain in programming:

You *will* have to refactor that code in the future, or you will quit. 
Whichever comes first.

So, straw man argument #2: "You're grossly oversimplifying matters to
prove your point, which flies right in the face of orderly, neat,
structured, standards-based software development."

is simply insulting :).  I was posting *actual* javascript code from a
well-working application with only the function names changed.  Want the
original code as written?  Here you go:

var addressesCallback = {
searchAddressesGetHTMLOptions: function(res) {
   document.getElementB

[PHP] Merging two partially-transparent images results in black pixels

2006-03-18 Thread Jason Young

Hello,

I have an image that uses partial transparency for borders and such.
At first, I tried using the whole image; creating a truecolor 'holder' 
image, then imagecopymerge-ing it, but that resulted in the outside 
transparent areas (the ones that would instead show the 'holder' image) 
were black, while the portions of transparency on the inside (these are 
rounded-squares) that had actual other images below them were white.


Then, I made two images. One having the outside transparency, and 
setting imagesavealpha to make it work as intended... then adding the 
needed images, then adding the 'window'-type transparent image on top.
This gives the best result, but the 'window' image also has partial 
transparency, and is instead showing in black.


I'm pretty much at wit's end. Everything's imagecopymerge'd, I've tried 
just about everything I could think of.


Can you actually not have two transparent images on top of one another?
Is there something else I can try?
And as an offshoot question, why won't any transparent images natively 
load/import as transparent? I always seem to have to call 
imagecolortransparent on portions that are definitely transparent in 
Photoshop, etc.


Any help would be much appreciated!
Thank you

-Jason Young

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



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Manuel Amador (Rudd-O)

Greg Beaver wrote:



This is obvious: you need only test the output of the PHP server class,
 

All the more reasons to use a serialization markup language instead of 
just plain HTML.  Testing for specific HTML output may break if the HTML 
output changes, but not if you're using XML or JSON, because:


1. you are forced to think carefully before changing the output
2. programming techniques such as DOM instead of matching for text are a 
reality



which is quite simple, as none of the complexity lies in the
javascript.  As long as your ajax javascript is testable for its ability
to work (and HTML_AJAX is), then you are covered.  In other words, the
need to test the javascript end is simply unnecessary.


That's so untrue, unit testing frameworks for JavaScript exist.


 All you need to
do is to test that the javascript actually properly initiates the ajax
call.  In my case, it involves these lines:

var someCallback = {
   doThis: function(res) {
  document.getElementById('blah').innerHTML = res;
   }
}

function doThisThing(fragment)
{
   var c = new backendclass(someCallback);
   c.doThis(fragment);
}

 


 Going beyond, how do you set up unit (or other types of) tests in a
cheap, straightforward way?  How do you assure quality of an
application built like this?
   



In order to unit test the javascript, you would need to do the same
stuff that is done for DOM, but it would be far simpler to set up.  I've
already answered the PHP end.
 


What I think is *still* unclear is that the difference between what you
are suggesting and what is actually working on my website is this:

Your solution:

1) PHP code generates the data from the fragment
2) PHP code converts the data into a text file
3) PHP code serializes it to JSON
4) javascript code unserializes the JSON
5) javascript code parses the text file to grab option/value combinations
6) javascript code creates each option node, and adds the value/text
7) javascript code creates the select node, adds each option
8) javascript code adds the select to the document
 


It's evident, from your statements, that you've misunderstood me:

1) You output XML or JSON directly from your PHP script.  Whether it's 
via print statements or an elaborated class like the DOM XML functions 
in PHP, that's your problem.
2) You receive the data and use one of the builtin JavaScript functions 
to parse it (if you're transferring a valid XML document, that's a piece 
of cake.  Generating a valid XML document is also piece of cake, using 
DOM-XML in php)
3) You write client-side application code that processes the nodes from 
the parsed output and does whatever it has to do to your current 
document's DOM tree.  See, it's much more generic.  You could use the 
same output from the server to generate a table, or a SELECT node.  
Besides, if you want to avoid writing code, libraries for doing this are 
a dime a dozen.  Plus if you reuse code you usually end up with a 
well-tested choice.



My solution:

1) PHP code generates the data from the fragment
2) PHP code converts the data into a string containing the
 tags
3) PHP code serializes it to JSON
4) javascript code unserializes the JSON
5) javascript code sets the innerHTML to the new select
 

Like I said, that's a very specific, non-generalizable, brittle 
solution.  It might work.  Then again, it might not.  Handling broken 
connections and other kinds of impromptu errors is much harder than with 
XML or JSON.  At least with XML, you can attest to the validity of the 
markup before embarking on an innerHTML binge.



In your solution, you need to test steps 1, 2, 5, 6 and 7.  In addition,
steps 2, 5, 6, and 7 all require testing in javascript (and time) to
guarantee that you get the result (8).

In my solution, you need to test step 1 and 2 to ensure that bounds are
satisfied and that a proper  tag is always generated, and this
only needs to be done in PHP.  Both cases assume you don't need to test
the ajax mechanism itself.
 


In short, it's just not worth the trouble to triple the number of
necessary tests when the result is identical, and it is actually
*easier* to see what HTML you're going to end up with from the PHP code.
 

Just for argument's sake: the result is not identical.  Assume, for one 
second, that you have two PHP functions:


function getCitiesAsHTML($countryName);
function getCitiesAsXML($countryName);

The first issues a snippet of HTML text, with s.  The second 
issues a serialized XML document.
The first one is engineered to be used with innerHTML.  The second one 
is engineered to be processed by the client so it can do any generic 
transformation.


Which one do you think has the greatest potential for reusability in 
your JS client code?  Option 1 or Option 2?




Okay, this is the end of the discussion for me.  You're stating a bunch 
of crap which does not correlate with modern accepted software quality 
practices.  You're conveniently ignoring that server-side error

Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Manuel Amador (Rudd-O) wrote:

>
>> 1) what if the returned markup is invalid?
>>
>> Well, the browser renders it oddly, and through the fact that your
>> server-side code is straightforward filling in an html template with
>> actual values, all you need to do is view the source (with the firefox
>> web debugging extension you can view generated source) or to add an
>> "alert(res)" in there.
>>  
>>
> Now, how do you automate that in a testing suite?

This is obvious: you need only test the output of the PHP server class,
which is quite simple, as none of the complexity lies in the
javascript.  As long as your ajax javascript is testable for its ability
to work (and HTML_AJAX is), then you are covered.  In other words, the
need to test the javascript end is simply unnecessary.  All you need to
do is to test that the javascript actually properly initiates the ajax
call.  In my case, it involves these lines:

var someCallback = {
doThis: function(res) {
   document.getElementById('blah').innerHTML = res;
}
}

function doThisThing(fragment)
{
var c = new backendclass(someCallback);
c.doThis(fragment);
}

Obviously, this is simply not complicated enough to warrant extensive
testing of the interface between the javascript -> HTML_AJAX -> php code
and back.  All we need to test is the HTML_AJAX component, and the PHP code.

>   Going beyond, how do you set up unit (or other types of) tests in a
> cheap, straightforward way?  How do you assure quality of an
> application built like this?

In order to unit test the javascript, you would need to do the same
stuff that is done for DOM, but it would be far simpler to set up.  I've
already answered the PHP end.

>
>> 3) tag soup?
>>
>> I hardly think a  tag qualifies as "tag soup" but "tag soup" is
>> of course a non-definite term anyways :).
>>  
>>
> Well, returning an JSON or XML document certainly is more structured
> than using a simple SELECT and several OPTION HTML tags.  The point
> here is, precisely, decoupling implementation from interface.

What I think is *still* unclear is that the difference between what you
are suggesting and what is actually working on my website is this:

Your solution:

1) PHP code generates the data from the fragment
2) PHP code converts the data into a text file
3) PHP code serializes it to JSON
4) javascript code unserializes the JSON
5) javascript code parses the text file to grab option/value combinations
6) javascript code creates each option node, and adds the value/text
7) javascript code creates the select node, adds each option
8) javascript code adds the select to the document

My solution:

1) PHP code generates the data from the fragment
2) PHP code converts the data into a string containing the
 tags
3) PHP code serializes it to JSON
4) javascript code unserializes the JSON
5) javascript code sets the innerHTML to the new select

In your solution, you need to test steps 1, 2, 5, 6 and 7.  In addition,
steps 2, 5, 6, and 7 all require testing in javascript (and time) to
guarantee that you get the result (8).

In my solution, you need to test step 1 and 2 to ensure that bounds are
satisfied and that a proper  tag is always generated, and this
only needs to be done in PHP.  Both cases assume you don't need to test
the ajax mechanism itself.

In short, it's just not worth the trouble to triple the number of
necessary tests when the result is identical, and it is actually
*easier* to see what HTML you're going to end up with from the PHP code.

> Sure, your solution mostly works.  But what I still wonder is, is it
> the best solution in terms of software quality? 

I think I've made my opinion sufficiently clear on this point.

Greg

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



RE: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Chrome
Ajax can be made to use POST by adding

req.open("POST", url, true); // true creates an asynchronous connection
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

where req is the XHR object

Also why not use the same style of formatting for the response as the
request uses... eg:

foo=My Foo&bar=My Bar&wibble=My Wibble

The first value is the option value and the second is the option text

FWIW I think that using innerHTML is a bad idea as the elements created
aren't included in the DOM tree... creating the elements using the DOM is a
much better idea... It may be more lengthy by that can be cut down some with
clever scripting :)

HTH

Dan

---
http://chrome.me.uk
 

-Original Message-
From: Daevid Vincent [mailto:[EMAIL PROTECTED] 
Sent: 18 March 2006 22:45
To: php-general@lists.php.net
Cc: 'tedd'
Subject: RE: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?

No. All of the examples I find are like the 'google' style suggest-thingy.

I want to dynamically (AJAX) populate an actual:


 foo 
 bar
 fee
 fum
 

Basically the core problem is passing back an 'array' of data from mysql
into JS to make the box.

What I've 'hacked' together so far is that I return my values like so from
PHP/mySQL to JS AJAX:

$tmp = "1|foo|2|bar|3|fee|4|fum";

And then in JS, I do this:

tokens = tmp.split('|');

Then use a for(i++2) loop and build up the options (key and value) of the
select box.

But, to me this seems like a hack.

Plus I'm a little worried that there is going to be a size limit of
characters or data or something? After all, AFAIK AJAX uses $_GET method
right? Not $_POST. So I think GET has a limit of like 1024 characters,
whereas POST doesn't have that limit.

My select box could have potentially thousands of items in it. Say for
example, IP addresses. I have supporting select boxes to filter by ranges,
or groups, or whatever, but there's nothing restricting a user from NOT
using them, and just wanting to see ALL the IP addresses...

So, I guess what I'm asking, is, is this the right way to solve this
challenge, or is there a better/more accepted way?

> -Original Message-
> From: tedd [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, March 18, 2006 1:02 PM
> To: php-general@lists.php.net; Daevid Vincent
> Subject: Re: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?
> 
> >I need to dynamically update a select box
> >with results from a SQL database using AJAX,
> >but I can't find a single example of how to do this.
> >
> >Basically I have a text input field, and a select box.
> >As someone types in the input field,
> >I want the select box to fill in the results of matches.
> >
> >I can fill in a  (as per the ten million examples out there)
> >and that's all fine and dandy, but way too simplistic for 
> what I need.
> 
> Select Box?
> 
> Do you mean a Selection List, that will change as the user types in 
> an input field like this:
> 
> http://www.itsyourdomain.com/
> 
> Just type domain name into the search box -- is that what 
> you're looking for?
> 
> tedd
> -- 
> --
> --
> http://sperling.com
> 

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


__ NOD32 1.1450 (20060318) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com

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



Re: [PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Rasmus Lerdorf

Rostislav Krasny wrote:

On Sat, 18 Mar 2006 13:49:19 -0800
[EMAIL PROTECTED] (Jim Lucas) wrote:


put a space after the ?> and you will retain the line feed


It also adds that space before the retained line feed, but so it looks
better anyway. Excellent suggestion, thank you! Could it be added to
the FAQ and to the official PHP tutorial? At least to the discussed
part of the tutorial, so PHP beginners like me wouldn't be confused :-)


I added it to the tutorial.  It will show up the next time the manual is 
built.


-Rasmus

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



RE: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread tedd

No. All of the examples I find are like the 'google' style suggest-thingy.

I want to dynamically (AJAX) populate an actual:


 foo
 bar
 fee
 fum


Basically the core problem is passing back an 'array' of data from mysql
into JS to make the box.

What I've 'hacked' together so far is that I return my values like so from
PHP/mySQL to JS AJAX:

$tmp = "1|foo|2|bar|3|fee|4|fum";

And then in JS, I do this:

tokens = tmp.split('|');

Then use a for(i++2) loop and build up the options (key and value) of the
select box.

But, to me this seems like a hack.

Plus I'm a little worried that there is going to be a size limit of
characters or data or something? After all, AFAIK AJAX uses $_GET method
right? Not $_POST. So I think GET has a limit of like 1024 characters,
whereas POST doesn't have that limit.

My select box could have potentially thousands of items in it. Say for
example, IP addresses. I have supporting select boxes to filter by ranges,
or groups, or whatever, but there's nothing restricting a user from NOT
using them, and just wanting to see ALL the IP addresses...

So, I guess what I'm asking, is, is this the right way to solve this
challenge, or is there a better/more accepted way?


A better acceptable way? I'm clueless as to what is better. Ajax is 
too new to me to make a determination as to what is the best or 
acceptable way.


I just know that ajax can be used to replace the contents between 
specific tags in an html document without having to reload the entire 
page. So, I don't see any reason why you can't replace stuff between 
 tags with stuff you pull out from mysql.


As far as the limit, your assumption is not correct. I just tried a 
test of over 14,000 characters with no problem at all, see:


http://www.xn--ovg.com/ajax1  Click First page

So, you shouldn't have any problem populating a select box with 
thousands of characters -- although you may want to LIMIT that in 
your mysql and pull it out in shorter segments.


tedd

--

http://sperling.com

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



RE: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Daevid Vincent
No. All of the examples I find are like the 'google' style suggest-thingy.

I want to dynamically (AJAX) populate an actual:


 foo 
 bar
 fee
 fum
 

Basically the core problem is passing back an 'array' of data from mysql
into JS to make the box.

What I've 'hacked' together so far is that I return my values like so from
PHP/mySQL to JS AJAX:

$tmp = "1|foo|2|bar|3|fee|4|fum";

And then in JS, I do this:

tokens = tmp.split('|');

Then use a for(i++2) loop and build up the options (key and value) of the
select box.

But, to me this seems like a hack.

Plus I'm a little worried that there is going to be a size limit of
characters or data or something? After all, AFAIK AJAX uses $_GET method
right? Not $_POST. So I think GET has a limit of like 1024 characters,
whereas POST doesn't have that limit.

My select box could have potentially thousands of items in it. Say for
example, IP addresses. I have supporting select boxes to filter by ranges,
or groups, or whatever, but there's nothing restricting a user from NOT
using them, and just wanting to see ALL the IP addresses...

So, I guess what I'm asking, is, is this the right way to solve this
challenge, or is there a better/more accepted way?

> -Original Message-
> From: tedd [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, March 18, 2006 1:02 PM
> To: php-general@lists.php.net; Daevid Vincent
> Subject: Re: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?
> 
> >I need to dynamically update a select box
> >with results from a SQL database using AJAX,
> >but I can't find a single example of how to do this.
> >
> >Basically I have a text input field, and a select box.
> >As someone types in the input field,
> >I want the select box to fill in the results of matches.
> >
> >I can fill in a  (as per the ten million examples out there)
> >and that's all fine and dandy, but way too simplistic for 
> what I need.
> 
> Select Box?
> 
> Do you mean a Selection List, that will change as the user types in 
> an input field like this:
> 
> http://www.itsyourdomain.com/
> 
> Just type domain name into the search box -- is that what 
> you're looking for?
> 
> tedd
> -- 
> --
> --
> http://sperling.com
> 

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



[PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Manuel Lemos
Hello,

on 03/17/2006 11:42 PM Daevid Vincent said the following:
> I need to dynamically update a select box 
> with results from a SQL database using AJAX, 
> but I can't find a single example of how to do this.
> 
> Basically I have a text input field, and a select box. 
> As someone types in the input field, 
> I want the select box to fill in the results of matches.
> 
> I can fill in a  (as per the ten million examples out there)
> and that's all fine and dandy, but way too simplistic for what I need.

You may want to take a look at this forms generation class that comes
with a plug-in that lets you do precisely what you ask.

The linked select input plug-in lets you switch the group of options of
a select input upon an arbitrary event, which in your case you need to
be when your text input changes its value.

The plug-in can work in two modes: static and dynamic. In the static
mode it loads all the alternative groups of options with the form. This
is not the way you want.

In the dynamic mode it makes an AJAX call that performs some action and
returns the alternative group of options depending on a value passed
from another input to the server.

In both modes it can take the alternative option groups from arrays or
execute some action that retrives the new options. There specialized
variants of the plug-in to take the options from database queries using
different API. Currently supported API are: MySQL, or any other database
supported by the database abstractions Metabase or PEAR::MDB2 .

There is also another plug-in for generic AJAX form submission in case
you need more special effects.

Here are live examples of the static mode:

http://www.phpclasses.org/mirrors.html

http://www.phpclasses.org/browse/view/html/file/9879/name/test_linked_select_page.html


The example scripts for the dynamic mode come with the class:

You may download the class and all plug-ins, examples and documentation
from here:

http://www.phpclasses.org/formsgeneration

-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

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



Re: [PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Rostislav Krasny
On Sat, 18 Mar 2006 13:49:19 -0800
[EMAIL PROTECTED] (Jim Lucas) wrote:

> put a space after the ?> and you will retain the line feed

It also adds that space before the retained line feed, but so it looks
better anyway. Excellent suggestion, thank you! Could it be added to
the FAQ and to the official PHP tutorial? At least to the discussed
part of the tutorial, so PHP beginners like me wouldn't be confused :-)

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



Re: [PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Jim Lucas

Rostislav Krasny wrote:

Hi,

I've tried to ask the following question on internals@lists.php.net but
has been pointed out that that mailing list isn't appropriate. So I'm
resinding it here.

I am a newbie to PHP. I've installed a php5-cgi-5.1.2_1 from FreeBSD
ports collection and access it by FastCGI protocol from nginx HTTP
server. I've tried an example of "Hello World" PHP script from the
following tutorial page:

http://www.php.net/manual/en/tutorial.firstpage.php

This is how the resulting HTML code is expected to look like, according
to the tutorial:


 
 PHP Test
 
 
 Hello World
 


And following is the HTML code I've got:


 
 PHP Test
 
 
 Hello World


Why there is no newline afer " Hello World" ?
Is it a PHP bug or the tutorial should be updated?

P.S. I'm not subscribed to this list, please Cc your reply.

  

put a space after the ?> and you will retain the line feed

jim

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



[PHP] Re: no newline after "?>" in the resulting HTML

2006-03-18 Thread Rostislav Krasny
On Sat, 18 Mar 2006 19:37:48 +
[EMAIL PROTECTED] (James Benson) wrote:

> I get the same results, I doubt it's a bug, the person who wrote the 
> article maybe never tried what it would output since they probably know 
> how the echo construct works,

I think it is a bug. That part of the article could been written with
very old version of PHP. By the way, ASP does not delete a newline
after its "%>".

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



Re: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread tedd

I need to dynamically update a select box
with results from a SQL database using AJAX,
but I can't find a single example of how to do this.

Basically I have a text input field, and a select box.
As someone types in the input field,
I want the select box to fill in the results of matches.

I can fill in a  (as per the ten million examples out there)
and that's all fine and dandy, but way too simplistic for what I need.


Select Box?

Do you mean a Selection List, that will change as the user types in 
an input field like this:


http://www.itsyourdomain.com/

Just type domain name into the search box -- is that what you're looking for?

tedd
--

http://sperling.com

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



Re: [PHP] Updating a single line in a file

2006-03-18 Thread Manuel Amador (Rudd-O)

Replies inlined.


Why dont you use a database for this?  You will run into race
conditions at some point.

If you need a file based database take a look at sqlite.

Curt.
--
   

About the race conditions, I didn't mentionned I had some extras code to 
care about concurrent writing on the file
About database, I know that will be the best, but on this small site, I 
can't use full database!
 


That's why they suggested a sqlite database, which uses a single file.


Thank you for your answer
SR 

 



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



Re: [PHP] Updating a single line in a file

2006-03-18 Thread smr78

"Curt Zirzow" <[EMAIL PROTECTED]> a écrit dans le message de news: 
[EMAIL PROTECTED]
> On Sat, Mar 18, 2006 at 11:01:07AM +0100, smr78 wrote:
>> Hi,
>> What is the best method to update a single line in a text file?
>> I have a file made of identifiers, that is pointed on by a htaccess file 
>> and
>> used by a server to give access to a web site.
>> The file content is like this :
>> login1:pass1\r\n
>> login2:pass2\r\n
>> 
>> loginn:passn\r\n
>> loginn1:passn1\r\n
>> 
>> lastlogin:lastpass\r\n
>
> Why dont you use a database for this?  You will run into race
> conditions at some point.
>
> If you need a file based database take a look at sqlite.
>
> Curt.
> -- 
About the race conditions, I didn't mentionned I had some extras code to 
care about concurrent writing on the file
About database, I know that will be the best, but on this small site, I 
can't use full database!
Thank you for your answer
SR 

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



Re: [PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Chris Shiflett

Rostislav Krasny wrote:

Why there is no newline afer "Hello World"?
Is it a PHP bug or the tutorial should be updated?


I discuss this here: http://shiflett.org/archive/151

It's a feature of PHP that has some advantages and disadvantages, and 
it's not likely to change (consistency has merit, regardless of what you 
think of the behavior).


Hope that helps.

Chris

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



[PHP] Re: no newline after "?>" in the resulting HTML

2006-03-18 Thread James Benson



Rostislav Krasny wrote:

Hi,

I've tried to ask the following question on internals@lists.php.net but
has been pointed out that that mailing list isn't appropriate. So I'm
resinding it here.

I am a newbie to PHP. I've installed a php5-cgi-5.1.2_1 from FreeBSD
ports collection and access it by FastCGI protocol from nginx HTTP
server. I've tried an example of "Hello World" PHP script from the
following tutorial page:

http://www.php.net/manual/en/tutorial.firstpage.php

This is how the resulting HTML code is expected to look like, according
to the tutorial:


 
 PHP Test
 
 
 Hello World
 


And following is the HTML code I've got:


 
 PHP Test
 
 
 Hello World


Why there is no newline afer " Hello World" ?
Is it a PHP bug or the tutorial should be updated?

P.S. I'm not subscribed to this list, please Cc your reply.






I get the same results, I doubt it's a bug, the person who wrote the 
article maybe never tried what it would output since they probably know 
how the echo construct works, if you want a line break you should change 
it to:-



Hello World\n"; ?>

or:-

Hello World" . PHP_EOL; ?>

or:-

Hello World
"; ?>




James

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



Re: [PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Rasmus Lerdorf

Adrian wrote:

Is there a way to circumvent this?
My template engine compiles templates to PHP files and this "feature"
makes the output html code look awful sometimes.


Nope.  Put in an extra newline after ?> if you need them, or put a \n at 
the end of the last echo inside the PHP block.


-Rasmus

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



Re: [PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Adrian
Is there a way to circumvent this?
My template engine compiles templates to PHP files and this "feature"
makes the output html code look awful sometimes.

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



Re: [PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Rasmus Lerdorf

Brady Mitchell wrote:

Why there is no newline afer " Hello World" ?
Is it a PHP bug or the tutorial should be updated?


The tutorial is fine.

The sample code mentioned:


 
  PHP Test
 
 
 Hello World'; ?>

 


Contains a line break after the Hello World is echoed .
 
Check your code, if you don't have that line break, PHP is not going to create it for you.


That's actually not true.  A line break after a closing ?> is ignored. 
This is to make it possible to have something like this:




...


And have that opening  tag be on the first line of the file.

Another reason is for include files.  If you include a file that ends 
with ?> then you normally don't want that newline.  Having a 
newline output for each file you include doesn't make much sense.


So yes, technically the tutorial is wrong.

-Rasmus

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



RE: [PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Brady Mitchell
> Why there is no newline afer " Hello World" ?
> Is it a PHP bug or the tutorial should be updated?

The tutorial is fine.

The sample code mentioned:


 
  PHP Test
 
 
 Hello World'; ?>

 

Contains a line break after the Hello World is echoed .
 
Check your code, if you don't have that line break, PHP is not going to create 
it for you.

Brady

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



Re: [PHP] Updating a single line in a file

2006-03-18 Thread Curt Zirzow
On Sat, Mar 18, 2006 at 11:01:07AM +0100, smr78 wrote:
> Hi,
> What is the best method to update a single line in a text file?
> I have a file made of identifiers, that is pointed on by a htaccess file and 
> used by a server to give access to a web site.
> The file content is like this :
> login1:pass1\r\n
> login2:pass2\r\n
> 
> loginn:passn\r\n
> loginn1:passn1\r\n
> 
> lastlogin:lastpass\r\n

Why dont you use a database for this?  You will run into race
conditions at some point.

If you need a file based database take a look at sqlite.

Curt.
-- 
cat .signature: No such file or directory

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



[PHP] no newline after "?>" in the resulting HTML

2006-03-18 Thread Rostislav Krasny
Hi,

I've tried to ask the following question on internals@lists.php.net but
has been pointed out that that mailing list isn't appropriate. So I'm
resinding it here.

I am a newbie to PHP. I've installed a php5-cgi-5.1.2_1 from FreeBSD
ports collection and access it by FastCGI protocol from nginx HTTP
server. I've tried an example of "Hello World" PHP script from the
following tutorial page:

http://www.php.net/manual/en/tutorial.firstpage.php

This is how the resulting HTML code is expected to look like, according
to the tutorial:


 
 PHP Test
 
 
 Hello World
 


And following is the HTML code I've got:


 
 PHP Test
 
 
 Hello World


Why there is no newline afer " Hello World" ?
Is it a PHP bug or the tutorial should be updated?

P.S. I'm not subscribed to this list, please Cc your reply.

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



Re: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread dave
hi, i used
http://www.ajaxfreaks.com/tutorials/6/3.php?topic_id=73&hl=104#104
it works just fine, i implemented to one of my web, so far so good. Hope
it's what u are looking for

Daevid Vincent wrote:
> I need to dynamically update a select box 
> with results from a SQL database using AJAX, 
> but I can't find a single example of how to do this.
> 
> Basically I have a text input field, and a select box. 
> As someone types in the input field, 
> I want the select box to fill in the results of matches.
> 
> I can fill in a  (as per the ten million examples out there)
> and that's all fine and dandy, but way too simplistic for what I need.
> 

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



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Manuel Amador (Rudd-O)



1) what if the returned markup is invalid?

Well, the browser renders it oddly, and through the fact that your
server-side code is straightforward filling in an html template with
actual values, all you need to do is view the source (with the firefox
web debugging extension you can view generated source) or to add an
"alert(res)" in there.
 

Now, how do you automate that in a testing suite?  Going beyond, how do 
you set up unit (or other types of) tests in a cheap, straightforward 
way?  How do you assure quality of an application built like this?



2) HTTP 500?

This should be handled internally by the ajax mechanism (HTML_AJAX does
handle this)
 


That's good.


3) tag soup?

I hardly think a  tag qualifies as "tag soup" but "tag soup" is
of course a non-definite term anyways :).
 

Well, returning an JSON or XML document certainly is more structured 
than using a simple SELECT and several OPTION HTML tags.  The point here 
is, precisely, decoupling implementation from interface.


Sure, your solution mostly works.  But what I still wonder is, is it the 
best solution in terms of software quality?



Greg
 



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



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Manuel Amador (Rudd-O) wrote:
> Greg Beaver wrote:
> 
>> This is far too complicated.  You don't need 50 lines of code to convert
>> from server-side data to HTML when the browser does it for you (and far
>> more efficiently) with this code:
>>
>> var someCallback = {
>>ajaxfunc: function(res) {
>>   document.getElementById('blah').innerHTML = res;
>>}
>> }
>>  
>>
> You know you're oversimplifying matters.  What if the returned markup is
> invalid?  What if the server experienced an HTTP 500 error?  Why should
> anyone want to program their application to return 'tag soup' instead of
> formally defining interfaces via standards?  That's asking for
> maintenance nightmares.

1) what if the returned markup is invalid?

Well, the browser renders it oddly, and through the fact that your
server-side code is straightforward filling in an html template with
actual values, all you need to do is view the source (with the firefox
web debugging extension you can view generated source) or to add an
"alert(res)" in there.

2) HTTP 500?

This should be handled internally by the ajax mechanism (HTML_AJAX does
handle this)

3) tag soup?

I hardly think a  tag qualifies as "tag soup" but "tag soup" is
of course a non-definite term anyways :).

Greg

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



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Manuel Amador (Rudd-O)

Greg Beaver wrote:


This is far too complicated.  You don't need 50 lines of code to convert
from server-side data to HTML when the browser does it for you (and far
more efficiently) with this code:

var someCallback = {
   ajaxfunc: function(res) {
  document.getElementById('blah').innerHTML = res;
   }
}
 

You know you're oversimplifying matters.  What if the returned markup is 
invalid?  What if the server experienced an HTTP 500 error?  Why should 
anyone want to program their application to return 'tag soup' instead of 
formally defining interfaces via standards?  That's asking for 
maintenance nightmares.




I hate to burst your bubble, but I am an experienced developer, and do
know how to use DOM.  My application used these exact techniques, and
was simply slower.  The internal rendering code for a browser is just
simply far faster than javascript DOM will ever be.

Another truth is self-evident: all browsers have uniformly implemented
the setting of innerHTML for far longer than the implementation of DOM
has been uniform, and your chances of encountering a bug in a particular
browser implementation are much slimmer.
 

I'm not talking about using DOM because it's more formal.  I'm talking 
about using DOM and formally defined interfaces for maintenance cost 
reasons.  Tag soup is harder to debug and automate/instrument for 
tests.  Tag soup is a nightmare.  Sure, for quickies it can't be 
beaten.  But try to figure out what the hell you (or one of your 
engineers) did six months ago without a formally specified way of 
returning values...


 


Don't try to be smart when you can be simple :)

 


I'd advise against this, and I'd also advise you to look up a
JavaScript-usable serialization microformat for data coming from the
server (XML is kind of unwieldy for this).  Look for JSON on google. 
   



You advise against simplicity?
 


No.  I'm advising against the false trap of initial simplicity.


First off, any good programmer will tell you that simplicity is always
the first thing to look for in an application, as complex algorithms are
almost always best implemented with simple (and clever) code, but this
is a tirade for another time.  Second, what makes you think I don't
transfer the HTML using JSON?
 

If you did that, you would be gaining nothing.  Whatever you use as 
return value format, it should be easily parsable markup and should be 
formally specified (standards of course should be preferred).  HTML is 
not XML and it's not as easily parsed as XML.



I use http://pear.php.net/HTML_AJAX for the actual ajax details, and it
has several serialization options, JSON by default.

First off, let's examine why one would use ajax in the first place. 
It's not to be "correct" or rigorous - it is to streamline the user

experience.  Ajax of course introduces other concerns such as the danger
of overloading the server with more HTTP requests than traditional apps,
but this is easily fixed by ensuring that examples like the "type in
text box and populate select" have some appropriate limits on how often
it actually sends the requests for data.
 


That statement I agree with.


If you still don't believe me, take a straw poll of the most proficient
programmers to see how they are using ajax in real-world time-critical
applications.
 

I've seen real-world AJAX applications succumb to complexity.  I'm just 
suggesting something to manage complexity which should be fairly obvious 
now.



Greg
 



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



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Manuel Amador (Rudd-O) wrote:

> Greg Beaver wrote:
>
>> Daevid Vincent wrote:
>>  
>>
>>> I need to dynamically update a select box with results from a SQL
>>> database using AJAX, but I can't find a single example of how to do
>>> this.
>>>
>>> Basically I have a text input field, and a select box. As someone
>>> types in the input field, I want the select box to fill in the
>>> results of matches.
>>>
>>> I can fill in a  (as per the ten million examples out there)
>>> and that's all fine and dandy, but way too simplistic for what I need.
>>>   
>>
>>
>> The best way to do this is indeed to put the entire select in a div, and
>> to replace the innerHTML of that div with the html for the select.
>>  
>>
> But that is not DOM.  Another way to do this is:

It's also not Java or Fortran, but as with these argument, that is
irrelevant information - it is valid javascript, and as we all know, the
"J" in ajax ain't DOM, it's javascript.

> - run your XMLHttpRequest
> - have your server-side AJAX target script spit a newline-separated
> text file, with IDs and names such as:
> 1 XYZ
> 2 JWV
> 3 Something
> - once the response is on the client, break the text file down with
> string manipulation functions/methods (split() comes to mind), perform
> a document.getElementByID("yourselect") and append
> document.createElement("option")'s to it, obviously setting the value
> properties on each element, and appending a
> document.createTextNode("your option text") into every option you create.

This is far too complicated.  You don't need 50 lines of code to convert
from server-side data to HTML when the browser does it for you (and far
more efficiently) with this code:

var someCallback = {
ajaxfunc: function(res) {
   document.getElementById('blah').innerHTML = res;
}
}

>
>> Always do as much processing as possible on the server side, or your
>> application will become interminably slow both to load and to run.
>>
>> In my testing, I've found that the latency over high speed internet of
>> passing the entire select is exactly the same as it is from my local
>> machine.  When I used to pass an array of data and repopulate using
>> javascript DOM, it was slow as molasses, and I would occasionally have
>> weird timeouts.
>>  
>>
> It shouldn't have been slow.  DOM manipulation is fast.  But you need
> to remember to instantiate new objects, add children objects first (in
> the example, the text nodes and options), and add the parent objects
> to your document then.  Otherwise, I can see how your application
> could get slow.

I hate to burst your bubble, but I am an experienced developer, and do
know how to use DOM.  My application used these exact techniques, and
was simply slower.  The internal rendering code for a browser is just
simply far faster than javascript DOM will ever be.

Another truth is self-evident: all browsers have uniformly implemented
the setting of innerHTML for far longer than the implementation of DOM
has been uniform, and your chances of encountering a bug in a particular
browser implementation are much slimmer.

>
>> Don't try to be smart when you can be simple :)
>>
> I'd advise against this, and I'd also advise you to look up a
> JavaScript-usable serialization microformat for data coming from the
> server (XML is kind of unwieldy for this).  Look for JSON on google. 

You advise against simplicity?

First off, any good programmer will tell you that simplicity is always
the first thing to look for in an application, as complex algorithms are
almost always best implemented with simple (and clever) code, but this
is a tirade for another time.  Second, what makes you think I don't
transfer the HTML using JSON?

I use http://pear.php.net/HTML_AJAX for the actual ajax details, and it
has several serialization options, JSON by default.

First off, let's examine why one would use ajax in the first place. 
It's not to be "correct" or rigorous - it is to streamline the user
experience.  Ajax of course introduces other concerns such as the danger
of overloading the server with more HTTP requests than traditional apps,
but this is easily fixed by ensuring that examples like the "type in
text box and populate select" have some appropriate limits on how often
it actually sends the requests for data.

If you still don't believe me, take a straw poll of the most proficient
programmers to see how they are using ajax in real-world time-critical
applications.

Greg

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



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Manuel Amador (Rudd-O)

Greg Beaver wrote:


Daevid Vincent wrote:
 

I need to dynamically update a select box 
with results from a SQL database using AJAX, 
but I can't find a single example of how to do this.


Basically I have a text input field, and a select box. 
As someone types in the input field, 
I want the select box to fill in the results of matches.


I can fill in a  (as per the ten million examples out there)
and that's all fine and dandy, but way too simplistic for what I need.
   



The best way to do this is indeed to put the entire select in a div, and
to replace the innerHTML of that div with the html for the select.
 


But that is not DOM.  Another way to do this is:
- run your XMLHttpRequest
- have your server-side AJAX target script spit a newline-separated text 
file, with IDs and names such as:

1 XYZ
2 JWV
3 Something
- once the response is on the client, break the text file down with 
string manipulation functions/methods (split() comes to mind), perform a 
document.getElementByID("yourselect") and append 
document.createElement("option")'s to it, obviously setting the value 
properties on each element, and appending a 
document.createTextNode("your option text") into every option you create.



Always do as much processing as possible on the server side, or your
application will become interminably slow both to load and to run.

In my testing, I've found that the latency over high speed internet of
passing the entire select is exactly the same as it is from my local
machine.  When I used to pass an array of data and repopulate using
javascript DOM, it was slow as molasses, and I would occasionally have
weird timeouts.
 

It shouldn't have been slow.  DOM manipulation is fast.  But you need to 
remember to instantiate new objects, add children objects first (in the 
example, the text nodes and options), and add the parent objects to your 
document then.  Otherwise, I can see how your application could get slow.



Don't try to be smart when you can be simple :)
 

I'd advise against this, and I'd also advise you to look up a 
JavaScript-usable serialization microformat for data coming from the 
server (XML is kind of unwieldy for this).  Look for JSON on google.



Greg

 



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



[PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Daevid Vincent wrote:
> I need to dynamically update a select box 
> with results from a SQL database using AJAX, 
> but I can't find a single example of how to do this.
> 
> Basically I have a text input field, and a select box. 
> As someone types in the input field, 
> I want the select box to fill in the results of matches.
> 
> I can fill in a  (as per the ten million examples out there)
> and that's all fine and dandy, but way too simplistic for what I need.

The best way to do this is indeed to put the entire select in a div, and
to replace the innerHTML of that div with the html for the select.
Always do as much processing as possible on the server side, or your
application will become interminably slow both to load and to run.

In my testing, I've found that the latency over high speed internet of
passing the entire select is exactly the same as it is from my local
machine.  When I used to pass an array of data and repopulate using
javascript DOM, it was slow as molasses, and I would occasionally have
weird timeouts.

Don't try to be smart when you can be simple :)

Greg

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



[PHP] Multiple inheritance: a technique

2006-03-18 Thread Manuel Amador (Rudd-O)

Hello, everyone.

I'm (by nature) a Python coder, and (by fiat) a PHP one.  Yes, I code in 
Python for fun, and PHP for work.  Despite that, I'm extremely thankful 
for the efforts poured into PHP.  It's a great language.


Except for one thing.  It lacks multiple inheritance.

But PHP 5 has the runkit extension.  While it does not allow users to 
get the full power of multiple inheritance, it does allow a limited (yet 
quite effective) form of it.


I've created a technique that exploits the power of PHP and runkit to 
simulate multiple inheritance, and I'd like to share it with you:


http://rudd-o.com/archives/2006/03/18/revisiting-multiple-inheritance-in-php/

If you find any inaccuracies or have anything to comment, feel free to 
use the page's commenting mechanisms.


Have a great day!

   Rudd-O

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



[PHP] Updating a single line in a file

2006-03-18 Thread smr78
Hi,
What is the best method to update a single line in a text file?
I have a file made of identifiers, that is pointed on by a htaccess file and 
used by a server to give access to a web site.
The file content is like this :
login1:pass1\r\n
login2:pass2\r\n

loginn:passn\r\n
loginn1:passn1\r\n

lastlogin:lastpass\r\n

This file can be modified in three ways
update a single line when a user updates its profile
delete a single line when the webmaster makes a user inactive
append a line when the webmaster makes a user active

the difficulties are :
there is not the same number of users and lines in this file,
we dont know at which line are the identifiers of a user,
when updating identifiers, we must keep new line characters at the end.

So what are the best functions to use to read and rewrite the file?

file() which puts all the content in an array, including the new line 
characters? (if so, we need to use array_search() or array_keys() to find 
where are the identifiers

fread() or file_get_contents() which puts all the content in a string? I 
tried this way and use eregi_replace() to find where are the identifiers, 
replace them by new value. But sometimes, I get errors where the new line 
characters are suppressed between two users identifiers or where an 
identifier is repeated like this :

loginx:passx\r\n
loginx:passx\r\n
loginn:passnloginn1:passn1\r\n
loginn2:passn2\r\n

Here is my code :

I know in "deleting" case, the eregi_replace pattern is so that the new line 
characters will not be removed, but this is not a problem

I'll try to use file() function and array_keys() and let you know.
Thanks

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



RE: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Weber Sites LTD
Why invent the wheel?

http://developer.ebusiness-apps.com/technologies/webdevelopment/codeandcompo
nents/ebawebcombov3/default.htm

Sincerely 
 
berber 
 
Visit the Weber Sites Today, 
To see where PHP might take you tomorrow. 
PHP code examples : http://www.weberdev.com 
PHP & MySQL Forums : http://www.weberforums.com
Free Uptime Monitor : http://uptime.weberdev.com
SEO Data Monitor http://seo.weberdev.com
 

-Original Message-
From: Daevid Vincent [mailto:[EMAIL PROTECTED] 
Sent: Saturday, March 18, 2006 4:43 AM
To: php-general@lists.php.net
Subject: [PHP] PHP, SQL, AJAX, JS and populating a SelectBox?

I need to dynamically update a select box with results from a SQL database
using AJAX, but I can't find a single example of how to do this.

Basically I have a text input field, and a select box. 
As someone types in the input field,
I want the select box to fill in the results of matches.

I can fill in a  (as per the ten million examples out there) and that's
all fine and dandy, but way too simplistic for what I need.

--
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] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread David Dorward
Daevid Vincent wrote:

> I need to dynamically update a select box
> with results from a SQL database using AJAX,
> but I can't find a single example of how to do this.

Break it down in to stages.

1. Make the request to the server
2. Have the PHP gather the data from the database
3. Return the data to the client (I'd use JSON for this)
4. Populate the select

> I can fill in a  (as per the ten million examples out there)
> and that's all fine and dandy, 

So you can already do the first three stanges then? That just leaves stage
4.

One quick google later:

http://www.google.com/search?q=JavaScript+dynamically+populate+select

And the first hit is:

http://www.petenelson.com/aspwatch/ASPWatch%20%20Using%20Javascript%20to%20Dynamically%20Populate%20Select%20Lists.htm

Which tells you how to do it (ignore the ASP mention, the article is all
JavaScript).

-- 
David Dorward      
 Home is where the ~/.bashrc is

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