0

I have problem with my script

the problem with loop if someone can help me please

Problems:

  1. I am starting loop perfectly without any problem with first loop only.
  2. When result = 0 next loop start it gives me -1 -2 -3 etc in first account only.

and the correct way : when next loop start its add +2 in smtp $server_index++; and start from first without sticky in first account and get minues numbers in same account .

    $server_index = 0;

    while($customer = mysql_fetch_assoc($result)){



    //// Start Server Switch

    $available_server_limit = $servers[$server_index]["per_day_limit"] - getEmailUsage($servers[$server_index]["id"],date("d/m/Y",time()));

    if($available_server_limit==0){

      if($server_index==$servers_count-1){

        //exit(showError("Sorry! We don't have limit to send more emails"));

        mysql_query("UPDATE `smtp_servers` SET `per_day_limit`=`per_day_limit`+2");

        $server_index=0;


      }else{

        $server_index++;

      }

    }
vee
  • 38,255
  • 7
  • 74
  • 78
Adnan
  • 1
  • 2
  • 2
    As a side note, this won't change your problem, but mysql_* is deprecated. It's highly recommended that you switch ASAP, for security and performance reasons: [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Luke Shaheen Aug 02 '13 at 00:57
  • there is no solution ? – Adnan Aug 02 '13 at 01:02
  • can u help me more please? – Adnan Aug 02 '13 at 02:15

1 Answers1

1

It's really difficult to see exactly what you want from only this much info. However, I should point out that you're only going to hit $server_index++; IF $available_server_limit==0

If $available_server_limit does not equal 0, you'll get stuck.

The loop -- by the way -- is in a while statement relying on variables you're not using. May I suggest a foreach, or for statement?

On another note, please do away with mysql_* while you still can. It's depreciated as of recent versions of PHP.

See this for more info

I also notice that you don't show the hole loop. So with that in mind, here's my GUESS at the best way around this for YOU.

$server_index = 0;
foreach( $servers as $key=>$val )
{
    $available_server_limit = $servers[$server_index]["per_day_limit"] - getEmailUsage($servers[$server_index]["id"],date("d/m/Y",time()));
    if($available_server_limit==0)
    {
        if($server_index==$servers_count-1)
        {
            mysql_query("UPDATE `smtp_servers` SET `per_day_limit`=`per_day_limit`+2");
            $server_index=0;
        }
    }
    $server_index++;

Note: I didn't close the foreach loop because your while loop isn't closed. I figure you've got code after this that you're using.

Community
  • 1
  • 1
Izodn
  • 152
  • 8
  • yeah please suggest a foreach, or for statement .. waiting your reply .. thank you. – Adnan Aug 02 '13 at 13:52
  • its not working can you add me skype please basel.atari@hotmail.com – Adnan Aug 02 '13 at 22:08
  • I'm sorry, I don't have the time to teach a new language. Seeing your other posts says to me that you're taking code from someone else, and modding it to your liking. I'll help with corrections, but for the code to be yours, the logic has to come from you. – Izodn Aug 02 '13 at 23:21