php-general Digest 14 Dec 2010 10:50:58 -0000 Issue 7086
Topics (messages 310007 through 310021):
Re: array_multisort into Natural order?
310007 by: Jim Lucas
310008 by: George Langley
310021 by: Richard Quadling
Re: Use PHP the way God intended...
310009 by: Daevid Vincent
310016 by: Robert Cummings
310017 by: Paul M Foster
310020 by: David Harkness
Re: empty() in email message
310010 by: Andre Polykanine
310011 by: Daevid Vincent
310013 by: Gary
310014 by: Gary
310015 by: Gary
310018 by: Gary
310019 by: Gary
Re: Scalable Vector Graphics with PHP
310012 by: sudarshana sampath
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 12/13/2010 11:59 AM, George Langley wrote:
> Hi all. Can use natsort($array1) to sort a single array of filenames into a
> "natural "alphanumeric order - 1.php, 2.php, 5.php, 10.php, 20.php, etc.
> But using array_multisort($array1, $array2, $array3) doesn't offer a natsort
> option, so I end up with 1.php, 10.php, 2.php, 20.php, 5.php, etc.
>
> Anyone have a solution to this limitation already? Nothing found in the
> archives or Googling.
> Thanks.
assuming that you are not using other options of array_multisort(), why not do
something like this.
$ar = array_merge($array1, $array2, $array3);
natsort($ar);
>
>
> George Langley Multimedia Developer Audio/Video Editor Musician,
> Arranger, Composer www.georgelangley.ca
>
>
>
--- End Message ---
--- Begin Message ---
Hi there! Correct me if I'm wrong but merge() just makes one array of all
items. array_multisort() keeps each array separate, while applying the same
re-ordering to all three arrays. This allows you to use the same position
number to get the required elements from each array, especially where each
array is a list of different properties. For example:
$name = array("Joe", "Charlie", "Jack");
$age = array(30, 12, 66);
$job = array("Plumber", "Student", "Retired");
array_multisort($name, $age, $job); // will re-order all three arrays based on
a "regular" alphanumeric sort of the names:
// $name is now array("Charlie", "Jack", "Joe");
// $age is now array(12, 66, 30);
// $job is now array("Student", "Retired", "Plumber", );
// can now do:
$firstName = $name[0]; // returns "Charlie"
$firstAge = $age[0]; // returns Charlie's age 12
$firstJob = $job[0]; // returns Charlie's job "Student"
A merge of these arrays will lose the different types of info each array
currently has, and make it impossible to match a name to the age or job.
Now, my other option is to group the items into a set of arrays:
$array1 = array('name' => 'Joe', age => '30' job => 'Plumber');
$array2 = array('name' => 'Charlie', age => '12' job => 'Student');
$array3 = array('name' => 'Jack', age => '66' job => 'Retired');
$largeArray = array($array1, $array2, $array3);
But, is there a way to the sort $largeArray, based on the "name" value in each
individual array? And if so, can that use the natsort()? I don't think an
asort() can do either.
Note that the original source of this info is a mySQL db call, and it is
initially sorted in the query, but again, there doesn't appear to be a way to
natural sort an SQL query either. So I get file1, file10, file2, file20,
file5.... instead of file1, file2, file5, file10, file20....
G
----- Original Message -----
From: Jim Lucas <[email protected]>
Date: Monday, December 13, 2010 16:00
Subject: Re: [PHP] array_multisort into Natural order?
To: George Langley <[email protected]>
Cc: [email protected]
> On 12/13/2010 11:59 AM, George Langley wrote:
> > Hi all. Can use natsort($array1) to sort a single array of
> filenames into a "natural "alphanumeric order - 1.php, 2.php,
> 5.php, 10.php, 20.php, etc.
> > But using array_multisort($array1, $array2, $array3) doesn't
> offer a natsort option, so I end up with 1.php, 10.php, 2.php,
> 20.php, 5.php, etc.
> >
> > Anyone have a solution to this limitation already? Nothing
> found in the archives or Googling.
> > Thanks.
>
> assuming that you are not using other options of
> array_multisort(), why not do
> something like this.
>
> $ar = array_merge($array1, $array2, $array3);
> natsort($ar);
>
> >
> >
> > George Langley Multimedia
> Developer Audio/Video Editor
> Musician, Arranger, Composer www.georgelangley.ca
> >
> >
> >
>
>
>
George Langley Multimedia Developer Audio/Video Editor Musician,
Arranger, Composer www.georgelangley.ca
--- End Message ---
--- Begin Message ---
On 13 December 2010 19:59, George Langley <[email protected]> wrote:
> Hi all. Can use natsort($array1) to sort a single array of filenames into a
> "natural "alphanumeric order - 1.php, 2.php, 5.php, 10.php, 20.php, etc.
> But using array_multisort($array1, $array2, $array3) doesn't offer a natsort
> option, so I end up with 1.php, 10.php, 2.php, 20.php, 5.php, etc.
>
> Anyone have a solution to this limitation already? Nothing found in the
> archives or Googling.
> Thanks.
>
>
> George Langley Multimedia Developer Audio/Video Editor Musician,
> Arranger, Composer www.georgelangley.ca
>
>
>
Based upon code I found at [1] I have the following function [2] which
I use to sort result sets. I've just added natural sorting (and
natural caseless sorting) and some examples on usage.
It might be slightly over the top, but it works well for me. No need
to extract the columns from the rows to supply to the sorter.
If you like it and find any issues with it, or enhancements, then I'd
be grateful if you could pass them back to me.
Richard.
[1] http://www.php.net/manual/en/function.array-multisort.php#68452
[2] http://pastebin.com/8JsMX7yS
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Robert Cummings [mailto:[email protected]]
> Sent: Friday, December 10, 2010 6:54 AM
> To: Daevid Vincent
> Cc: [email protected]
> Subject: Re: [PHP] ORM doctrine
>
> On 10-12-09 10:41 PM, Daevid Vincent wrote:
> > Use PHP the way God intended it to be used.
>
> Could you cite a reference for where God states his intentions on PHP?
>
> Thanks,
> Rob.
I believe it was in the Old PHPestament,
"The Book of Rasmus" chapter 42 verse 69...
66 ...
67 And behold as he opened the 5th point 2nd seal
68 and the Lord said unto him,
69 "Thou shalt not use frameworks,
70 for they art cumbersome
71 and a bastardization of mine own language"
72 ...
It goes on to talk about using "<?=" instead of "<?php echo"
And how you should always put the closing "?>" on the page bottom,
But I digress...
ROFL! :D
--- End Message ---
--- Begin Message ---
On 10-12-13 07:28 PM, Daevid Vincent wrote:
-----Original Message-----
From: Robert Cummings [mailto:[email protected]]
Sent: Friday, December 10, 2010 6:54 AM
To: Daevid Vincent
Cc: [email protected]
Subject: Re: [PHP] ORM doctrine
On 10-12-09 10:41 PM, Daevid Vincent wrote:
Use PHP the way God intended it to be used.
Could you cite a reference for where God states his intentions on PHP?
Thanks,
Rob.
I believe it was in the Old PHPestament,
"The Book of Rasmus" chapter 42 verse 69...
66 ...
67 And behold as he opened the 5th point 2nd seal
68 and the Lord said unto him,
69 "Thou shalt not use frameworks,
70 for they art cumbersome
71 and a bastardization of mine own language"
72 ...
It goes on to talk about using "<?=" instead of "<?php echo"
And how you should always put the closing "?>" on the page bottom,
But I digress...
ROFL! :D
*heheh* I think you've been reading it backwards ;)
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
On Mon, Dec 13, 2010 at 11:04:52PM -0500, Robert Cummings wrote:
> On 10-12-13 07:28 PM, Daevid Vincent wrote:
> >
> >
[snip]
> >
> >I believe it was in the Old PHPestament,
> >"The Book of Rasmus" chapter 42 verse 69...
> >
> >66 ...
> >67 And behold as he opened the 5th point 2nd seal
> >68 and the Lord said unto him,
> >69 "Thou shalt not use frameworks,
> >70 for they art cumbersome
> >71 and a bastardization of mine own language"
> >72 ...
> >
> >It goes on to talk about using "<?=" instead of "<?php echo"
> >And how you should always put the closing "?>" on the page bottom,
> >But I digress...
> >
> >ROFL! :D
>
> *heheh* I think you've been reading it backwards ;)
Nah, if he'd read it backwards, you'd be able to hear MePHPistoPHPeles
say, "Rasmus is the Penguin".
(Yes, you have to be dang old to get that obscure reference. ;-)
Paul
--
Paul M. Foster
--- End Message ---
--- Begin Message ---
On Mon, Dec 13, 2010 at 8:48 PM, Paul M Foster <[email protected]>wrote:
> Nah, if he'd read it backwards, you'd be able to hear MePHPistoPHPeles
> say, "Rasmus is the Penguin".
>
> (Yes, you have to be dang old to get that obscure reference. ;-)
>
Pshaw, not *that* old! I get the reference, and I'm only . . . oh, damn. :(
David
--- End Message ---
--- Begin Message ---
Hello Gary,
Try using this:
if (!empty($beefolives)) $msg.="Order: beef olives";
or:
$msg.=empty($beefolives)? "": "Order: beef olives";
--
With best regards from Ukraine,
Andre
Skype: Francophile
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion
----- Original message -----
From: Gary <[email protected]>
To: [email protected] <[email protected]>
Date: Monday, December 13, 2010, 7:47:49 PM
Subject: [PHP] empty() in email message
I have an email message
$msg = 'Name: $fname ' . ' $lname\n'
. "Phone: $phone\n"
. "Email: $email\n"
and it works fine, however in this message there are about 30 variables that
are being called...as such
. "Order: beefschnitzel $beefschnitzel\n"
. "Order: beefstrips $beefstrips\n"
. "Order: cheesesausage $cheesesausage\n"
. "Order: crumbedsausage $crumbedsausage\n"
. "Order: chucksteak $chucksteak\n"
. "Order: cornedbeef $cornedbeef\n"
. "Order: dicedsteak $dicedsteak\n"
. "Order: filletmignon $filletmignon\n"
I want to only send the message if the submitter enters an amount in the
form for the corresponding variable, instead of having a bunch of empty
messages. So I have been trying to use the empty() function as such:
. if empty($beefolives){''} elseif (isset($beefolives)) { 'Order: beefolives
$beefolives\n'}
But I am getting the error
Parse error: syntax error, unexpected T_IF
Can someone point me in the right direction?
Thank you
--
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5699 (20101213) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
> ----- Original message -----
> From: Gary <[email protected]>
> To: [email protected] <[email protected]>
> Date: Monday, December 13, 2010, 7:47:49 PM
> Subject: [PHP] empty() in email message
>
> I have an email message
>
> $msg = 'Name: $fname ' . ' $lname\n'
> . "Phone: $phone\n"
> . "Email: $email\n"
>
> and it works fine, however in this message there are about 30
> variables that
> are being called...as such
>
> . "Order: beefschnitzel $beefschnitzel\n"
> . "Order: beefstrips $beefstrips\n"
> . "Order: cheesesausage $cheesesausage\n"
> . "Order: crumbedsausage $crumbedsausage\n"
> . "Order: chucksteak $chucksteak\n"
> . "Order: cornedbeef $cornedbeef\n"
> . "Order: dicedsteak $dicedsteak\n"
> . "Order: filletmignon $filletmignon\n"
>
> I want to only send the message if the submitter enters an
> amount in the
> form for the corresponding variable, instead of having a
> bunch of empty
> messages. So I have been trying to use the empty() function as such:
>
> . if empty($beefolives){''} elseif (isset($beefolives)) {
> 'Order: beefolives
> $beefolives\n'}
You are setting this up fundamentally wrong.
You should be using an array and looping through it.
Something like:
$myorder['cowface'] = 1;
$myorder['beefenweiner'] = 2;
$myorder['chucksteak'] = 1;
foreach ($myorder as $item => $quantity)
{
echo "Order: $item x $quantity\n";
}
Then your array only contains the items someone actually puchased and how
many.
d
--- End Message ---
--- Begin Message ---
"Bastien Koert" <[email protected]> wrote in message
news:[email protected]...
On Mon, Dec 13, 2010 at 12:47 PM, Gary <[email protected]> wrote:
> I have an email message
>
> $msg = 'Name: $fname ' . ' $lname\n'
> . "Phone: $phone\n"
> . "Email: $email\n"
>
> and it works fine, however in this message there are about 30 variables
> that
> are being called...as such
>
> . "Order: beefschnitzel $beefschnitzel\n"
> . "Order: beefstrips $beefstrips\n"
> . "Order: cheesesausage $cheesesausage\n"
> . "Order: crumbedsausage $crumbedsausage\n"
> . "Order: chucksteak $chucksteak\n"
> . "Order: cornedbeef $cornedbeef\n"
> . "Order: dicedsteak $dicedsteak\n"
> . "Order: filletmignon $filletmignon\n"
>
> I want to only send the message if the submitter enters an amount in the
> form for the corresponding variable, instead of having a bunch of empty
> messages. So I have been trying to use the empty() function as such:
>
> . if empty($beefolives){''} elseif (isset($beefolives)) { 'Order:
> beefolives
> $beefolives\n'}
>
> But I am getting the error
>
> Parse error: syntax error, unexpected T_IF
>
> Can someone point me in the right direction?
>
> Thank you
> --
> Gary
>
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 5699 (20101213) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Less complication is better, reduce the code to the below. The empty
portion needs to be inside the parentheses. Also double quotes are
needed to make the vairable parse correctly into the value you want to
see
if (!empty($beefolives)) { echo "Order: beefolives $beefolives\n";}
--
Bastien
Bastien
Thank you for your response, and I agree, I like simpler. Your script
however did not work in the email message, it did work in another section
where I echo to screen the information to the screen.
Does the echo command work in emails?
Thank you again.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5700 (20101213) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
"Paul M Foster" <[email protected]> wrote in message
news:[email protected]...
> On Mon, Dec 13, 2010 at 12:47:49PM -0500, Gary wrote:
>
>> I have an email message
>>
>> $msg = 'Name: $fname ' . ' $lname\n'
>> . "Phone: $phone\n"
>> . "Email: $email\n"
>>
>> and it works fine, however in this message there are about 30 variables
>> that
>> are being called...as such
>>
>> . "Order: beefschnitzel $beefschnitzel\n"
>> . "Order: beefstrips $beefstrips\n"
>> . "Order: cheesesausage $cheesesausage\n"
>> . "Order: crumbedsausage $crumbedsausage\n"
>> . "Order: chucksteak $chucksteak\n"
>> . "Order: cornedbeef $cornedbeef\n"
>> . "Order: dicedsteak $dicedsteak\n"
>> . "Order: filletmignon $filletmignon\n"
>>
>> I want to only send the message if the submitter enters an amount in the
>> form for the corresponding variable, instead of having a bunch of empty
>> messages. So I have been trying to use the empty() function as such:
>>
>> . if empty($beefolives){''} elseif (isset($beefolives)) { 'Order:
>> beefolives
>> $beefolives\n'}
>>
>> But I am getting the error
>>
>> Parse error: syntax error, unexpected T_IF
>>
>> Can someone point me in the right direction?
>
> It looks like you're trying to do something like:
>
> $str = 'something' .
> if ($somethingelse)
> 'another string'
> else
> 'a different string';
>
> For one thing, you can't put a conditional on the right side of a
> concatenation mark (.). You'd have to do it this way:
>
> $str = 'something';
> if ($somethingelse) {
> $str .= 'another string';
> }
> else {
> $str .= 'a different string';
> }
>
> You also can't do:
>
> elseif (isset($beefolives)) {
> 'Order: beefolives $beefolives\n';
> }
>
> For one thing, surrounding the 'Order...' line with single quotes will
> cause the \n *not* to be interpreted as a newline. Second, your 'Order:
> beefolives...' does nothing. You haven't assigned it to anything or
> operated on that string in any way.
>
> You might want to study up on single versus double quotes, the
> concatenation operator (.), etc.
>
> Paul
>
> --
> Paul M. Foster
>
Paul
Thank you for your reponse. I will admit I get a little fuzzy on the single
v double quotation marks, generally the rule I go by is if it is a string, I
use singles, if any processing I use doubles. I am not recalling why did it
that way, perhaps I had doubles and it did not work so I was whittling down
the options....
Thank you again for your help.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5700 (20101213) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
""Daniel P. Brown"" <[email protected]> wrote in message
news:[email protected]...
On Mon, Dec 13, 2010 at 12:47, Gary <[email protected]> wrote:
> I have an email message
>
> $msg = 'Name: $fname ' . ' $lname\n'
> . "Phone: $phone\n"
> . "Email: $email\n"
>
> and it works fine, however in this message there are about 30 variables
> that
> are being called...as such
>
> . "Order: beefschnitzel $beefschnitzel\n"
> . "Order: beefstrips $beefstrips\n"
> . "Order: cheesesausage $cheesesausage\n"
> . "Order: crumbedsausage $crumbedsausage\n"
> . "Order: chucksteak $chucksteak\n"
> . "Order: cornedbeef $cornedbeef\n"
> . "Order: dicedsteak $dicedsteak\n"
> . "Order: filletmignon $filletmignon\n"
>
> I want to only send the message if the submitter enters an amount in the
> form for the corresponding variable, instead of having a bunch of empty
> messages. So I have been trying to use the empty() function as such:
>
> . if empty($beefolives){''} elseif (isset($beefolives)) { 'Order:
> beefolives
> $beefolives\n'}
>
> But I am getting the error
>
> Parse error: syntax error, unexpected T_IF
>
> Can someone point me in the right direction?
That's because you're concatenating. When appending to a
variable, you can't use constructs and conditions, unless using
ternaries:
. (!empty($beefolives) && is_numeric($beefolives) ? 'Order: beefolives
'.$beefolives : null)
However, for readability and ease of management, you might want to
try something like this. It makes at least two assumptions: you're
using a form post, and you understand that it's untested (as I'm just
typing it here into the body of this email).
<?php
// If we've posted our order
if (isset($_POST) && is_array($_POST['order'])) {
// Instantiate the $order variable
$order = null;
// Iterate the order quantities
foreach ($_POST['order'] as $k => $v) {
// If the field is set and the amount is a number
if (isset($v) && is_numeric($v)) {
$order .= 'Order: '.$k.': '.$v.PHP_EOL;
}
}
/**
* Note: in your example, you used single (literal)
* quotes and included the variables. That would
* literally print $fname and $lname.
*/
$msg = 'Name: '.$_POST['fname'].' '.$_POST['lname'].PHP_EOL;
$msg .= 'Phone: '.$_POST['phone'].PHP_EOL;
$msg .= 'Email: '.$_POST['email'].PHP_EOL;
$msg .= PHP_EOL;
$msg .= $order;
// And then handle the rest of your processing. Here, we just echo.
echo '<pre>'.PHP_EOL.$msg.'</pre>'.PHP_EOL;
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
First Name: <input type="text" name="fname" id="fname"><br/>
Last Name: <input type="text" name="lname" id="lname"><br/>
Phone: <input type="text" name="phone" id="phone"><br/>
Email: <input type="text" name="email" id="email"><br/>
<br />
<h3>Order</h3>
Beef Schnitzel: <input type="text" name="order[beefschnitzel]"
id="order[beefschnitzel]" size="2" maxlength="3"><br/>
Beef Strips: <input type="text" name="order[beefstrips]"
id="order[beefstrips]" size="2" maxlength="3"><br/>
Cheese Sausage: <input type="text" name="order[cheesesausage]"
id="order[cheesesausage]" size="2" maxlength="3"><br/>
Crumbed Sausage: <input type="text" name="order[crumbedsausage]"
id="order[crumbedsausage]" size="2" maxlength="3"><br/>
Chuck Steak: <input type="text" name="order[chucksteak]"
id="order[chucksteak]" size="2" maxlength="3"><br/>
Corned Beef: <input type="text" name="order[cornedbeef]"
id="order[cornedbeef]" size="2" maxlength="3"><br/>
Diced Steak: <input type="text" name="order[dicedsteak]"
id="order[dicedsteak]" size="2" maxlength="3"><br/>
Filet Mignon: <input type="text" name="order[filletmignon]"
id="order[filletmignon]" size="2" maxlength="3"><br/>
<!-- NOTE: "Filet" as displayed on the form has one 'L', but the
variable is unchanged. -->
<br />
<input type="submit" value="Order Now">
</form>
--
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/
Daniel
As always, thank you for your input. I had tried your first script, and it
worked to a degree. What I was getting was a message that was correct, but,
well, this is what it looked like in an email
Order: beefschnitzel
10Order:
Which was supposed to look like
Order: beefschnitzel 10
Order:
I have not tried your second suggestion yet, I'll let you know how that
works.
Again, thank you for your help.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5700 (20101213) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
"Andre Polykanine" <[email protected]> wrote in message
news:[email protected]...
> Hello Gary,
>
> Try using this:
> if (!empty($beefolives)) $msg.="Order: beef olives";
> or:
> $msg.=empty($beefolives)? "": "Order: beef olives";
>
> --
> With best regards from Ukraine,
> Andre
> Skype: Francophile
> Twitter: http://twitter.com/m_elensule
> Facebook: http://facebook.com/menelion
>
> ----- Original message -----
> From: Gary <[email protected]>
> To: [email protected] <[email protected]>
> Date: Monday, December 13, 2010, 7:47:49 PM
> Subject: [PHP] empty() in email message
>
> I have an email message
>
> $msg = 'Name: $fname ' . ' $lname\n'
> . "Phone: $phone\n"
> . "Email: $email\n"
>
> and it works fine, however in this message there are about 30 variables
> that
> are being called...as such
>
> . "Order: beefschnitzel $beefschnitzel\n"
> . "Order: beefstrips $beefstrips\n"
> . "Order: cheesesausage $cheesesausage\n"
> . "Order: crumbedsausage $crumbedsausage\n"
> . "Order: chucksteak $chucksteak\n"
> . "Order: cornedbeef $cornedbeef\n"
> . "Order: dicedsteak $dicedsteak\n"
> . "Order: filletmignon $filletmignon\n"
>
> I want to only send the message if the submitter enters an amount in the
> form for the corresponding variable, instead of having a bunch of empty
> messages. So I have been trying to use the empty() function as such:
>
> . if empty($beefolives){''} elseif (isset($beefolives)) { 'Order:
> beefolives
> $beefolives\n'}
>
> But I am getting the error
>
> Parse error: syntax error, unexpected T_IF
>
> Can someone point me in the right direction?
>
> Thank you
> --
> Gary
>
>
Andre
That looks good, I will give that a try in the morning, thank you for your
help.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5700 (20101213) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
""Daevid Vincent"" <[email protected]> wrote in message
news:[email protected]...
>> ----- Original message -----
>> From: Gary <[email protected]>
>> To: [email protected] <[email protected]>
>> Date: Monday, December 13, 2010, 7:47:49 PM
>> Subject: [PHP] empty() in email message
>>
>> I have an email message
>>
>> $msg = 'Name: $fname ' . ' $lname\n'
>> . "Phone: $phone\n"
>> . "Email: $email\n"
>>
>> and it works fine, however in this message there are about 30
>> variables that
>> are being called...as such
>>
>> . "Order: beefschnitzel $beefschnitzel\n"
>> . "Order: beefstrips $beefstrips\n"
>> . "Order: cheesesausage $cheesesausage\n"
>> . "Order: crumbedsausage $crumbedsausage\n"
>> . "Order: chucksteak $chucksteak\n"
>> . "Order: cornedbeef $cornedbeef\n"
>> . "Order: dicedsteak $dicedsteak\n"
>> . "Order: filletmignon $filletmignon\n"
>>
>> I want to only send the message if the submitter enters an
>> amount in the
>> form for the corresponding variable, instead of having a
>> bunch of empty
>> messages. So I have been trying to use the empty() function as such:
>>
>> . if empty($beefolives){''} elseif (isset($beefolives)) {
>> 'Order: beefolives
>> $beefolives\n'}
>
> You are setting this up fundamentally wrong.
>
> You should be using an array and looping through it.
>
> Something like:
>
> $myorder['cowface'] = 1;
> $myorder['beefenweiner'] = 2;
> $myorder['chucksteak'] = 1;
>
> foreach ($myorder as $item => $quantity)
> {
> echo "Order: $item x $quantity\n";
> }
>
> Then your array only contains the items someone actually puchased and how
> many.
>
> d
>
Daevid
I knew someone was going to point out this was a convoluted method, and I
agree. This was sent to me by someone that needed to make the mail form
work. My suggestion was to look into a pre-made shopping cart, however that
was not going to work for them, so I made the mail() work for them.
I had thought about putting it into an array, but had not gotten that far
into it. I will look over the code to see how it works.
Thank you for your help.
gary
__________ Information from ESET Smart Security, version of virus signature
database 5700 (20101213) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
Nathan Nobbe, Thank you very much for your response,
Protovis is looking interesting...
graphviz also a good one.
http://pear.php.net/package-info.php?package=Image_Graphviz
On Mon, Dec 13, 2010 at 2:39 PM, Nathan Rixham <[email protected]> wrote:
> disclaimer: a different nathan
>
> You may also be interested in protovis, and raphael, both of which are js
> libraries which make, or export, svg graphics :)
>
> Best,
>
> Nathan
>
>
> sudarshana sampath wrote:
>
>> Nathan, Thank you very much for your response, we are going to visualize
>> network management system(topolgy view) with SVG and AJAX.
>>
>> We found a jQuery plugin, following are urls.
>>
>> http://plugins.jquery.com/project/svg
>> http://keith-wood.name/svg.html
>>
>>
>>
>> On Thu, Dec 9, 2010 at 10:50 PM, Nathan Nobbe <[email protected]
>> >wrote:
>>
>> On Thu, Dec 9, 2010 at 4:55 AM, sudarshana sampath <
>>> [email protected]> wrote:
>>>
>>> Hi,
>>>>
>>>> We are going add a topology view to our Network Management System.
>>>> Our Network Management System is based on PHP, CakePHP, jQuery and other
>>>> web
>>>> related tools(middle tier written using C++).
>>>>
>>>> So we are going to work with Scalable Vector Graphics.
>>>>
>>>> We are looking for the best solution for doing that.
>>>>
>>>> Are there any extensions, plugins, frameworks available for SVG related
>>>> things ?
>>>>
>>>> not sure exactly what youre trying to accomplish, but obviously you
>>> could
>>> use any number of vector programs over the cli from php.
>>>
>>> you might also have a peak at the cairo library which php allegedly
>>> supports (ive never tried it myself).
>>>
>>> http://us.php.net/manual/en/intro.cairo.php
>>>
>>> -nathan
>>>
>>>
>>
>>
>>
>
--
Cheers,
Sudarshana Sampath.
--- End Message ---