2 if else语句和2种不同的$类型

时间:2011-12-06 00:47:39

标签: php

基本上我在网站商店工作并遇到问题。网上似乎没有什么我需要弄清楚的。我有第一个if else语句工作正常,第二个没有正常工作。这是编码告诉我什么是错的或我能做些什么不同。

<?php
$adsql = mysql_query("SELECT * FROM store_items WHERE userid='$id2'");
while($adrow = mysql_fetch_array($adsql)){
    $type = $adrow['type'];(this is int)
                               $item = $adrow['id'];
    if ($type == 1) {
        $item1 = "<center>You have bought this already</center>";
    } else {
        $item1 = This is where item1 is bought

            }
    if ($type == 2) {
        $item2 = "<center>You have bought this already</center>";
    } else {
        $item2 = This is where item2 is bought
            </table>
            ";
              }
      }
    ?>

它检索最后一个数字而不是所有数字,而这些数字仅显示if else语句中的1个而不是两个。任何想法都是错的。

1 个答案:

答案 0 :(得分:1)

行:

$item1 = This is where item1 is bought

$item2 = This is where item2 is bought

应该是:

$item1 = "This is where item1 is bought";

$item2 = "This is where item2 is bought";

如果没有引号,语句在语法上是不正确的。