-5

这是代码示例,请在此处添加以解决 $name 只是最后一种蔬菜 :((( 我需要所有这些都在链接中:

<?php
    $mike = mysql_query('SELECT vegetables FROM nature');
    while($subfile = mysql_fetch_assoc($mike))
    {
        $jack = $subfile['vegetables'];
        $name = $jack;
    }                       
    //while ends                        

    echo ('<span><a href="index.php?='.$name.'">Vegetables</a>
    | 
    Fruits
    | 
    Suggestions </span>');
?>
4

3 回答 3

1

假设您希望所有这些都采用番茄、黄瓜、沙拉之类的格式,将它们堆叠成一个数组,同时循环遍历结果,然后将它们粘合在一起。

<?php
                    $mike = mysql_query('SELECT vegetables FROM nature');
                    $names = array();
                    while($subfile = mysql_fetch_assoc($mike)) {
                       $jack = $subfile['vegetables'];
                       $names[] = $jack;
                    }

                    //while ends

$list = join(',',$names);
echo ('<span><a href="index.php?='.$list.'">Vegetables</a>
| 
Fruits
| 
Suggestions </span>');
?>
于 2013-09-09T10:28:51.527 回答
0

将下面的代码放入 while 循环中,

echo ('<span><a href="index.php?='.$name.'">Vegetables</a>
| 
Fruits
| 
Suggestions </span>');
于 2013-09-09T10:27:50.427 回答
0
<?php
    $mike = mysql_query('SELECT vegetables FROM nature');
    while($subfile = mysql_fetch_assoc($mike))
    {
        $name = $subfile['vegetables'];
        echo ('<span><a href="index.php?='.$name.'">'.$name.'</a>
        | 
        Fruits
        | 
        Suggestions </span>');
    }                       
    //while ends   
?>
于 2013-09-09T10:29:19.740 回答