没有收到mysql查询的结果

时间:2012-01-09 14:25:19

标签: php mysql

我的脚本下面有一些问题,我收到以下警告,我认为这意味着查询结果为空?但问题是,如果我在MySQL控制台中运行代码查询本身,我会得到结果吗?

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go    \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :     eval()'d code on line 53

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go    \server2go\htdocs\chandlers\components\com_jumi\views\application \view.html.php(38) :    eval()'d code on line 93

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go    \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :     eval()'d code on line 134

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go    \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :     eval()'d code on line 177

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go    \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :     eval()'d code on line 218

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go    \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :     eval()'d code on line 259




    <?php                 
        // SETS THE TIMEZONE TO UK TIME
        date_default_timezone_set('Europe/London');

        // DEFINES WEEKDAY AND DAY OF THE MONTH
        $weekday = date('D');
        $dayOfMonth = date('d');

        // RUNS THE EVERY DAY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY DAY
        gasoildailyemailer();
        dervdailyemailer();
        kerodailyemailer();
        if ($weekday == 'Mon')
        {

        // RUNS THE WEEKLY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY WEEK
         gasoilweeklyemailer();
         dervweeklyemailer();
         keroweeklyemailer();
        if ($dayOfMonth <=6) {

        // RUNS THE MONTHLY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY MONTH
        gasoilmonthlyemailer();
        dervmonthlyemailer();
        keromonthlyemailer(); }
        }

        ?>


    <?php
    //start of gas oil daily emailer
    function gasoildailyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test";

    $gasoil_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'") or die(mysql_error());
    $result = @MYSQL_QUERY($gasoil_daily_users);

    while ($row = mysql_fetch_array ($result)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    ?>    

    <?php
    // START OF DERV DAILY EMAILER
    function dervdailyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test";

    $derv_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivedervmailinglist = 'everyday'") or die(mysql_error());
    $result1 = @MYSQL_QUERY($derv_daily_users);

    while ($row = mysql_fetch_array ($result1)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    // end of DERV daily emailer
    ?>    

    <?php
    //start of KERO daily emailer
    function kerodailyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test";

    $kero_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivekeromailinglist = 'everyday'") or die(mysql_error());
    $result2 = @MYSQL_QUERY($kero_daily_users);

    while ($row = mysql_fetch_array ($result2)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    // end of KERO daily emailer
    ?>    



    <?php
    // start of GAS OIL WEEKLY emailer
    function gasoilweeklyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test Weekly";

    $gasoil_every_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everymonday'") or die(mysql_error());
    $result3 = @MYSQL_QUERY($gasoil_every_mon_users);

    while ($row = mysql_fetch_array ($result3)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    //end of GAS OIL WEEKLY emailer
    ?>    

    <?php
    // START OF DERV WEEKLY EMAILER
    function dervweeklyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test Weekly";

    $derv_every_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivedervmailinglist = 'everymonday'") or die(mysql_error());
    $result4 = @MYSQL_QUERY($derv_every_mon_users);

    while ($row = mysql_fetch_array ($result4)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    // END OF DERV WEEKLY EMAILER
    ?>    

    <?php
    // START OF KERO WEEKLY EMAILER
    function keroweeklyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test Weekly";

    $kero_every_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivekeromailinglist = 'everymonday'") or die(mysql_error());
    $result5 = @MYSQL_QUERY($kero_every_mon_users);

    while ($row = mysql_fetch_array ($result5)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    // END OF KERO WEEKLY EMAILER
    ?>    



    <?php
    // START OF GAS OIL MONTHLY EMAILER
    function gasoilmonthlyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test monthly";

    $gasoil_1st_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'firstmondayofthemonth'") or die(mysql_error());
    $result6 = @MYSQL_QUERY($gasoil_1st_mon_users);

    while ($row = mysql_fetch_array ($result6)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    // END OF GAS OIL MONTHLY EMAILER
    ?>    

    <?php
    //START OF DERV MONTHLY EMAILER
    function dervmonthlyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test monthly";

    $derv_1st_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivedervmailinglist = 'firstmondayofthemonth'") or die(mysql_error());
    $result7 = @MYSQL_QUERY($derv_1st_mon_users);

    while ($row = mysql_fetch_array ($result7)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    //END OF DERV MONTHLY EMAILER
    ?>    

    <?php
    // START OF KERO MONTHLY EMAILER
    function keromonthlyemailer(){
    require_once('./send/class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

    // $body                = file_get_contents('contents.html');

    $body = 'Dear Test this is a test.';

    // $body = preg_replace('/\\\\/i', $body);

    $mail->SetFrom('crea@cruiseit.co.uk', 'List manager');
    $mail->AddReplyTo('crea@cruiseit.co.uk', 'List manager');

    $mail->Subject       = "Mailing List Test monthly";

    $kero_1st_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivekeromailinglist = 'firstmondayofthemonth'") or die(mysql_error());
    $result8 = @MYSQL_QUERY($kero_1st_mon_users);

    while ($row = mysql_fetch_array ($result8)) {
      $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
      $mail->MsgHTML($body);
      $mail->AddAddress($row["email"], $row["leadname"]);
      $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

      if(!$mail->Send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
      } else {
        echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
      }
      // Clear all addresses and attachments for next loop
      $mail->ClearAddresses();
      $mail->ClearAttachments();
    }
    };
    //END OF KERO MONTHLY EMAILER
    ?>    

2 个答案:

答案 0 :(得分:1)

mysql_query mysql_query

$gasoil_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'") or die(mysql_error());
$result = @MYSQL_QUERY($gasoil_daily_users);

如果删除第二行,或将$gasoil_daily_users更改为查询字符串:

$gasoil_daily_users = "SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'";
$result = mysql_query($gasoil_daily_users) or die(mysql_error());

您的代码应该可以正常运行。

答案 1 :(得分:0)

你做错了 - 而不是:

$gasoil_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'") or die(mysql_error());
$result = @MYSQL_QUERY($gasoil_daily_users);
while ($row = mysql_fetch_array ($result))
...

应该是:

$result = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'") or die(mysql_error());
while ($row = mysql_fetch_array ($result)) {
...

无需再次查询查询;)