2009-06-12 12 views
0

私は<の場合はうまく動作しますが、私には<の場合は次のエラーが表示されます。ループで奇妙な問題が発生しました

このエラーが発生します。クエリが失敗しました:SQL構文にエラーがあります。あなたのMySQLサーバーのバージョンに対応するマニュアルをチェックして、正しい構文が1行目の 'WHERE 1244790000 - datecreated> = 432000'近くで使用されるようにしてください。実際のクエリ:

そしてここにループがあります。 .Only数ヶ月のためにプログラミングされて、まだOOPを採用していない。[...)// STATUS }

 for($i=0;$i<2;$i++) { 
    $row=mysql_fetch_assoc($displaylistings); 

    // Check to what store this listing belongs to 
    $nordstromtest=mysql_query("SELECT * FROM nordstromlisting WHERE ShopperID = '$ShopperID'"); 
    $nordstromstore=mysql_fetch_assoc($nordstromtest); 
    if ($row == $nordstromstore) { 
     $storename = "Nordstrom Listing: "; 
     $storetbl = "nordstromlisting"; 
    } 

    $saksfifthavenuetest=mysql_query("SELECT * FROM saksfifthavenuelisting WHERE ShopperID = '$ShopperID'"); 
    $saksfifthavenuestore=mysql_fetch_assoc($saksfifthavenuetest); 
    if ($row == $saksfifthavenuestore) { 
     $storename = "Sak's Fifth Avenue Listing: "; 
     $storetbl = "saksfifthavenuelisting"; 
    } 

    $neimanmarcustest=mysql_query("SELECT * FROM neimanmarcuslisting WHERE ShopperID = '$ShopperID'"); 
    $neimanmarcusstore=mysql_fetch_assoc($neimanmarcustest); 
    if ($row == $neimanmarcusstore) { 
     $storename = "Neiman Marcus Listing: "; 
     $storetbl = "neimanmarcuslisting"; 
    } 

    $guesstest=mysql_query("SELECT * FROM guesslisting WHERE ShopperID = '$ShopperID'"); 
    $guessstore=mysql_fetch_assoc($guesstest); 
    if ($row == $guessstore) { 
     $storename = "GUESS Listing: "; 
     $storetbl = "guesslisting"; 
    } 

    $americaneagletest=mysql_query("SELECT * FROM americaneaglelisting WHERE ShopperID = '$ShopperID'"); 
    $americaneaglestore=mysql_fetch_assoc($americaneagletest); 
    if ($row == $americaneaglestore) { 
     $storename = "American Eagle Listing: "; 
     $storetbl = "americaneaglelisting"; 
    } 

    $gnctest=mysql_query("SELECT * FROM gnclisting WHERE ShopperID = '$ShopperID'"); 
    $gncstore=mysql_fetch_assoc($gnctest); 
    if ($row == $gncstore) { 
     $storename = "GNC Listing: "; 
     $storetbl = "gnclisting"; 
    } 

    $footlockertest=mysql_query("SELECT * FROM footlockerlisting WHERE ShopperID = '$ShopperID'"); 
    $footlockerstore=mysql_fetch_assoc($footlockertest); 
    if ($row == $footlockerstore) { 
     $storename = "Foot Locker Listing: "; 
     $storetbl = "footlockerlisting"; 
    } 

    $bananarepublictest=mysql_query("SELECT * FROM bananarepubliclisting WHERE ShopperID = '$ShopperID'"); 
    $bananarepublicstore=mysql_fetch_assoc($bananarepublictest); 
    if ($row == $bananarepublicstore) { 
     $storename = "Banana Republic Listing: "; 
     $storetbl = "bananarepubliclisting"; 
    } 

    $urbanoutfitterstest=mysql_query("SELECT * FROM urbanoutfitterslisting WHERE ShopperID = '$ShopperID'"); 
    $urbanoutfittersstore=mysql_fetch_assoc($urbanoutfitterstest); 
    if ($row == $urbanoutfittersstore) { 
     $storename = "Urban Outfitters Listing: "; 
     $storetbl = "urbanoutfitterslisting"; 
    } 

    //Delete old listings (test with minutes...) 

    $timenow = date("Y-m-d"); 
    $time = strtotime($timenow); 
    $storehistory = str_ireplace("listing","history","$storetbl"); 
    $movetohistory = mysql_query("INSERT INTO $storehistory SELECT * FROM $storetbl WHERE $time - datecreated >= 432000"); 
    $deltefromlisting = mysql_query("DELETE FROM $storetbl WHERE $time - datecreated >= 432000") or die ("Query failed: " . mysql_error() . " Actual query: " . $query); 

    //Item link modifactions 
    if ($row['link'] != null) { 
     $shortlink = substr($row['link'],0,30); 
     $shortlink .= '...'; 
    } 


    if ($row['itemsize'] != null) { 
     $mensshirt = $row['itemsize']; 
    } 

    if ($row['waistsize'] != 0) { 
     $waistsize = $row['waistsize']; 
     $w = 'Waist'; 
    } 

    if ($row['lengthsize'] != 0) { 
     $lengthsize = $row['lengthsize']; 
     $l = 'Length'; 
    } 

    if ($row['ladystopsize'] != null) { 
     $ladystopsize = $row['ladystopsize']; 
    } 

    if ($row['ladysdresssize'] != 0) { 
     $ladysdresssize = $row['ladysdresssize']; 
    } 

    if ($row['ladysbottomsize'] != 0) { 
     $ladysbottomsize = $row['ladysbottomsize']; 
    } 

    if ($row['shoesize'] != 0) { 
     $shoesize = $row['shoesize']; 
    } 

    echo "<div id='listings2'><div id='storenametab'><b><span class='storename'>$storename</span></b></div><br /><br />"; 
    echo "<span id='orderdetails'>Item Number : $row[itemnum] <br />"; 
    echo "Discount Price: $$row[DiscountedPrice] <br />"; 
    echo "Item Type : $row[itemtype]<br />"; 
    echo "Item Size : 
    $mensshirt 
    $waistsize $w 
    $lengthsize $l 
    $ladystopsize 
    $ladysdresssize 
    $ladysbottomsize 
    $shoesize 
    <br />"; 
    echo "Item Color: $row[itemcolor] <br />"; 

    if ($row['link'] != null) { 
    echo "Item URL: <a href='$row[link]' target='_blank'>$shortlink</a><br />"; 
    } 

// STATUS

if ($row['VillainID'] == 0) 
     echo "Status: Unclaimed <br />"; 

    else { 

     $VillainPaypalEmail = mysql_query("SELECT PaypalEmail FROM villains WHERE VillainID = '$row[VillainID]'"); 
     $fetchVillain = mysql_fetch_assoc($VillainPaypalEmail); 
     $VillainPaypal = $fetchVillain['PaypalEmail']; 

     $itemname = "Item Number: $row[itemnum] -- $row[itemtype] -- $mensshirt $waistsize $w $lengthsize $l $ladystopsize $ladysdresssize $ladysbottomsize $shoesize -- $row[itemcolor]"; 
     $discprice = $row['DiscountedPrice']; 
     $state = mysql_query("SELECT state from users WHERE Username = '$username'"); 
     $fetchstate = mysql_fetch_assoc($state); 
     $state = $fetchstate['state']; 

     switch ($storetbl) { 
      case "nordstromlisting": 
       $shipping = 8; 
       if ($state == 'AZ' || 'CA' || 'CO' || 'CT' || 'FL' || 'GA' || 'HI' || 'IA' || 'ID' || 'IL' || 'IN' || 'KS' || 'MA' || 'MD' || 'MN' || 'MO' || 'NC' || 'NJ' || 'NV' || 'NY' || 'OH' || 'PA' || 'RI' || 'SD' || 'TX' || 'UT' || 'VA' || 'WA') { 
        $tax = $discprice * .09; 
       } 
       else { 
        $tax = $discprice * .02; 
       } 
       break; 
      case "saksfifthavenuelisting": 
       switch ($discprice) { 
        case ($discprice <= 25): 
         $shipping = 5; 
         break; 
        case ($discprice > 25 && $discprice <= 50): 
         $shipping = 8; 
         break; 
        case ($discprice > 50 && $discprice <= 100): 
         $shipping = 10; 
         break; 
        case ($discprice > 100 && $discprice <= 200): 
         $shipping = 13; 
         break; 
        case ($discprice > 200 && $discprice <= 300): 
         $shipping = 15; 
         break; 
        case ($discprice > 300 && $discprice <= 500): 
         $shippig = 17; 
         break; 
        case ($discprice > 500): 
         $shipping = 20; 
         break; 
       } 
       if ($state == 'AL' || 'AZ' || 'CA' || 'CO' || 'CT' || 'FL' || 'GA' || 'IL' || 'IN' || 'LA' || 'MA' || 'MD' || 'MN' || 'MO' || 'NC' || 'NJ' || 'NV' || 'NY' || 'OH' || 'OK' || 'PA' || 'SC' || 'TX' || 'VA' || 'DC') { 
        $tax = $discprice * .09; 
       } 
       else { 
        $tax = $discprice * .02; 
       } 
       break; 
      case "neimanmarcuslisting": 
       switch ($discprice) { 
        case ($discprice <= 25): 
         $shipping = 6; 
         break; 
        case ($discprice > 25 && $discprice <= 50): 
         $shipping = 9; 
         break; 
        case ($discprice > 50 && $discprice <= 100): 
         $shipping = 11.50; 
         break; 
        case ($discprice > 100 && $discprice <= 200): 
         $shipping = 16.50; 
         break; 
        case ($discprice > 200 && $discprice <= 300): 
         $shipping = 18.50; 
         break; 
        case ($discprice > 300 && $discprice <= 500): 
         $shippig = 21.50; 
         break; 
        case ($discprice > 500 && $discprice <= 700): 
         $shipping = 25.50; 
         break; 
        case ($discprice > 700 && $discprice <= 1000): 
         $shipping = 29.00; 
         break; 
        case ($discprice > 1000): 
         $shipping = 32.00; 
         break; 
       } 
       if ($state == 'AZ' || 'CA' || 'CO' || 'FL' || 'GA' || 'HI' || 'IL' || 'MA' || 'MD' || 'MI' || 'MN' || 'MO' || 'NC' || 'NJ' || 'NV' || 'NY' || 'PA' || 'TX' || 'VA' || 'WA' || 'DC') { 
        $tax = $discprice * .09; 
       } 
       else { 
        $tax = $discprice * .02; 
       } 
       break; 
      case "urbanoutfitterslisting": 
       switch ($discprice) { 
        case ($discprice <= 50): 
         $shipping = 6; 
         break; 
        case ($discprice > 25 && $discprice < 50): 
         $shipping = 8; 
         break; 
        case ($discprice >= 50 && $discprice < 100): 
         $shipping = 10; 
         break; 
        case ($discprice >= 100 && $discprice < 150): 
         $shipping = 12; 
         break; 
        case ($discprice > 150): 
         $shipping = 0; 
         break; 
       } 
       if ($state == 'AL' || 'AZ' || 'CA' || 'CO' || 'CT' || 'FL' || 'GA' || 'IL' || 'IN' || 'KS' || 'LA' || 'MA' || 'MD' || 'MI' || 'MN' || 'MO' || 'NB' || 'NM' || 'NC' || 'OH' || 'OR' || 'NV' || 'NY' || 'PA' || 'RI' || 'SC' || 'TN' || 'TX' || 'UT' || 'VA' || 'VT' || 'WA' || 'WI' || 'DC') { 
        $tax = $discprice * .09; 
       } 
       else { 
        $tax = $discprice * .02; 
       } 
       break; 
      case "gnclisting": 
       $shipping = 6; 
       break; 
      case "bananarepubliclisting"; 
       $shipping = 7; 
       //call Banana Republic for list of taxable states 
       break; 
      case "guesslisting": 
       $shipping = 7.95; 
       if ($state == 'AZ' || 'CA' || 'CO' || 'CT' || 'FL' || 'GA' || 'HI' || 'IL' || 'IN' || 'KS' || 'LA' || 'MA' || 'MD' || 'MI' || 'MN' || 'MO' || 'NJ' || 'NV' || 'NY' || 'NC' || 'OH' || 'PA' || 'RI' || 'SC' || 'TN' || 'TX' || 'VA' || 'WA') { 
        $tax = $discprice * .09; 
       } 
       else { 
        $tax = $discprice * .02; 
       } 
       break; 
      case "footlockerlisting"; 
       $shipping = 6.99; 
       if ($state == 'AK' || 'DE'|| 'MT' || 'NH' || 'OR') { 
        $tax = $discprice * .02; 
       } 
       else { 
        $tax = $discprice * .09; 
       } 
       break; 
      case "americaneaglelisting": 
       switch($discprice) { 
        case ($discprice < 100): 
        $shipping = 7; 
        break; 
        case ($discprice > 100): 
        $shipping = 0; 
        break; 
       } 
        $tax = $discprice * .09; 
       break; 
     } 

     echo "Status: Claimed!"?> 
     <form action='https://www.paypal.com/cgi-bin/webscr' target='blank' method='post'> 
     <input type='hidden' name='business' value='<?php echo $VillainPaypal ?>'> 
     <input type='hidden' name='cmd' value='_xclick'> 
     <input type='hidden' name='item_name' value="<?php echo $itemname ?>"> 
     <input type='hidden' name='shipping' value="<?php echo $shipping ?>"> 
     <input type='hidden' name='tax' value="<?php echo $tax ?>"> 
     <input type='hidden' name='amount' value='<?php echo $row['DiscountedPrice'] ?>'> 
     <input type='hidden' name='currency_code' value='USD'> 
     <input type='image' name='submit' border='0' 
     src='https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif' 
     alt='PayPal - The safer, easier way to pay online'> 
     <img alt='blahblah' border='0' width='1' height='1' 
     src='https://www.paypal.com/en_US/i/scr/pixel.gif' > 
     </form> 
     <br /> 
     <?php ; 

>を ?"> ">

<?php 

    echo "</span></div>"; 

    $mensshirt = ""; 
    $waistsize = ""; 
    $lengthsize = ""; 
    $ladystopsize = ""; 
    $ladysdresssize = ""; 
    $ladysbottomsize = ""; 
    $shoesize = ""; 
    $storename = ""; 
    $storetbl = ""; 

}

+3

300行以上のコードを投稿しました。少なくとも、あなたに困惑している断片を投稿するだけで試したことを示してください。 –

+1

コードを少し修正してください。すべてのコードを少なくとも4つのスペースでインデントする必要があります。 –

+0

インデックスにコードがまったく使用されていないと、なぜループが必要なのか分かりません。 – Fiur

答えて

1

私の推測では、ループを介して第2の時間で、

の$ storetblのいずれかである、全く何もない、またはテーブル名に設定されていますデータベースには存在しません。

"$時間が$ storetbl。DELETE FROM - datecreated> = 432000" - > = 432000

を決定するために、いくつかのデバッグ文やデバッガを試してみてくださいdatecreatedその後、$時間はどこからDELETE

のようなものと評価されます$ storetblは2回目のループで評価されます。

+0

そうです。あなたの条件が真でない場合、$ storetblは空白になり、SQLクエリは失敗します。 if($ storetbl == "")を続けることをお勧めします。あなたの質問の前に。 –

+0

ループの各パスの最初に$ storetbl/$ storenameを初期化することもできます。そうしないと、前のパスの値はそのまま残ります –

+0

実際には各ループの繰り返しの終わりにそれを行います書式設定 – tschaible

関連する問題