php-general Digest 16 Oct 2012 12:21:51 -0000 Issue 8009

Topics (messages 319468 through 319475):

Re: foreach
        319468 by: Bastien
        319469 by: Jim Lucas
        319470 by: David McGlone

Re: SNMP via PHP
        319471 by: Tom Rogers
        319475 by: Lester Caine

Re: Serving an image
        319472 by: Jan Ehrhardt
        319473 by: viper
        319474 by: marco.behnke.biz

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 ---

Bastien Koert

On 2012-10-15, at 8:16 PM, David McGlone <da...@dmcentral.net> wrote:

> I've been sitting here playing around with foreach() and I'm wondering why I 
> am getting these results. here's what I've been fooling around with. the code 
> has no perticular meaning, but I noticed if the script fails, I get the 
> sentence "Too expensive I'm going home LOL" 6 times because there are 6 words 
> in the sentence. I also have a database that looks like this:
> 
> product_id        product        price
> 1                Milk        2.59
> 2                bread        1.05
> 
> And when $row is equal to 0 the output I get is
> 1 1 Milk Milk 2.59 2.59 Which is printed to the screen according to how many 
> rows are in the db I belive.
> 
> So my question is why this behavior? I was expecting something like a while 
> loop.
> 
> -- 
> David M.
> 

Dave,

Foreach is an iterator over an array. Your $row is a pointer to a db result 
set. If you were to pass the $row result set to the foreach as an array, you'd 
get what you think you should

Www.php.net/foreach

--- End Message ---
--- Begin Message ---
On 10/15/2012 05:16 PM, David McGlone wrote:
I've been sitting here playing around with foreach() and I'm wondering why I
am getting these results. here's what I've been fooling around with. the code
has no perticular meaning, but I noticed if the script fails, I get the
sentence "Too expensive I'm going home LOL" 6 times because there are 6 words
in the sentence. I also have a database that looks like this:

product_id              product         price
1                               Milk            2.59
2                               bread           1.05

And when $row is equal to 0 the output I get is
1 1 Milk Milk 2.59 2.59 Which is printed to the screen according to how many
rows are in the db I belive.

So my question is why this behavior? I was expecting something like a while
loop.


Code please.

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

--- End Message ---
--- Begin Message ---
On Monday, October 15, 2012 08:21:23 PM you wrote:
> Bastien Koert
> 
> On 2012-10-15, at 8:16 PM, David McGlone <da...@dmcentral.net> wrote:
> > I've been sitting here playing around with foreach() and I'm wondering why
> > I am getting these results. here's what I've been fooling around with.
> > the code has no perticular meaning, but I noticed if the script fails, I
> > get the sentence "Too expensive I'm going home LOL" 6 times because there
> > are 6 words in the sentence. I also have a database that looks like this:
> > 
> > product_id        product        price
> > 1                Milk        2.59
> > 2                bread        1.05
> > 
> > And when $row is equal to 0 the output I get is
> > 1 1 Milk Milk 2.59 2.59 Which is printed to the screen according to how
> > many rows are in the db I belive.
> > 
> > So my question is why this behavior? I was expecting something like a
> > while
> > loop.
> 
> Dave,
> 
> Foreach is an iterator over an array. Your $row is a pointer to a db result
> set. If you were to pass the $row result set to the foreach as an array,
> you'd get what you think you should
> 
> Www.php.net/foreach

Thanks Bastien.
Heres what I started with:

$result = mysql_query("SELECT * FROM items");
$row = mysql_fetch_array($result);
foreach($row as $rows){
$row = 0;
if($row == 0){
echo $rows;
} else{
echo "Too expensive I'm going home LOL";
}
}

Here's what I ended up with after you gave me the advise:
$result = mysql_query("SELECT * FROM items");
  $rows = array();
  while($row = mysql_fetch_array($result))
   $rows[] = $row;
  foreach($rows as $row){
  $product = $row['product'];
  $price = $row['price'];
    echo "$product ";
    echo "$price ";
    
    
    $justright = 0;
    $toohigh = 5; //I was going to use this to check if the price was too high 
                                just so I could use an elseif in the exercise, 
but I realized that 
                                it would only work if the if() evaluated to 
false, which would be       
                                impossible. Ahhh pizz on it, it was fun anyway! 
:-)
    
    if($justright <= $price){
     echo "Not bad. I'll buy it.<br />";
      } else
     echo "Too expensive I'm going home LOL ";
       
  }

It's a dumb script that makes no sense but I had a blast doing this. When 
things start coming together like this, it gets so gratifying. :-)

 -- 
David M.


--- End Message ---
--- Begin Message ---
Hello Lester,

Monday, October 15, 2012, 9:09:13 PM, you wrote:

> OK I've spent the last two hours going through pages of crap generated by
> google, and that includes google crap created by searches on sites like
> http://www.phpbuilder.com - cause mainly of cause by php pages on sites
> supporting other languages :(
> Certainly it seems that PHP is preferred even to website java and ruby ...

> I had some problems over the weekend with the network here and decided it was
> time to get some monitoring in place locally. cacti simply loaded up and I 
> have
> working system, but now I'm having trouble getting SNMP sorted on the target
> machines. So I started looking for an editor to handle the MIB data and keep
> hitting one dead end after another.

> I'm sure there must be something out there using php-snmp for a browser?

> -- 
> 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


Did you see this: http://www.php.net/manual/en/book.snmp.php

-- 
Best regards,
 Tom                            mailto:trog...@kwikin.com


--- End Message ---
--- Begin Message ---
Tom Rogers wrote:
Did you see this:http://www.php.net/manual/en/book.snmp.php

Once you know the answer, then the question is easy ...
In order to use your link one has to know how SNMP works and understand things like 'object_id' ...

http://www.jffnms.org/ turned up and is just what I was looking for and can see the devices and report what each is providing. I still need to get cacti to see those devices, but once one has SOMETHING working then things get a lot easier :) The question I should have been asking was "php network monitoring system"

I still need to add monitoring of the domain list and that each domain is being correctly returned, but now I have something I can pull apart and play with and push my own parts back into.

--
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 ---
viper in php.general (Mon, 15 Oct 2012 17:58:06 +0200):
>then in your email you can put:
><img src="http://myurl.com/image.php?id=5"; />

Many receiving e-mail clients will not show external images. External
images are used by spammers to trach if a message is read.

Jan

--- End Message ---
--- Begin Message ---
On Tue, Oct 16, 2012 at 7:40 AM, Jan Ehrhardt <php...@ehrhardt.nl> wrote:
> Many receiving e-mail clients will not show external images. External
> images are used by spammers to trach if a message is read.

true;

you could embed images in email..
http://www.campaignmonitor.com/blog/post/1761/embedding-images-in-email/

so you could use this (or similar) to write the email:
echo '<img 
src="data:image/png;base64,'.base64_encode(file_get_contents('test.png'));.">';

(i don't know if it works :D  )


viper

-- 
+  http://vipertechnology.dyndns.org
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments
+  http://vipertechnology.dyndns.org/cotnact/

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

viper <recursivepoin...@gmail.com> hat am 16. Oktober 2012 um 08:54 geschrieben:
> On Tue, Oct 16, 2012 at 7:40 AM, Jan Ehrhardt <php...@ehrhardt.nl> wrote:
> > Many receiving e-mail clients will not show external images. External
> > images are used by spammers to trach if a message is read.
>
> true;
>
> you could embed images in email..
> http://www.campaignmonitor.com/blog/post/1761/embedding-images-in-email/
>
> so you could use this (or similar) to write the email:
> echo '<img
> src="data:image/png;base64,'.base64_encode(file_get_contents('test.png'));.">';

Actually this is bad practice ... it blows up your code.
Use attachments for that.

>
> (i don't know if it works :D  )
>
>
> viper
>
> --
> +  http://vipertechnology.dyndns.org
> ()  ascii ribbon campaign - against html e-mail
> /\  www.asciiribbon.org   - against proprietary attachments
> +  http://vipertechnology.dyndns.org/cotnact/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

--- End Message ---

Reply via email to