OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
php-general Digest 3 Sep 2007 08:30:37 -0000 Issue 4997

php-general-digest-helplists.php.net
Date: Mon Sep 03 2007 - 03:30:37 CDT


php-general Digest 3 Sep 2007 08:30:37 -0000 Issue 4997

Topics (messages 261620 through 261629):

Re: for loop inside a switch
        261620 by: Jonesy
        261628 by: M. Sokolewicz

Re: mail() takes too much time
        261621 by: Gavin M. Roy
        261623 by: brian

Re: Pragmatically changing a "Record Number"
        261622 by: brian
        261625 by: tedd
        261626 by: Chris

Hey Php-generallists.php.net ;)
        261624 by: Jose Ramirez

Re: what is my dns ip address
        261627 by: Olav Mørkrid

Create a matrix gallery
        261629 by: Humani Power

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


On Fri, 31 Aug 2007 22:05:11 -0700, jekillen wrote:

>You can run a switch inside a for loop and when a case is matched set
>a variable to true.
>the break statement will break out of the switch, then inside the
>iteration code, after the switch block, test the variable for true. If
>it is true the use another break instruction.
>That should break out of the loop altogether at the end on that
>particular iteration.

Ahhhh.... The *GoTo* solution. :-)

Jonesy

attached mail follows:


jekillen wrote:
> On Aug 31, 2007, at 6:26 PM, Robert Cummings wrote:
>
>> On Fri, 2007-08-31 at 15:56 -0700, Dan wrote:
>>> Sanjeev is right. You're thinking about the problem backwards. You're
>>> trying to build a Switch inside a loop. Remember, if you ever have
>>> to do
>>> some operating multiple times you're using a forloop, then the thing
>>> that
>>> you want to repeat(switch case) is INSIDE the for loop.
>>
>> Not always true. Sometimes once you've made the switch it applies to all
>> members of a data array. In which case switching on every iteration is a
>> waste of processor since you can check a single time outside the loop.
>>
>> Cheers,
>> Rob.
>> --
>>
> You can run a switch inside a for loop and when a case is matched set a
> variable to true.
> the break statement will break out of the switch, then inside the
> iteration code, after
> the switch block, test the variable for true. If it is true the use
> another break instruction.
> That should break out of the loop altogether at the end on that
> particular iteration.
> like so:
> for($i = 0; $i < somevalue; $i++)
> {
> $bar = false;
> switch($anotherValue[$i]) // /this assumes you are looping through
> an indexed array
> { case 'foo':
> $bar = true
> //other code;
> break;
> default;
> // $bar is not set to true so the loop continues
> }
> if($bar == true)
> {
> break;
> }
> /* instead of the default line in the switch statement
> else
> {
> continue;
> }
> */
> }
>
> Hope this is useful.
> Jeff K

why not just:
for($i = 0; $i < somevalue; $i++)
{
    $bar = false;
    switch($anotherValue[$i]) // /this assumes you are looping through
an indexed array
    {
       case 'foo':
          //other code;
          break(2);

       default;
          // anything really
    }

    // more crap

    continue;
}

attached mail follows:


You might want to consider a few things:

Queueing your email in a database table and sending it out in a
separate process.

or

Finding a mail daemon that will queue quickly for you and not send
directly on adding to the queue.

I use the first of the two options and it works quite well for us.

Gavin

On 9/2/07, shiplu <shiplu.netgmail.com> wrote:
> Hello everybody,
>
> I am maintaining a social network site.
> there each user can send other mail.
> these mails are not real mail rather message entry to database.
> I added a new feature so that every message is sent to me (admin/webmaster)
> via email (real e-mail).
> I used mail function.
> THis is a simple mail function. all it does sends mail with the message as
> the mail body to my address.
> Thats it. no extra complexity.
> But the problem is I got the mail very late. after 4-6 hours. That is huge
> time difference.
> I shouldn't take more than 3-5 mins.
> Do you know the reason?
> my mail code is here,
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> $headers = "MIME-Version: 1.0\r\n";
> $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
> list($myname,$mydomain)=preg_split("/\/",$myemail,2);
> $headers .= "From: $myname <$myemail>\r\n";
> mail("memysite.com", "message from XXX to YYY", $message_content,
> $headers);
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> --
> shout at http://shiplu.awardspace.com/
>
> Available for Hire/Contract/Full Time
>

attached mail follows:


shiplu wrote:
> Hello everybody,
>
> I am maintaining a social network site.
> there each user can send other mail.
> these mails are not real mail rather message entry to database.
> I added a new feature so that every message is sent to me (admin/webmaster)
> via email (real e-mail).
> I used mail function.
> THis is a simple mail function. all it does sends mail with the message as
> the mail body to my address.
> Thats it. no extra complexity.
> But the problem is I got the mail very late. after 4-6 hours. That is huge
> time difference.
> I shouldn't take more than 3-5 mins.
> Do you know the reason?
> my mail code is here,
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> $headers = "MIME-Version: 1.0\r\n";
> $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
> list($myname,$mydomain)=preg_split("/\/",$myemail,2);
> $headers .= "From: $myname <$myemail>\r\n";
> mail("memysite.com", "message from XXX to YYY", $message_content,
> $headers);
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

This might be an issue with your MTA (Sendmail, Postfix, etc.). Have you
tried sending a mail directly (ie. via shell)?

Also, if it's not required that you receive a notice of each post
immediately, perhaps you could instead have some process (on your
computer) check the database periodically. If you go this route and you
have an auto_increment id field, you should save the largest so that
your script only has to retrieve messages with id > last_id.

brian

attached mail follows:


tedd wrote:
> Hi to the original poster:
>
> Snip -- a lot of discussion
>
> Use the following code at your own peril.
>
> $dbQuery = "ALTER TABLE $dbtable ";
> $dbQuery .= "DROP id, ";
> $dbQuery .= "ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT,";
> $dbQuery .= "AUTO_INCREMENT = 1";
> $result = mysql_query($dbQuery) or die("Could not renumber dB $dbQuery"
> . mysql_error());
>
> The reason for not wanting to care about the auto_increment id is that
> it is something that the database uses and really should not be changed.
> If you want to have a sequential record number, then add that field and
> alter it as you will, but leave the internal workings of database alone.
>
> However, if you wish not to understand how all that works, then use the
> code above -- it will renumber your auto_increment id leaving no gaps.
>

At the risk of turning this into a truly marathon thread ...

I don't think altering the id is necessary at all. The solution the OP
seems to be looking for is to (as Graham has said) count off the rows as
they are being printed using a variable. Using a table for clarity:

<?php
$sql = 'SELECT id, title FROM foo';
$result = mysql_query($sql);
$count = 0;
while (++$count && ($row = $result->fethchRow()))
{
?>
  <tr>
   <td>
     row #<?= $count ?>
   </td>
   <td>
     <a href="foo.php?id=<?= $row['id'] ?>"><?= $row['title'] ?></a>
   </td>
  </tr>
<?php
}

It seems that all this is about is displaying a rowcount. The ids can be
anything at all and it'll still look spiffy.

brian

attached mail follows:


At 6:14 PM -0400 9/2/07, brian wrote:
>tedd wrote:
>>Hi to the original poster:
>>
>>Snip -- a lot of discussion
>>
>>Use the following code at your own peril.
>>
>>$dbQuery = "ALTER TABLE $dbtable ";
>>$dbQuery .= "DROP id, ";
>>$dbQuery .= "ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT,";
>>$dbQuery .= "AUTO_INCREMENT = 1";
>>$result = mysql_query($dbQuery) or die("Could not renumber dB
>>$dbQuery" . mysql_error());
>>
>>The reason for not wanting to care about the auto_increment id is
>>that it is something that the database uses and really should not
>>be changed. If you want to have a sequential record number, then
>>add that field and alter it as you will, but leave the internal
>>workings of database alone.
>>
>>However, if you wish not to understand how all that works, then use
>>the code above -- it will renumber your auto_increment id leaving
>>no gaps.
>>
>
>At the risk of turning this into a truly marathon thread ...
>
>I don't think altering the id is necessary at all. The solution the
>OP seems to be looking for is to (as Graham has said) count off the
>rows as they are being printed using a variable. Using a table for
>clarity:
>
><?php
>$sql = 'SELECT id, title FROM foo';
>$result = mysql_query($sql);
>$count = 0;
>while (++$count && ($row = $result->fethchRow()))
>{
>?>
> <tr>
> <td>
> row #<?= $count ?>
> </td>
> <td>
> <a href="foo.php?id=<?= $row['id'] ?>"><?= $row['title'] ?></a>
> </td>
> </tr>
><?php
>}
>
>It seems that all this is about is displaying a rowcount. The ids
>can be anything at all and it'll still look spiffy.
>
>brian

How is that contrary to what I said?

Cheers,

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

attached mail follows:


tedd wrote:
> At 6:14 PM -0400 9/2/07, brian wrote:
>> tedd wrote:
>>> Hi to the original poster:
>>>
>>> Snip -- a lot of discussion
>>>
>>> Use the following code at your own peril.
>>>
>>> $dbQuery = "ALTER TABLE $dbtable ";
>>> $dbQuery .= "DROP id, ";
>>> $dbQuery .= "ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT,";
>>> $dbQuery .= "AUTO_INCREMENT = 1";
>>> $result = mysql_query($dbQuery) or die("Could not renumber dB
>>> $dbQuery" . mysql_error());
>>>
>>> The reason for not wanting to care about the auto_increment id is
>>> that it is something that the database uses and really should not be
>>> changed. If you want to have a sequential record number, then add
>>> that field and alter it as you will, but leave the internal workings
>>> of database alone.
>>>
>>> However, if you wish not to understand how all that works, then use
>>> the code above -- it will renumber your auto_increment id leaving no
>>> gaps.
>>>
>>
>> At the risk of turning this into a truly marathon thread ...
>>
>> I don't think altering the id is necessary at all. The solution the OP
>> seems to be looking for is to (as Graham has said) count off the rows
>> as they are being printed using a variable. Using a table for clarity:
>>
>> <?php
>> $sql = 'SELECT id, title FROM foo';
>> $result = mysql_query($sql);
>> $count = 0;
>> while (++$count && ($row = $result->fethchRow()))
>> {
>> ?>
>> <tr>
>> <td>
>> row #<?= $count ?>
>> </td>
>> <td>
>> <a href="foo.php?id=<?= $row['id'] ?>"><?= $row['title'] ?></a>
>> </td>
>> </tr>
>> <?php
>> }
>>
>> It seems that all this is about is displaying a rowcount. The ids can
>> be anything at all and it'll still look spiffy.
>>
>> brian
>
>
> How is that contrary to what I said?

You are actually changing the id's in the database.

Brian's example is making up an id to display (much like the excel row
numbers) rather than actually changing the id in the database.

--
Postgresql & php tutorials
http://www.designmagick.com/

attached mail follows:


http://www.hi5.com/register/XlneT?inviteId=A_90991ca_0C09xs.2txp151622090

Jose

attached mail follows:


the source of the problem is gethostbyaddr(). it seems to have a 4,5
second timeout, so some lookups time out after 4,5 seconds, while most
of them are resolved in < 0.1 second; a radically performance
difference.

the user written gethostbyaddr_timeout() on the gethostbyaddr man page
overcomes this problem, but unlike gethostbyaddr() requires a specific
dns address, which seems unavailable from php at the moment.

parsing nslookup and similar things seems like a workaround. where
does one propose a dns_ip() function which returns the system's
default dns ip address?

or better yet, to add a timeout value to gethostbyaddr(), or in some
other way ensure that lookups return quickly, whether they have an
answer or not.

attached mail follows:


hi list. I wonder if anyone can help me with this.
i have a database with the file name of several images stored in a
filesystem, and I want to create a table containing the image results of a
query.

this is my code

<?php
include_once("../../../connection/connection.php");
?>
<html>
<head>
<title>Image Gallery</title>
</head>

<table border=1>
    <?php
//get the thumbsnails
$getpic=mysql_query("select * from rsiis_images")
 or die(mysql_error());

     while ($rows=mysql_fetch_assoc($getpic))
     {
      extract ($rows);
      echo "<tr>";
     echo "<td><a href=editing_image.php?pic=".$rows['image_id']."><img
src=".$ImageThumb.$rows['image_id'].".jpg></td>";
       }
?>

</tr>

</table>
</body>
</html>

With this code, I am able to see the thumb images with their respective link
ok, but if I have a query with 40 results, I will have a big row of images.
____________________________________________________

|pic1 | pic2 | pic3 | pic4 | pic5 | pic6 | pic7 | pic8 | pic9 | pic10 |
______________________________________________________

What I want to to do is insert a new <td> after showing 5 thumb images, and
continue with the next picture on the next row.
something like this
__________________________
|pic1 | pic2 | pic3 | pic4 | pic5 |
__________________________
|pic6 | pic7 | pic8 | pic9 | pic10 |
__________________________
|pic11 | pic12 | pic13 |
__________________

Thanks in advance.
Yamil