0

在一个 JS 图片幻灯片文件脚本中是这样的

slides :    [           // Slideshow Images
                                            {image : 'images/bgslide/r1.jpg', title : '<h1>Välkommen till Restaurangen SPICE</h1> <p>Bokabord/Beställa Online/ Smaka Gott<br><span></span></p>',},
                                            {image : 'images/bgslide/r2.jpg', title : '<h1>Thai Veg-Tallrik</h1> <p>Blandade Thai veg-rätter med sallad. Helgenserbjudande<br> <span>:89 </span></p>',},
                                            {image : 'images/bgslide/r3.jpg', title : '<h1>Välkommen till Restaurangen SPICE</h1> <p>Bokabord/Beställa Online/ Smaka Gott<br> <span></span> </p>',},
                                            {image : 'images/bgslide/r4.jpg', title : '<h1>Dessert</h1> <p>vaniljglass med körsbär<br><span>:59 </span></p>',}
                                    ],

但我想用 php mysql 制作这张幻灯片。想使用while循环。我写的循环代码是

slides : [ // Slideshow Images <?php $q_f ="SELECT * FROM bgslide order by id" or die($query."<br/>".mysql_error()); $r_f = mysql_query($q_f); $comma=''; while($row = mysql_fetch_array($r_f)) { ?> <?php echo $comma; ?> {image : 'images/bgslide/<?php echo $row["bgimg"]; ?>', title : '<h1><?php echo $row["captitle"]; ?></h1> <p><?php echo $row["capdsc"]; ?><br><span><?php echo $row["price"]; $comma=', '; ?></span></p>',} <?php } ?> ], 它不工作。任何人都可以帮助我解决这个问题..?

4

1 回答 1

-1

Just try this-

<?php 
    $q_f ="SELECT * FROM bgslide order by id" or die($query."<br/>".mysql_error()); 
    $r_f = mysql_query($q_f); 
    $slide = ''; 
    while($row = mysql_fetch_array($r_f)) {
        $slide .= "{image : 'images/bgslide/".$row["bgimg"]."', title : '<h1>".$row["captitle"]."</h1> <p>".$row["capdsc"]."<br><span></span></p>',},";
    }
    ?>
slides :    [<?php echo $slide?>],
于 2013-01-16T12:28:47.563 回答