php-general Digest 7 Oct 2007 07:35:50 -0000 Issue 5059

Topics (messages 262874 through 262889):

Re: A two flavored post
        262874 by: Robert Cummings
        262886 by: tedd
        262887 by: heavyccasey.gmail.com

Sending lots of emails - 2 choices - choose the best one
        262875 by: Martin Zvarík
        262879 by: Daevid Vincent
        262882 by: Jeff Cohan

mySQL Results To XML
        262876 by: CK
        262877 by: CK
        262878 by: mike

Re: mySQL Results To XML -- my xmltag() functions
        262880 by: Daevid Vincent
        262881 by: mike
        262884 by: Timothy Murphy

Something you can do with AJAX + PHP as well
        262883 by: Mark

Handling profile view counters
        262885 by: Steve Finkelstein

Re: Beginner Tutorials for using CLASSES in PHP4
        262888 by: Nathan Nobbe

Please recommend blog script
        262889 by: Niels

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
On Sat, 2007-10-06 at 13:41 -0400, tedd wrote:
> At 1:26 PM -0400 10/5/07, Nathan Nobbe wrote:
> >strange; i missed that when i put it together; my bad, it was late.
> >here is a revision that works.
> >
> ><html>
> >     <head>
> >         <script type="text/javascript">
> >             window.onload = function() {
> >                 var someLink = document.getElementById('someLink');
> >                 someLink.href += "&anotherVar=8";
> >                 alert(document.getElementById('someLink').href);
> >             }
> >         </script>
> >     </head>
> >     <body>
> >         <a id="someLink" href=" http://somesite.com?a=5";>
> >             click here
> >         </a>
> >     </body>
> ></html>
> >
> >the problem was the local variable was being assigned the value of the
> >attribute, not the reference
> >to the tag in the dom.  i have now set it to be a reference to the variable
> >in the dom.
> 
> -nathan:
> 
> Not that I provided information otherwise, but 
> document.getElementById won't work in this case because there are 
> several links involved. As such, I have to use 
> document.getElementByClass and that has problems.
> 
> Unfortunately, my solution isn't unobtrusive.
> 
> <a href="img.php?i=<?php echo($value);?>" onclick="window.location = 
> this.getAttribute( 'href' ) + '&s=' + s; return false;">
> 
> However, I couldn't see a way to make it so.

Why not? I'm guessing because you need to the link to have the
JavaScript variable in it. If this is the case then the href target
should link to a page informing the user that they need to have
JavaScript installed. By doing so you inform them of why clicking on the
link is not having the desired outcome :)

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
At 1:49 PM -0400 10/6/07, Robert Cummings wrote:
On Sat, 2007-10-06 at 13:41 -0400, tedd wrote:
 > Unfortunately, my solution isn't unobtrusive.

 <a href="img.php?i=<?php echo($value);?>" onclick="window.location =
 this.getAttribute( 'href' ) + '&s=' + s; return false;">

 However, I couldn't see a way to make it so.

Why not? I'm guessing because you need to the link to have the
JavaScript variable in it. If this is the case then the href target
should link to a page informing the user that they need to have
JavaScript installed. By doing so you inform them of why clicking on the
link is not having the desired outcome :)

Cheers,
Rob.

Rob:

I would agree with you IF I was creating a web page for the general public. However, what I am creating in my laboratory is a monster of my own making that will be used only by my clients AND those clients will be required to have javascript turned on.

Sometimes, programming for the lowest common denominator limits possibilities.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
ALSO:

<a href="img.php?i=<?php echo($value);?>" onclick="window.location =
this.getAttribute( 'href' ) + '&s=' + s; return false;">

can be altered to be:

<a href="img.php?i=<?php echo($value);?>"
onclick="this.setAttribute(this.getAttribute( 'href') + '&s=' + s);">

What exactly do you need to do, anyways? Maybe there'll be some better
way to do this.

On 10/6/07, tedd <[EMAIL PROTECTED]> wrote:
> At 1:49 PM -0400 10/6/07, Robert Cummings wrote:
> >On Sat, 2007-10-06 at 13:41 -0400, tedd wrote:
> >  > Unfortunately, my solution isn't unobtrusive.
> >>
> >>  <a href="img.php?i=<?php echo($value);?>" onclick="window.location =
> >>  this.getAttribute( 'href' ) + '&s=' + s; return false;">
> >>
> >>  However, I couldn't see a way to make it so.
> >
> >Why not? I'm guessing because you need to the link to have the
> >JavaScript variable in it. If this is the case then the href target
> >should link to a page informing the user that they need to have
> >JavaScript installed. By doing so you inform them of why clicking on the
> >link is not having the desired outcome :)
> >
> >Cheers,
> >Rob.
>
> Rob:
>
> I would agree with you IF I was creating a web page for the general
> public. However, what I am creating in my laboratory is a monster of
> my own making that will be used only by my clients AND those clients
> will be required to have javascript turned on.
>
> Sometimes, programming for the lowest common denominator limits possibilities.
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hello--
   I want to send email to 100+ recipients. Two choices I thought of:

1) once call mail() and use BCC, but the negative of this method is that every recipient in BCC has header "To" same (so I used to put my email in here - not email of one of the recipients).

2) several calls to mail() function with each recipient's emal

Thanks for ideas,
--Martin

--- End Message ---
--- Begin Message ---
Option 3) setup a dedicated program to handle the mail, such as
"mailman" and then send ONE email from PHP to the listserver which will
then dispatch the mail accordingly, properly, in batches.

http://www.gnu.org/software/mailman/index.html

(at least, that's how I do it currently) 

> -----Original Message-----
> From: Martin Zvarík [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, October 06, 2007 11:13 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Sending lots of emails - 2 choices - choose 
> the best one
> 
> Hello--
>     I want to send email to 100+ recipients. Two choices I thought of:
> 
> 1) once call mail() and use BCC, but the negative of this 
> method is that 
> every recipient in BCC has header "To" same (so I used to put 
> my email 
> in here - not email of one of the recipients).
> 
> 2) several calls to mail() function with each recipient's emal
> 
> Thanks for ideas,
> --Martin
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

--- End Message ---
--- Begin Message ---
Martin Zvarík wrote:
> Hello--
> I want to send email to 100+ recipients. Two choices I 
> thought of:
> 
> 1) once call mail() and use BCC, but the negative of this 
> method is that every recipient in BCC has header "To" 
> same (so I used to put my email in here - not email of 
> one of the recipients).
> 
> 2) several calls to mail() function with each recipient's emal

I like #2, within a loop.

E.g.,

// variables defined:
$subject = 'My weekly newsletter';
$headers = [your mail headers here]
$message = "Blah blah \n" .
"and furthermore yada yada \n" .
"and finally so on";

while ( $record = mysql_query('SELECT email from clients etc') )
{
  $to = $record[email];
  mail($to, $subject, $message, $headers);
}

--- End Message ---
--- Begin Message ---
Hi,


Here's the mission, creating a movie DB, I need the results returned from mySQL in an XML format for use with the FLASH Professional DataGrid. Any tips on formating mySQL results would be grand. Here's the structure of the DB, if needed.

DVD Table
*Title ID
*Title
*Genre
*Actor
*Director
*Producer
*Date Purchased
*Price
*Date Released
*Length
*Plot
*Review(*****)
*Rating


person table
*Producer ID
*First Name
*Last Name
*Director ID
*First Name
*Last Name


Actors_Link
actor_link_id just a primary auto-increment number
person_id
movie_id
role_id


--- End Message ---
--- Begin Message ---
Hi,


Here's the mission, creating a movie DB, I need the results returned from mySQL in an XML format for use with the FLASH Professional DataGrid. Any tips on formating mySQL results would be grand. Here's the structure of the DB, if needed.

DVD Table
*Title ID
*Title
*Genre
*Actor
*Director
*Producer
*Date Purchased
*Price
*Date Released
*Length
*Plot
*Review(*****)
*Rating


person table
*Producer ID
*First Name
*Last Name
*Director ID
*First Name
*Last Name


Actors_Link
actor_link_id just a primary auto-increment number
person_id
movie_id
role_id


--- End Message ---
--- Begin Message ---
On 10/6/07, CK <[EMAIL PROTECTED]> wrote:
> Hi,
>
>
> Here's the mission, creating a movie DB, I need the results returned
> from mySQL in an XML format for use with the  FLASH Professional
> DataGrid. Any tips on formating mySQL results would be grand.  Here's
> the structure of the DB, if needed.

you could easily just print the xml manually.

<dvd>
 <titleID>foo</titleID>
 <bar>etc</bar>
</dvd>

or, i believe mysql will return XML output but i'm not sure a PHP
function exists to do that.

no need to use fancy DOM functions, outputting XML is easy, parsing it
is when you need to use the special functions and such.

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

> -----Original Message-----
> you could easily just print the xml manually.
> 
> <dvd>
>  <titleID>foo</titleID>
>  <bar>etc</bar>
> </dvd>
> 
> or, i believe mysql will return XML output but i'm not sure a PHP
> function exists to do that.
> 
> no need to use fancy DOM functions, outputting XML is easy, parsing it
> is when you need to use the special functions and such.

Here's the 'functions_xml.inc.php' file I use, it has served me well and
handles I believe all tag cases, personally I'm a big fan of using the
attributes as they're most easily parsed out in the PHP DOM functions:

--------------------------------8<--------------------------------------
---

<?php
/**
* Aborts XML output with an Error message
*
* @return       string xml formatted tags and data
* @param        string $message the error message to output
* @version      1.3
* @date 07/14/05
*/
function XML_exit($message)
{
        header( "Content-type: text/xml" );
        print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
        //TODO: [dv] we should probably put an error code so that it's
easier for the scripts to parse
        //print xmltag('error', array('code'=>'TBD',
'string'=>$message));
        print xmltag('error',null, 1);
                print xmltag('code','TBD');
                print xmltag('string',$message);
        print xmltag('error',null, 2);
        exit;
}

/**
* Returns a well formed lowercase XML tag string suitable for printing
to screen
*
* tagType=1: is like tagType=3, but without the />
* tagType=2: is the closing </xmltag> only.
*
* tagType=3:
*       <xmltag foo=bar />
*
*       also note that array('foo'=>'bar','__VALUE'='1234') will
generate:
*       <xmltag foo=bar>1234</xmltag>
*
* tagType=4:
*               <xmltag>
*                       <foo>bar</foo>
*               </xmltag>
*
* @return       string xml formatted tags and data
* @param        string $xmltag  is the tag name to surround
* @param        mixed $data     data to output between the tags, if
$data is an array, it will be expanded as KEY=VALUE in the tag. If there
is an array element __VALUE that will be a value between XML tags after
the list of attributes
* @param        int $tagType 1=start tag only, 2=end tag only,
3=default, 4=verbose tag
* @todo         use recursion to get nested arrays working, especially
for tagType=4
* @version      1.6
* @date         01/16/06
*/
function xmltag($xmltag, $data, $tagType = 3) 
{
        // convert spaces to underscores and makes it lowercase as per
XML specification
        $xmltag = strtolower(str_replace(' ','_', $xmltag ));

        // encode all characters that need to be converted for export
into XML
        $data = xmlentities($data);
        
        //we put this first, as it is used most frequently
        if ($tagType == 3) 
        {
                if (isset($data))
                {
                        if (is_array($data))
                        {
                                if (isset($data['__VALUE']))
                                {
                                        $value_data = $data['__VALUE'];
                                        unset($data['__VALUE']);
                                }
                                
                                $tmp = '<'.$xmltag;
                                
                                foreach($data as $key => $value)
                                {
                                        if ( is_bool($value) ) $value =
($value === true)?'true':'false';
                                        $tmp .= '
'.$key.'="'.$value.'"';
                                }
                                
                                if (isset($value_data))
                                {
                                        if ( is_bool($value_data) )
$value_data = ($value_data === true)?'true':'false';
                                        $tmp .=
">".$value_data."</".$xmltag.">\r\n";
                                }
                                else
                                        $tmp .= " />\r\n";
                                
                                return $tmp;
                        }
                        else
                        {
                                if ( is_bool($data) ) $data = ($data ===
true)?'true':'false';
                                return
'<'.$xmltag.'>'.$data.'</'.$xmltag.">\r\n";
                        }
                }
                else return '<'.$xmltag." />\r\n";
        } //tag type 3
        
        if ($tagType == 1)      
        {
                $tmp = '<'.$xmltag;
                
                if (is_array($data))
                {
                        foreach($data as $key => $value)
                        {
                                if ( is_bool($value) ) $value = ($value
=== true)?'true':'false';
                                $tmp .= ' '.$key.'="'.$value.'"';
                        }
                }
                
                $tmp .= ">\r\n";
                
                return $tmp;
        } //tag type 1
        
        if ($tagType == 2)      return '</'.$xmltag.">\r\n";
        
        if ($tagType == 4) 
        {
                if (isset($data))
                {
                        if (is_array($data))
                        {
                                $tmp = '<'.$xmltag.">\r\n";
                                
                                foreach($data as $key => $value)
                                {
                                        if ( is_bool($value) ) $value =
($value === true)?'true':'false';
                                        $tmp .=
'<'.$key.'>'.$value.'<'.$key."/>\r\n";
                                }
                                
                                $tmp = '</'.$xmltag.">\r\n";
                                
                                return $tmp;
                        }
                        else
                        {
                                if ( is_bool($data) ) $data = ($data ===
true)?'true':'false';
                                return
'<'.$xmltag.'>'.$data.'</'.$xmltag.">\r\n";
                        }
                }
                else return '<'.$xmltag." />\r\n";
        } //tag type 4
}

/**
* Print out an array in XML form (useful for debugging)
* @access       public
* @param        string $myArray the array to output in XML format
* @author       Daevid Vincent [EMAIL PROTECTED]
* @version      1.0
* @date         07/19/05
* @todo It would be nice if we could extract the array's variable name
and output that as an attribute
*/
function print_r_xml($myArray)
{
        print xmltag('ARRAY', null, 1);
        foreach($myArray as $k => $v)
        {
                if (is_array($v))
                        print_r_xml($v);
                else
                        print xmltag($k,htmlspecialchars($v));
        }
        print xmltag('ARRAY', null, 2);
}
?>

--- End Message ---
--- Begin Message ---
On 10/6/07, Daevid Vincent <[EMAIL PROTECTED]> wrote:

> Here's the 'functions_xml.inc.php' file I use, it has served me well and
> handles I believe all tag cases, personally I'm a big fan of using the
> attributes as they're most easily parsed out in the PHP DOM functions:

I made this at one point:

function array2xml($array, $complete = true) {
    $xml = "<$array[NODE] ";
    unset($array['NODE']);
    ksort($array);
    foreach(array_keys($array) as $key) {
        $xml .= "$key=\"$array[$key]\" ";
    }
    if($complete) {
        $xml .= "/";
    }
    $xml .= ">";
    return $xml;
}

it takes an associative array with a key of "NODE" for the node name
and makes it a single xml node with all the content in attributes. it
even alphabetizes the attributes. special preparing of the data (like
htmlspecialchars()) might be needed to ensure XML compliance.

i made one to translate it into nodes, but i think at the time i read
that attribute parsing is quicker.

calling it looks like this:

$context['NODE'] = "context-info";
$context['current-datetime'] = format_time_xml(time(),"UTC");
$context['current-hostname'] = $_SERVER['HTTP_HOST'];
$context['current-page'] = $_SERVER['PHP_SELF'];
$xml = array2xml($context);

--- End Message ---
--- Begin Message ---
<posted & mailed>

mike wrote:

> I made this at one point:
> 
> function array2xml($array, $complete = true) {
>     $xml = "<$array[NODE] ";
>     unset($array['NODE']);
>     ksort($array);
>     foreach(array_keys($array) as $key) {
>         $xml .= "$key=\"$array[$key]\" ";
>     }
>     if($complete) {
>         $xml .= "/";
>     }
>     $xml .= ">";
>     return $xml;
> }

What about the reverse - converting the XML back to MySQL?
(I'm interested for an address book project,
but don't know too much of XML or mySQL!)

--- End Message ---
--- Begin Message ---
Hey,

I've made a nice video where you see ajax in combination with php. and
it works really well although really is misspelled "realy".

Here is the video:
http://magedb.mageprojects.com/videos/MageDB%202nd%20WIP%20demonstration%20with%20AJAX.mpeg

Cool huh?

Mark.

--- End Message ---
--- Begin Message ---
Hi all,

I'm contemplating on a proper way of handling a counter for profile
views on my auto dealership website. I'm currently confused with the
type of algorithm to approach this with.

Say a user has a registered session, and views profile a). I can
increment the counter for that vehicle. The user can then surf
vehicles b,c,d....N etc and I'll increment the counter. However, if
the same session tries to visit profile a,b,c,d should I not increment
the counter? How would you all do it?

Any examples with code would be very insightful and appreciated.

Thank you kindly.

- sf

--- End Message ---
--- Begin Message ---
On 10/6/07, Robert Cummings <[EMAIL PROTECTED]> wrote:

>
> Tony is right here. Encapsulation is about hiding the details of the
> implementation


rob, here is tonys definition of encapsulation:
Encapsulation is the act of placing data and the
operations that perform on that data in the same class. The data does not
have to be private at all.
tony did not at any point say that encapsulation is about hiding
implementation details.
im the one who indicated encapsulation is about hiding implementation
details.

tonys definition is contrary to all the definitions i have pulled from books
on object oriented programming (see last post).
actually, its not contrary, but it is only part of the definition.

encapsulation is infact about hiding implementation details; its about
driving client code through a well defined interface, to get access to the
behavior the class supplies.
in order to implement this behavior there are often times variables *and*
methods that client code should not have access to.

i pointed out that classes that do not utilize ppp allow client code to
become dependent upon their implementation.  because weve only been
stressing the hiding of member variables (i guess thats what data hiding
means) in this conversation i think we have glossed over the fact that it is
also important to be able to hide certain member functions as well.

this cannot be done in php4, and as i said can lead to systems where client
code is made dependent upon the implementation of other classes, which leads
to very delicate systems.

you guys are not the only php4 advocates ive run into; it just so happens i
have a good friend with a very strong php background who tells me
practically the same thing, ppp isnt that big of a deal.  i disagree, why,
is it because ive had a classical education in oop, because ive worked with
a number of languages that dont allow you to create class members without
specifying an access level?  for those reasons and because ive had the
misfortune of working in places that have tightly coupled code.  im talking
about hundreds of thousands of lines of madness.  ppp could have saved these
systems greatly.

Also, don't forget that abstraction, encapsulation, and information
> hiding all have a price.
>

if youre referring to performance i think the price of not using these tools
is also worth mention.  namely code which is easily subject to tight
coupling, which as i said leads to systems that are difficult to maintain
and extend.
personally i value maintainability and extensibility over performance, but
thats merely a personal preference.

(tony)
> I strongly disagree. It *IS* possible to write perfectly adequate OO
programs
> using PHP 4. If you cannot then you have been taught some bad habits.

and what exactly does adequate mean?  any oo php4 'program' is inherently
weak for the reasons i have sighted, namely the implementation can be
latched onto producing tightly coupled code.
dont worry tony, i can construe some pretty decent php4 code myself; i wrote
a date time package that ive ported to 3 projects including a conversion to
php5 in one of those.  the point is that the other developers i work with
dont have a clue about object oriented concepts which in my experience
constitutes the vast majority of php developers.  the even bigger point, on
the topic of this thread is that php4 is out the door, so there is yet
another possibly more important reason not to waste time learning oop
studying php4.

ive studied oop for years and worked with a number of oop languages; many of
the bad habits i had at one point or another have been removed.  guess what
the first one was, not letting client code access member variables directly
:)

if you dont mind brittle oop code, php4 will suffice.  if you want to tap
into real object oriented features, many of which i consider fundamental
(such as ppp [to name just one]) go for php5.  truthfully i still think
there are some features missing; interface hierarchies being the main one,
perhaps well get lucky in php6...

-nathan

--- End Message ---
--- Begin Message ---
Hi,

I'm looking to add some blogging functionality to a website.

I want:
- Articles in categories
- Wysiwyg and images
- Php/mysql/apache
- Readers can comment
- Admin interface

I don't want:
- Website builder / CMS
- To put my website in a blog, rather the other way around

Basically I want to integrate articles into existing pages, something like 
<?php blog::getArticlesHTML($rule); ?>
<?php blog::getUserCommentEditHTML($article); ?>

Can anyone recommend a suitable blog script?


Thanks!
Niels

--- End Message ---

Reply via email to