duanhuan8983
duanhuan8983
2014-06-27 09:25
浏览 35

html中的PHP代码无法正常工作

I want to use this code to get results from my database and show it in html but this is not happening. Getting all weird results and am not able to fix it.

it display } ? > on my webpage at the end wonder why.And i cannot get any results from my database displayed either.

Database is proper I believe some error in html and php code(php variables in html tags).

<?php  
while($row = mysqli_fetch_array($result)) {

$price = ($row['ISBN']%1000);
echo $price;
<li>
        <div class="book-display-bg">
            <div class="book-display-placeholder">
                <div class="book-display-container">
                    <div class="book-display-centered">
                        <a href='product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html'  >
                            <img src=''$row['Image_URL_M']'' style='border: 0;' alt=''$row['Book_Title']''/>
                        </a>
                    </div>
                </div>
            </div>
        </div>    
        <div class="book-display-details">
            <div class="book-display-title"><p><a href='product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html'  title=''$row['Book_Title']'' >$row['Book_Title']</a></p></div>
            <div class="book-display-author"><p>$row['Book_Author']</p></div>
            <div id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_divStock" class="book-display-stock"></div>
            <div class="book-display-price">$price</div>
            <input type="submit" name="ctl00$ctl00$CMSContentMasterPlaceHolder$cphContent1$ctl01$ProductSummary1$DataList1$ctl02$btnBuyNow" value="add to basket" id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_btnBuyNow" title="add to basket" class="ecom-add-basket" />
        </div>        
        <div class="clear"></div>
    </li>
}
?>

Thanks in advance

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongxun4110
    dongxun4110 2014-06-27 09:35
    已采纳

    You forget to add echo for the li element. You can try following:

    <?php  
    while($row = mysqli_fetch_array($result)) {
    
    $price = ($row['ISBN']%1000);
    echo $price; ?>
    <li>
            <div class="book-display-bg">
                <div class="book-display-placeholder">
                    <div class="book-display-container">
                        <div class="book-display-centered">
                            <a href='product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html'  >
                                <img src='<?php echo $row['Image_URL_M']; ?>' style='border: 0;' alt='<?php echo $row['Book_Title']; ?>'/>
                            </a>
                        </div>
                    </div>
                </div>
            </div>    
            <div class="book-display-details">
                <div class="book-display-title"><p><a href='product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html'  title='<?php echo $row['Book_Title']; ?>' ><?php echo $row['Book_Title']; ?></a></p></div>
                <div class="book-display-author"><p><?php echo $row['Book_Author']; ?></p></div>
                <div id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_divStock" class="book-display-stock"></div>
                <div class="book-display-price"><?php echo $price; ?></div>
                <input type="submit" name="ctl00$ctl00$CMSContentMasterPlaceHolder$cphContent1$ctl01$ProductSummary1$DataList1$ctl02$btnBuyNow" value="add to basket" id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_btnBuyNow" title="add to basket" class="ecom-add-basket" />
            </div>        
            <div class="clear"></div>
        </li><?php
    }
    ?>
    

    or You can do it this way:

    <?php  
    while($row = mysqli_fetch_array($result)) {
    
    $price = ($row['ISBN']%1000);
    echo $price;
    echo '<li>
            <div class="book-display-bg">
                <div class="book-display-placeholder">
                    <div class="book-display-container">
                        <div class="book-display-centered">
                            <a href="product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html"  >
                                <img src="' . $row['Image_URL_M'] . '" style="border: 0;" alt="$row[\'Book_Title\']"/>
                            </a>
                        </div>
                    </div>
                </div>
            </div>    
            <div class="book-display-details">
                <div class="book-display-title"><p><a href="product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html"  title="' . $row['Book_Title'] . '" >' . $row['Book_Title'] . '</a></p></div>
                <div class="book-display-author"><p> ' .$row['Book_Author'] . '</p></div>
                <div id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_divStock" class="book-display-stock"></div>
                <div class="book-display-price">' . $price . '</div>
                <input type="submit" name="ctl00$ctl00$CMSContentMasterPlaceHolder$cphContent1$ctl01$ProductSummary1$DataList1$ctl02$btnBuyNow" value="add to basket" id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_btnBuyNow" title="add to basket" class="ecom-add-basket" />
            </div>        
            <div class="clear"></div>
        </li>';
    }
    ?>
    

    hope it helped

    点赞 评论
  • dongpo7467
    dongpo7467 2014-06-27 09:30

    You must echo html content or close php tag before them

    Try this:

    <?php  
    while($row = mysqli_fetch_array($result)) {
    
    $price = ($row['ISBN']%1000);
    echo $price;
    ?>
    <li>
            <div class="book-display-bg">
                <div class="book-display-placeholder">
                    <div class="book-display-container">
                        <div class="book-display-centered">
                            <a href='product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html'  >
                                <img src="<?php echo $row['Image_URL_M']?>" style='border: 0;' alt=" <?php echo $row['Book_Title']?>"/>
                            </a>
                        </div>
                    </div>
                </div>
            </div>    
            <div class="book-display-details">
                <div class="book-display-title"><p><a href='product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html'  title="<?php echo $row['Book_Title'] ?>" > <?php echo $row['Book_Title']?></a></p></div>
                <div class="book-display-author"><p><?php echo $row['Book_Author'] ?></p></div>
                <div id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_divStock" class="book-display-stock"></div>
                <div class="book-display-price"><?php echo $price ?></div>
                <input type="submit" name="ctl00$ctl00$CMSContentMasterPlaceHolder$cphContent1$ctl01$ProductSummary1$DataList1$ctl02$btnBuyNow" value="add to basket" id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_btnBuyNow" title="add to basket" class="ecom-add-basket" />
            </div>        
            <div class="clear"></div>
        </li>
    <?php 
    }
    ?>
    
    点赞 评论
  • douzhoubing2805
    douzhoubing2805 2014-06-27 09:30

    Please do use open and close braces correctly.

    If you want to use the HTMl code in php then all you have to do is echo

    for example:

    <?php  
    while($row = mysqli_fetch_array($result)) {
       echo "<div class='book-display-centered'>{$row['Book_Author']}</div>"
    }
    ?>
    

    And since you have lot of data in html you can use it like this

     <?php  
        while($row = mysqli_fetch_array($result)) {
         ?>
             <div class='book-display-centered'><?php echo $row['Book_Author'] ?></div>
        <?php 
    }
        ?>
    
    点赞 评论
  • dsfsdf5646
    dsfsdf5646 2014-06-27 11:21

    Use below code... while($row = mysqli_fetch_array($result)) {

    $price = ($row['ISBN']%1000);
    echo $price;
    ?>
    <li>
        <div class="book-display-bg">
            <div class="book-display-placeholder">
                <div class="book-display-container">
                    <div class="book-display-centered">
                        <a href='product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html'  >
                            <img src=''$row['Image_URL_M']'' style='border: 0;' alt=''$row['Book_Title']''/>
                        </a>
                    </div>
                </div>
            </div>
        </div>    
        <div class="book-display-details">
            <div class="book-display-title"><p><a href='product/taqatu-niran-min-yaumiyat-al-intifada-as-suriya-9789953892368-(105523).html'  title=''$row['Book_Title']'' >$row['Book_Title']</a></p></div>
            <div class="book-display-author"><p>$row['Book_Author']</p></div>
            <div id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_divStock" class="book-display-stock"></div>
            <div class="book-display-price">$price</div>
            <input type="submit" name="ctl00$ctl00$CMSContentMasterPlaceHolder$cphContent1$ctl01$ProductSummary1$DataList1$ctl02$btnBuyNow" value="add to basket" id="ctl00_ctl00_CMSContentMasterPlaceHolder_cphContent1_ctl01_ProductSummary1_DataList1_ctl02_btnBuyNow" title="add to basket" class="ecom-add-basket" />
        </div>        
        <div class="clear"></div>
    </li>
    <?php
    }
    ?>
    
    点赞 评论

相关推荐