php-general Digest 24 Aug 2012 15:01:43 -0000 Issue 7934

Topics (messages 318791 through 318810):

Re: Using PEAR and PHP
        318791 by: Ashley Sheridan
        318792 by: Suraj Shah
        318793 by: Matijn Woudt
        318794 by: Lester Caine
        318795 by: Ashley Sheridan
        318796 by: Suraj Shah
        318797 by: Matijn Woudt
        318798 by: Suraj Shah
        318799 by: Matijn Woudt
        318800 by: Suraj Shah
        318801 by: Ashley Sheridan
        318802 by: Suraj Shah
        318803 by: Matijn Woudt
        318804 by: Matijn Woudt
        318805 by: Suraj Shah
        318807 by: Matijn Woudt

Dynamic Content thoughts
        318806 by: admin
        318808 by: Matijn Woudt
        318809 by: admin
        318810 by: tamouse mailing lists

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Thu, 2012-08-23 at 18:42 +0100, Suraj Shah wrote:

> Hi.
> 
> I am currently working on a website which uses PHP as an integral programming 
> language as part of it.
> 
> I am trying to replicate the website’s contents from one ftp server to 
> another but am encountering serious issues in doing so. I’ve spent two days 
> trying to find out the reasons and now think its down to the PEAR 
> installation.
> 
> This is therefore a question on if I want to transfer a website from one 
> domain to another, then do I need to install PEAR and re-configure all the 
> files? At the moment, all I can see within the ftp client regarding PEAR are 
> the ‘Mail’ and ‘Mail_Mime’ components.
> 
> I am new to this so any help on this would be great.
> 
> Many thanks
> 
> Suraj
> 
> 
> Suraj Shah
> Online Marketing Executive
> 26 Throgmorton Street | London | EC2N 2AN
> t: 020 7826 9031
> e: su...@aifa.net
> w: www.aifa.net


That would depend. Some servers install Pear outside the web root but in
a location the web server has access to so that it can be used within
your own scripts. Most often though, I've just seen code use a library
or two from Pear and include them like you can see from your FTP access.

What kinds of errors are you getting when you attempt to get the site
running on the second server?

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Thanks for your reply Ashley.

I’m getting the attached error message which I can’t seem to solve. If it’s 
just a matter of adding code to use for a library, would this be possible? How 
do I go about configuring it?

Many thanks,
Suraj



On 23/08/2012 19:08, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

On Thu, 2012-08-23 at 18:42 +0100, Suraj Shah wrote:

Hi.

I am currently working on a website which uses PHP as an integral programming 
language as part of it.

I am trying to replicate the website’s contents from one ftp server to another 
but am encountering serious issues in doing so. I’ve spent two days trying to 
find out the reasons and now think its down to the PEAR installation.

This is therefore a question on if I want to transfer a website from one domain 
to another, then do I need to install PEAR and re-configure all the files? At 
the moment, all I can see within the ftp client regarding PEAR are the ‘Mail’ 
and ‘Mail_Mime’ components.

I am new to this so any help on this would be great.

Many thanks

Suraj


Suraj Shah
Online Marketing Executive
26 Throgmorton Street | London | EC2N 2AN
t: 020 7826 9031
e: su...@aifa.net
w: www.aifa.net <http://www.aifa.net>

That would depend. Some servers install Pear outside the web root but in a 
location the web server has access to so that it can be used within your own 
scripts. Most often though, I've just seen code use a library or two from Pear 
and include them like you can see from your FTP access.

What kinds of errors are you getting when you attempt to get the site running 
on the second server?

Suraj Shah
Online Marketing Executive
26 Throgmorton Street | London | EC2N 2AN
t: 020 7826 9031
e: su...@aifa.net
w: www.aifa.net
twitter: @official_AIFA

--- End Message ---
--- Begin Message ---
On Thu, Aug 23, 2012 at 8:12 PM, Suraj Shah <su...@aifa.net> wrote:
> Thanks for your reply Ashley.
>
> I’m getting the attached error message which I can’t seem to solve. If it’s 
> just a matter of adding code to use for a library, would this be possible? 
> How do I go about configuring it?
>
> Many thanks,
> Suraj
>

Suraj,

Attachments usually don't work at mailing lists, you should paste it
in your mail, or use something like pastebin. Second, you should
bottom post at this (and probably any) mailing list.
About your question, you can install the php-pear package if you don't
have it from your package manager, and then all you have to do is call
pear install <package>
and you're done.

- Matijn

--- End Message ---
--- Begin Message ---
Suraj Shah wrote:
I am currently working on a website which uses PHP as an integral programming 
language as part of it.

I am trying to replicate the website’s contents from one ftp server to another 
but am encountering serious issues in doing so. I’ve spent two days trying to 
find out the reasons and now think its down to the PEAR installation.

This is therefore a question on if I want to transfer a website from one domain 
to another, then do I need to install PEAR and re-configure all the files? At 
the moment, all I can see within the ftp client regarding PEAR are the ‘Mail’ 
and ‘Mail_Mime’ components.

I am new to this so any help on this would be great.

PEAR can be managed in a number of ways. You do not say what OS you are working on, but most linux distributions carry PEAR packages as additional packages you can download and install with the PHP setup. This is often the preferred way of doing things, so if those packages have not been installed on your target system, then there will obviously be problems.

What I have done for some time since I used to be working between Linux and Windows servers was include the PEAR packages that I use as extra libraries within the website itself. That way the correct version is always distributed with the website.

What you need to do will depend on how you are currently accessing PEAR packages, and also which packages you are using.

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk



--- End Message ---
--- Begin Message ---
On Thu, 2012-08-23 at 19:12 +0100, Suraj Shah wrote:

> Thanks for your reply Ashley.
> 
> I’m getting the attached error message which I can’t seem to solve. If
> it’s just a matter of adding code to use for a library, would this be
> possible? How do I go about configuring it?
> 
> Many thanks,
> Suraj
> 
> 
> 
> On 23/08/2012 19:08, "Ashley Sheridan" <a...@ashleysheridan.co.uk>
> wrote:
> 
> 
>         On Thu, 2012-08-23 at 18:42 +0100, Suraj Shah wrote: 
>         
>                 
>                 Hi.
>                 
>                 I am currently working on a website which uses PHP as
>                 an integral programming language as part of it.
>                 
>                 I am trying to replicate the website’s contents from
>                 one ftp server to another but am encountering serious
>                 issues in doing so. I’ve spent two days trying to find
>                 out the reasons and now think its down to the PEAR
>                 installation.
>                 
>                 This is therefore a question on if I want to transfer
>                 a website from one domain to another, then do I need
>                 to install PEAR and re-configure all the files? At the
>                 moment, all I can see within the ftp client regarding
>                 PEAR are the ‘Mail’ and ‘Mail_Mime’ components.
>                 
>                 I am new to this so any help on this would be great.
>                 
>                 Many thanks
>                 
>                 Suraj
>                 
>                 
>                 Suraj Shah
>                 Online Marketing Executive
>                 26 Throgmorton Street | London | EC2N 2AN
>                 t: 020 7826 9031
>                 e: su...@aifa.net
>                 w: www.aifa.net <http://www.aifa.net> 
>         
>         
>         That would depend. Some servers install Pear outside the web
>         root but in a location the web server has access to so that it
>         can be used within your own scripts. Most often though, I've
>         just seen code use a library or two from Pear and include them
>         like you can see from your FTP access.
>         
>         What kinds of errors are you getting when you attempt to get
>         the site running on the second server?
> 
> 
> Suraj Shah
> Online Marketing Executive
> 26 Throgmorton Street | London | EC2N 2AN
> t: 020 7826 9031
> e: su...@aifa.net
> w: www.aifa.net
> twitter: @official_AIFA


Sorry, attachments get removed on this mailing list. Could you please
paste it into the body of one of your replies.

Also, please try not to top-post.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---


On 23/08/2012 19:11, "Matijn Woudt" <tijn...@gmail.com> wrote:

> On Thu, Aug 23, 2012 at 8:12 PM, Suraj Shah <su...@aifa.net> wrote:
>> Thanks for your reply Ashley.
>>
>> I’m getting the attached error message which I can’t seem to solve. If it’s
>> just a matter of adding code to use for a library, would this be possible?
>> How do I go about configuring it?
>>
>> Many thanks,
>> Suraj
>>
>
> Suraj,
>
> Attachments usually don't work at mailing lists, you should paste it
> in your mail, or use something like pastebin. Second, you should
> bottom post at this (and probably any) mailing list.
> About your question, you can install the php-pear package if you don't
> have it from your package manager, and then all you have to do is call
> pear install <package>
> and you're done.
>
> - Matijn


Thank you Matijn.

Please find below the message I get when loading the page:

[cid:3428594509_2202610]

As I am totally new to this, I am not sure how to get the package manager or to 
install this on my Mac.

Sorry.

Suraj

--- End Message ---
--- Begin Message ---
On Thu, Aug 23, 2012 at 8:21 PM, Suraj Shah <su...@aifa.net> wrote:

>
>
>
> On 23/08/2012 19:11, "Matijn Woudt" <tijn...@gmail.com> wrote:
>
> > On Thu, Aug 23, 2012 at 8:12 PM, Suraj Shah <su...@aifa.net> wrote:
> >> Thanks for your reply Ashley.
> >>
> >> I’m getting the attached error message which I can’t seem to solve. If
> it’s
> >> just a matter of adding code to use for a library, would this be
> possible?
> >> How do I go about configuring it?
> >>
> >> Many thanks,
> >> Suraj
> >>
> >
> > Suraj,
> >
> > Attachments usually don't work at mailing lists, you should paste it
> > in your mail, or use something like pastebin. Second, you should
> > bottom post at this (and probably any) mailing list.
> > About your question, you can install the php-pear package if you don't
> > have it from your package manager, and then all you have to do is call
> > pear install <package>
> > and you're done.
> >
> > - Matijn
>
>
> Thank you Matijn.
>
> Please find below the message I get when loading the page:
>
>
>
> As I am totally new to this, I am not sure how to get the package manager
> or to install this on my Mac.
>
> Sorry.
>
> Suraj
>

Hi,

I don't know much about PHP on Mac, though I think you'll find something
useful on google with 'Install PEAR on Mac'.
Looking at the error, it might be pearweb, or is there a site.php file in
your web folder on the old server?


- Matijn

--- End Message ---
--- Begin Message ---


On 23/08/2012 19:26, "Matijn Woudt" <tijn...@gmail.com> wrote:



On Thu, Aug 23, 2012 at 8:21 PM, Suraj Shah <su...@aifa.net> wrote:



On 23/08/2012 19:11, "Matijn Woudt" <tijn...@gmail.com 
<http://tijn...@gmail.com> > wrote:

> On Thu, Aug 23, 2012 at 8:12 PM, Suraj Shah <su...@aifa.net 
> <http://su...@aifa.net> > wrote:
>> Thanks for your reply Ashley.
>>
>> I’m getting the attached error message which I can’t seem to solve. If it’s
>> just a matter of adding code to use for a library, would this be possible?
>> How do I go about configuring it?
>>
>> Many thanks,
>> Suraj
>>
>
> Suraj,
>
> Attachments usually don't work at mailing lists, you should paste it
> in your mail, or use something like pastebin. Second, you should
> bottom post at this (and probably any) mailing list.
> About your question, you can install the php-pear package if you don't
> have it from your package manager, and then all you have to do is call
> pear install <package>
> and you're done.
>
> - Matijn


Thank you Matijn.

Please find below the message I get when loading the page:



As I am totally new to this, I am not sure how to get the package manager or to 
install this on my Mac.

Sorry.

Suraj

Hi,

I don't know much about PHP on Mac, though I think you'll find something useful 
on google with 'Install PEAR on Mac'.
Looking at the error, it might be pearweb, or is there a site.php file in your 
web folder on the old server?


- Matijn


OK thanks Matijn.

I’ll google it now and install it.

There is a site.php as well as a config.php file in the sub-directory of the 
old server. I’ve copied these over but not sure why it still doesn’t recognise 
it. I’ve amended the code to point to the new server as well.

Suraj

--- End Message ---
--- Begin Message ---
>
> OK thanks Matijn.
>
> I’ll google it now and install it.
>
> There is a site.php as well as a config.php file in the sub-directory of the
> old server. I’ve copied these over but not sure why it still doesn’t
> recognise it. I’ve amended the code to point to the new server as well.
>
> Suraj

The old server has probably some freaky settings that make that
directory automatically included, for example by modifing the php
include dir in php.ini, or it is part of a package. You can open up
this site.php file and look at the first lines, it might give you a
hint if it's part of some package.

- Matijn

--- End Message ---
--- Begin Message ---


On 23/08/2012 19:33, "Matijn Woudt" <tijn...@gmail.com> wrote:

>>
>> OK thanks Matijn.
>>
>> I’ll google it now and install it.
>>
>> There is a site.php as well as a config.php file in the sub-directory of the
>> old server. I’ve copied these over but not sure why it still doesn’t
>> recognise it. I’ve amended the code to point to the new server as well.
>>
>> Suraj
>
> The old server has probably some freaky settings that make that
> directory automatically included, for example by modifing the php
> include dir in php.ini, or it is part of a package. You can open up
> this site.php file and look at the first lines, it might give you a
> hint if it's part of some package.
>
> - Matijn


This is currently what the first few lines of code say:

<?PHP 
//------------------------------------------------------------------------------
 //  Controller. // // This file acts as a controller for the site, handling 
the top // level actions, starting sessions, connecting to database, etc 
//------------------------------------------------------------------------------
    $site['dir']['root'] = dirname(__FILE__);     
//------------------------------------------------------------------------------
 //  Configuration. // // The configuration file includes DB details, email 
addresses // and any other easily configurable options. 
//------------------------------------------------------------------------------
    $site['dir']['document_root'] = $site['dir']['root'] . '/public_html/';     
   require_once $site['dir']['root'] . '/config.php'; 
//------------------------------------------------------------------------------
 // Functions 
//------------------------------------------------------------------------------
    // Base Functions    require_once $site['dir']['functions'] . 
'functions.php';        require_once $site['dir']['functions'] . 'common.php';


Not sure what any of this means.

Suraj

--- End Message ---
--- Begin Message ---
On Thu, 2012-08-23 at 20:33 +0200, Matijn Woudt wrote:

> >
> > OK thanks Matijn.
> >
> > I’ll google it now and install it.
> >
> > There is a site.php as well as a config.php file in the sub-directory of the
> > old server. I’ve copied these over but not sure why it still doesn’t
> > recognise it. I’ve amended the code to point to the new server as well.
> >
> > Suraj
> 
> The old server has probably some freaky settings that make that
> directory automatically included, for example by modifing the php
> include dir in php.ini, or it is part of a package. You can open up
> this site.php file and look at the first lines, it might give you a
> hint if it's part of some package.
> 
> - Matijn
> 


You just made me think actually, could it be an .htaccess file
re-routing the file paths (different to URL re-routing)? Because of the
way MacOS and Linux works, an .htaccess file would be hidden by default
and therefore not necessarily copied across.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---


On 23/08/2012 20:12, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

On Thu, 2012-08-23 at 20:33 +0200, Matijn Woudt wrote:

>
> OK thanks Matijn.
>
> I’ll google it now and install it.
>
> There is a site.php as well as a config.php file in the sub-directory of the
> old server. I’ve copied these over but not sure why it still doesn’t
> recognise it. I’ve amended the code to point to the new server as well.
>
> Suraj

The old server has probably some freaky settings that make that
directory automatically included, for example by modifing the php
include dir in php.ini, or it is part of a package. You can open up
this site.php file and look at the first lines, it might give you a
hint if it's part of some package.

- Matijn


You just made me think actually, could it be an .htaccess file re-routing the 
file paths (different to URL re-routing)? Because of the way MacOS and Linux 
works, an .htaccess file would be hidden by default and therefore not 
necessarily copied across.


Ok thanks Ashley.

If this .htaccess file was hidden by default, how would I go about accessing it 
and copying or transferring it over?

Suraj

--- End Message ---
--- Begin Message ---
On Thu, Aug 23, 2012 at 9:14 PM, Suraj Shah <su...@aifa.net> wrote:
>
>
>
> On 23/08/2012 20:12, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>
> On Thu, 2012-08-23 at 20:33 +0200, Matijn Woudt wrote:
>
>
>>
>> OK thanks Matijn.
>>
>> I’ll google it now and install it.
>>
>> There is a site.php as well as a config.php file in the sub-directory of
>> the
>> old server. I’ve copied these over but not sure why it still doesn’t
>> recognise it. I’ve amended the code to point to the new server as well.
>>
>> Suraj
>
> The old server has probably some freaky settings that make that
> directory automatically included, for example by modifing the php
> include dir in php.ini, or it is part of a package. You can open up
> this site.php file and look at the first lines, it might give you a
> hint if it's part of some package.
>
> - Matijn
>
>
> You just made me think actually, could it be an .htaccess file re-routing
> the file paths (different to URL re-routing)? Because of the way MacOS and
> Linux works, an .htaccess file would be hidden by default and therefore not
> necessarily copied across.
>
>
>
> Ok thanks Ashley.
>
> If this .htaccess file was hidden by default, how would I go about accessing
> it and copying or transferring it over?
>
> Suraj

On Linux systems (and probably Mac too), you can show if there are
hidden files by using ls -a.
You can just use cp .htaccess <destination> to copy.

- Matijn

--- End Message ---
--- Begin Message ---
On Thu, Aug 23, 2012 at 9:12 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:

> **
> On Thu, 2012-08-23 at 20:33 +0200, Matijn Woudt wrote:
>
> >
> > OK thanks Matijn.
> >
> > I’ll google it now and install it.
> >
> > There is a site.php as well as a config.php file in the sub-directory of the
> > old server. I’ve copied these over but not sure why it still doesn’t
> > recognise it. I’ve amended the code to point to the new server as well.
> >
> > Suraj
>
> The old server has probably some freaky settings that make that
> directory automatically included, for example by modifing the php
> include dir in php.ini, or it is part of a package. You can open up
> this site.php file and look at the first lines, it might give you a
> hint if it's part of some package.
>
> - Matijn
>
>
>
> You just made me think actually, could it be an .htaccess file re-routing
> the file paths (different to URL re-routing)? Because of the way MacOS and
> Linux works, an .htaccess file would be hidden by default and therefore not
> necessarily copied across.
>
>
>
That could be a possibility, though looking at the code Suraj send it's not
very likely as there is path redirect magic in there. Most likely the web
folder is named differently (it seems like it assumes the web files to be
in public_html, which might not be the case in his new server.

- Matijn

--- End Message ---
--- Begin Message ---

On 23/08/2012 20:12, "Matijn Woudt" <tijn...@gmail.com> wrote:



On Thu, Aug 23, 2012 at 9:12 PM, Ashley Sheridan <a...@ashleysheridan.co.uk> 
wrote:

On Thu, 2012-08-23 at 20:33 +0200, Matijn Woudt wrote:
>
> OK thanks Matijn.
>
> I’ll google it now and install it.
>
> There is a site.php as well as a config.php file in the sub-directory of the
> old server. I’ve copied these over but not sure why it still doesn’t
> recognise it. I’ve amended the code to point to the new server as well.
>
> Suraj

The old server has probably some freaky settings that make that
directory automatically included, for example by modifing the php
include dir in php.ini, or it is part of a package. You can open up
this site.php file and look at the first lines, it might give you a
hint if it's part of some package.

- Matijn


You just made me think actually, could it be an .htaccess file re-routing the 
file paths (different to URL re-routing)? Because of the way MacOS and Linux 
works, an .htaccess file would be hidden by default and therefore not 
necessarily copied across.



That could be a possibility, though looking at the code Suraj send it's not 
very likely as there is path redirect magic in there. Most likely the web 
folder is named differently (it seems like it assumes the web files to be in 
public_html, which might not be the case in his new server.

- Matijn

You’re right Matijn.

It’s currently pointing to a folder called ‘public_html’ where the index.php 
and the rest of the website is stored. I, first, tried configuring it so that 
on the new server, it was directly within the root server but this kept on 
bringing error messages.

I then replicated the old server on the new server but am still getting these 
error messages as described earlier.

Also, I have typed in ls  -a and it comes up with the directories, but there is 
no “such file” for .htaccess.

Suraj

--- End Message ---
--- Begin Message ---
On Thu, Aug 23, 2012 at 9:25 PM, Suraj Shah <su...@aifa.net> wrote:
>
>
> On 23/08/2012 20:12, "Matijn Woudt" <tijn...@gmail.com> wrote:
>
>
>
> On Thu, Aug 23, 2012 at 9:12 PM, Ashley Sheridan <a...@ashleysheridan.co.uk>
> wrote:
>
>
> On Thu, 2012-08-23 at 20:33 +0200, Matijn Woudt wrote:
>
>>
>> OK thanks Matijn.
>>
>> I’ll google it now and install it.
>>
>> There is a site.php as well as a config.php file in the sub-directory of
>> the
>> old server. I’ve copied these over but not sure why it still doesn’t
>> recognise it. I’ve amended the code to point to the new server as well.
>>
>> Suraj
>
> The old server has probably some freaky settings that make that
> directory automatically included, for example by modifing the php
> include dir in php.ini, or it is part of a package. You can open up
> this site.php file and look at the first lines, it might give you a
> hint if it's part of some package.
>
> - Matijn
>
>
> You just made me think actually, could it be an .htaccess file re-routing
> the file paths (different to URL re-routing)? Because of the way MacOS and
> Linux works, an .htaccess file would be hidden by default and therefore not
> necessarily copied across.
>
>
>
> That could be a possibility, though looking at the code Suraj send it's not
> very likely as there is path redirect magic in there. Most likely the web
> folder is named differently (it seems like it assumes the web files to be in
> public_html, which might not be the case in his new server.
>
> - Matijn
>
> You’re right Matijn.
>
> It’s currently pointing to a folder called ‘public_html’ where the index.php
> and the rest of the website is stored. I, first, tried configuring it so
> that on the new server, it was directly within the root server but this kept
> on bringing error messages.
>
> I then replicated the old server on the new server but am still getting
> these error messages as described earlier.
>
> Also, I have typed in ls  -a and it comes up with the directories, but there
> is no “such file” for .htaccess.
>
> Suraj

It's hard to say how the files should be stored and how it should be
configured, because it is specific to your old website.
All I can say now is, check the following:
1) Make sure you copied all files from the old server, so that all
files end up at the same place in the new server.
2) .htaccess files can also be stored in subdirectories, though that
doesn't seem likely here.
3) Check you old website virtual host config, this depends on which
webserver there is. In most (all?) webservers it is possibily to
specify URL redirects. For Apache on a Unix based server, check the
config files in /etc/apache (ubuntu has them in
/etc/apache/sites_enabled), Nginx would be in /etc/nginx (Ubuntu also
has them in /etc/nginx/sites_enabled). Other webservers probably also
have their config files in /etc/<webservername>/...

- Matijn

--- End Message ---
--- Begin Message ---
Hello everyone,

                In my quest to build bigger and better dynamic content, I am
putting forth a concept to see what you all think.

Many times I come across customers who want drop down menus dynamically
built from database tables.

 

Old way Example:

Echo '<SELECT ID=personnel><option value='0'>--Please  Select--</option>';

$query = "SELECT * FROM personnel ORDER BY last_name";

$result = mysql_query($query);

If(mysql_num_rows($result) >= 1)

{

While($row = mysql_fetch_assoc($result))

{

Echo "<option value='".$row['ID']."'>".$row['first_name']."
".$row['last_name']."</option>";

                }

}

Echo '</select>';

*********************************************************

 

I am purposing a Method for this that has some flexibility.

 

Initialize Object:  $yourobject = new yourclass();

Call method: // The call design is just so you have a better understanding
of my concept

$dropdown = $yourobject-> dropmenu('personnell','ID',array(0 =>
'first_name', 1 => 'last_name'), 'last_name'); 

 

Function dropmenu($table,$fieldforvalue,$fieldstodisplay,$fieldorder)  //
Yes you could add some WHERE filters as well 

{

                $arraytoreturn = array();

                If(strlen($table) >= 3){   

                if(is_array($fieldstodisplay)){

                $count = 0;

                                foreach($fieldstodisplay as $key=>$values){

                                                if(strlen($values) >=3){

                                If($count == 0){

                                $fields = $values;

}else{

$fields . = ",".$values;

                                }                              

$count++;

                                                                }


}

                }else{

                                If(strlen(($fieldstodisplay) >= 1){

                                $fields = $fieldstodisplay;

                                $fieldstodisplay = array(0
=>$fieldstodisplay);

                                }else{

                                Return $arraytoreturn; // Return nothing
because no field was selected.

}

                }

}else{

Return $arraytoreturn; // Return nothing because no table was selected.

}              

                If(strlen($fieldorder) >= 3) {

$orderfilter = " ORDER BY ".$fieldorder." ";          

                }else{

                $orderfilter = "";

}

$query = "SELECT ".$fields." FROM ".$table." ".$orderfilter." ";

$result = mysql_query($query);

If(mysql_num_rows($result) >= 1)

{

$arraytoreturn[] = "<option value=0>--Please Select--</option>";

                                While($row = mysql_fetch_assoc($result))

{

$display_fields   = "";

                Foreach($fieldstodisplay as $key=>$values){

                $display_fields  .= $row[$values]." ";      

                }              

                If(strlen($fieldforvalue >= 3){

                $arraytoreturn[] = "<option
value='".$row[$fieldforvalue]."'>".$display_fields  ."</option>";

                }else{

                $arraytoreturn[] = "<option>".$display_fields  ."</option>";

                }

}

                Return $arraytoreturn;

                }else{

Return $arraytoreturn; // Nothing to return.

                }

}

 

Now I can call the drop downs driven by database tables dynamically and It
saves me a TON of time.

Echo '<SELECT ID=personnel>';

Foreach($dropdown as $key=>$values){

Echo $values;

}

Echo '</select>';

 

 

Richard L. Buskirk

"Some of the world's greatest feats were accomplished by people not smart
enough to know they were impossible"

 


--- End Message ---
--- Begin Message ---
On Thu, Aug 23, 2012 at 9:51 PM, admin <ad...@buskirkgraphics.com> wrote:
> Hello everyone,
>
>                 In my quest to build bigger and better dynamic content, I am
> putting forth a concept to see what you all think.
>
> Many times I come across customers who want drop down menus dynamically
> built from database tables.
>
>
>
> Old way Example:
>

>
> *********************************************************
>
>
>
> I am purposing a Method for this that has some flexibility.
>
>
>
> Initialize Object:  $yourobject = new yourclass();
>
> Call method: // The call design is just so you have a better understanding
> of my concept
>
> $dropdown = $yourobject-> dropmenu('personnell','ID',array(0 =>
> 'first_name', 1 => 'last_name'), 'last_name');
>
>
>
> Function dropmenu($table,$fieldforvalue,$fieldstodisplay,$fieldorder)  //
<<snip>>
>
>
>
> Now I can call the drop downs driven by database tables dynamically and It
> saves me a TON of time.
>
> Echo '<SELECT ID=personnel>';
>
> Foreach($dropdown as $key=>$values){
>
> Echo $values;
>
> }
>
> Echo '</select>';
>
>

Hi Richard,


First of all, I don't really see the problem with the first code, as
it's not that many LOC. OTOH comparing it to the enormous amount of
lines needed for your function it seems a bit overkill. If you combine
$query = .. and mysql_query($query), to a single line (which I
prefer), then you only have 4 lines of code in your first example. ( I
only count lines that do something, not the brackets etc). Your
function has about 40.
If you still want this function, I would change a few things.
1) Do all the echo stuff inside your function, or, only return the
data and print the <option> html stuff outside of your function.
You're now mixing both which seems wrong.
2) Use SQL as input, and if you wish to make it easy for yourself,
write a seperate function that writes SQL queries for you (or just use
a lib for it, there are probably plenty).
3) Use mysqli, mysql is deprecated.
4) Use mysqli_real_escape_string to sanitize your input before using
it on the database.

Hope this helps you,

- Matijn

--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Matijn Woudt [mailto:tijn...@gmail.com] 
Sent: Thursday, August 23, 2012 4:39 PM
To: admin
Cc: php-gene...@lists.php.net
Subject: Re: [PHP] Dynamic Content thoughts

On Thu, Aug 23, 2012 at 9:51 PM, admin <ad...@buskirkgraphics.com> wrote:
> Hello everyone,
>
>                 In my quest to build bigger and better dynamic 
> content, I am putting forth a concept to see what you all think.
>
> Many times I come across customers who want drop down menus 
> dynamically built from database tables.
>
>
>
> Old way Example:
>

>
> *********************************************************
>
>
>
> I am purposing a Method for this that has some flexibility.
>
>
>
> Initialize Object:  $yourobject = new yourclass();
>
> Call method: // The call design is just so you have a better 
> understanding of my concept
>
> $dropdown = $yourobject-> dropmenu('personnell','ID',array(0 => 
> 'first_name', 1 => 'last_name'), 'last_name');
>
>
>
> Function dropmenu($table,$fieldforvalue,$fieldstodisplay,$fieldorder)  
> //
<<snip>>
>
>
>
> Now I can call the drop downs driven by database tables dynamically 
> and It saves me a TON of time.
>
> Echo '<SELECT ID=personnel>';
>
> Foreach($dropdown as $key=>$values){
>
> Echo $values;
>
> }
>
> Echo '</select>';
>
>

Hi Richard,


First of all, I don't really see the problem with the first code, as it's not 
that many LOC. OTOH comparing it to the enormous amount of lines needed for 
your function it seems a bit overkill. If you combine $query = .. and 
mysql_query($query), to a single line (which I prefer), then you only have 4 
lines of code in your first example. ( I only count lines that do something, 
not the brackets etc). Your function has about 40.
If you still want this function, I would change a few things.
1) Do all the echo stuff inside your function, or, only return the data and 
print the <option> html stuff outside of your function.
You're now mixing both which seems wrong.
2) Use SQL as input, and if you wish to make it easy for yourself, write a 
seperate function that writes SQL queries for you (or just use a lib for it, 
there are probably plenty).
3) Use mysqli, mysql is deprecated.
4) Use mysqli_real_escape_string to sanitize your input before using it on the 
database.

Hope this helps you,

- Matijn

------------------------------
Thank you Matijn,
        For coding style, I think we can agree on the fact each person has a 
different style and reasoning's for their own style.
My style on SQL statements was passed down to me from some very successful 
developers who felt the reason for creating a 
SQL statement in such a manor was to assist in informatics and Debugging.

While you're not getting the point in the Method being in the class and called 
when needed. It cuts coding size and time down by extremes when you have 
multiple drop downs that may or may not repeat on different views. 

Matijn was very correct on the combination of HTML and PHP in a Method and I do 
agree, many feel this is a giant no no. Many could simply pass the array to the 
view and create the drop down from there. The wonderful part of the method is 
that it has the flexibility to meet many coding styles and a vast range of 
abilities.

I do however feel the Mysql_real_escape_string to be un-necessary for the 
developer, being the end-user(GUI between the keyboard and Chair) will not be 
passing these fields to the Database. But escape away if you feel safer doing 
this with-in your own version of the method. 

As for the MYSQL VS MYSQLI in MOST benchmarks, I find the MYSQL extension to be 
slightly faster. 
Yes MYSQLI functions are more Object-oriented in some designs I feel MYSQL out 
performs MYSQLI in large database setups for a personal preference.
Again you may change the Design of the method to meets your needs MYSQL or 
MYSQLI doesn’t really take away from the concept.







--- End Message ---
--- Begin Message ---
OT Reply -- just frustrated with the way email screws up program
listings. It's a royal pain to have to strip out code and then put it
in an editor and tidy it up just to be able to make heads or tails out
of something. There are lots of code pasting sites around, but that
breaks up the continuity of the list archive. No solution, just
frustrated....

--- End Message ---

Reply via email to