一次获取多个查询字段时,查询字段不会分开

时间:2011-11-20 21:09:32

标签: php sql

当我运行此查询时,它工作正常,但各个字段将拉出。与ThumbFilePathTitle一样。

如果我只使用一个字段运行查询:

$result = mysql_query("select ThumbFilePath from artwork where SCID = $SCID") or die(mysql_error());

工作正常。任何想法为什么我不能拉其他领域?

<?php
    $dbname = 'pdartist2';
    $table = 'artowrk';
    // query
    $result = mysql_query("select AID, ThumbFilePath, Title, DisplayOrder from artwork where SCID = $SCID") or die(mysql_error());

    while($row = mysql_fetch_row($result))
    {
        foreach($row as $cell)
        {
            echo "<div id='thumb_container'>";        
            echo "
<a href='gallery_detail.php?AID=$AID'>
 <img src='http://markdinwiddie.com/PHP2012/$ThumbFilePath' title='Enlarge' alt='Enlarge' border='0'>
</a>
";
            echo "$Title";
            echo "</div>";
        }
    }
    mysql_free_result($result);
?>

1 个答案:

答案 0 :(得分:0)

通常,您始终需要取消引用所需的列。例如:

  while($row = mysql_fetch_row($result)) {
      $aid = $row['AID'];
      $tpath= $row['ThumbFilePath'];
      $title = $row['title'];
      ...



<?php
  $dbname = 'pdartist2';
  $table = 'artowrk';
  // query
  $sql = "select AID, ThumbFilePath, Title, DisplayOrder from artwork where SCID = $SCID";
  $result = mysql_query($sql) or die(mysql_error());
  while($row = mysql_fetch_row($result)) {
    $AID = $row['AID'];
    $ThumbFilePath= $row['ThumbFilePath'];
    $Title = $row['Title'];
    $DisplayOrder = $row['DisplayOrder'];
    echo "<div id='clear'></div>";
    echo "<div id='thumb_container'>";
    echo "<a href='gallery_detail.php?AID=$AID'><img src='http://markdinwiddie.com/PHP2012/$ThumbFilePath' title='Enlarge' alt='Enlarge' border='0'></a>";
    echo "<div id='name_spacer'></div>";
    echo "<div id='thumbdesc'>";
    echo "$Title";
    echo "</div>";
    echo "</div>";
  }
  mysql_free_result($result);
?>