duaijiao0648 2015-09-09 03:18
浏览 36
已采纳

PHP编程错误(无法运行while循环)

<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />

<?php
    session_start();

    $conn = mysqli_connect("localhost", "root", "","test");

    $product_code = $_GET['product_code'];
    $sql = "SELECT * FROM test_config WHERE product_code = '$product_code'";
    $product_list = mysqli_query ( $conn, $sql);

    if($product_list = 1)
    echo"good";
    else
    echo"bad"; 
?>
</head>

<body>

<span id="tttt"></span>
<form id="msform" method="post">
<!-- progressbar -->
<ul id="progressbar">
<li class="active">

<?php While ($one_product = mysqli_fetch_assoc($product_list)) {?>


<li><?php echo $one_product['test_name']; ?></li>

<?php } ?>

<!-- <a href="index.html" >Start-Over</a>  -->
<span onclick="window.close()" style="float:right">Start-Over</span>
</ul>

<?php While ( $one_product = mysqli_fetch_assoc($product_list)  ) { 

        $num_test = $one_product['num_test'];
        $test_name = $one_product['test_name'];
        $images_pos = $one_product['images_pos'];
        $images_neg = $one_product['images_neg'];
        $images_inv = $one_product['images_inv'];
?>
<!-- fieldsets -->
<fieldset id="<?php $test_name; ?>" data-set="0">
<h2 class="fs-title"><?php echo "$test_name"; ?></h2>
<img src="images/<?php $images_pos; ?>"  class="case" data-case="1"/><br/>
<input name="<?php $test_name; ?>" type="radio" value="N" class="hide">
<img src="images/<?php $images_neg; ?>"  class="case" data-case="2"/><br/>
<input name="<?php $test_name; ?>" type="radio" value="P" class="hide">
<img src="images/<?php $images_inv; ?>"  class="case" data-case="3"/><br/>
<input name="<?php $test_name; ?>" type="radio" value="I" class="hide">
<img src="images/skip_button.fw.png"  class="case" data-case="4"/><br/>
<input name="<?php $test_name; ?>" type="radio" value="S" class="hide">
<br/>

<?php if ($num_test > 1) { ?>
<input type="button" name="next" class="next action-button" value="Next" />

<br/>
<?php if($num_test == 1) { ?>

<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="submit" id="submit" class="action-button" value="SAVE" />

</fieldset>
<?php }
$num_test --; ?>
<?php } }?>

</form>

</body>
</html>

Errors: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, integer given on line 41 and line 52 (Line that contain )

Please help me thanks!!!!! The sql does get the data from the database. However, the while loop is still having some errors.

  • 写回答

3条回答 默认 最新

  • doute3621 2015-09-09 06:51
    关注

    if($product_list = 1) echo"good"; else echo"bad";

    Shouldnt be there. As it will make $product_list into boolean and thus cannot run through the loop

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?