php无法显示结果网页

时间:2014-06-12 13:51:57

标签: php html mysql

我在尝试获取在php中工作的网址时遇到问题,我基本上得到了显示的内容列表,列表内容成为结果网页的链接(detail.php)。我想显示结果网页的更多详细信息。在同一网页上,后退按钮到原始列表。

=====
 my list webpage code
 =====

$c = 0; //Variable to keep count of categories
$servicetype = '$brand';    //variable declaration last displayed servicetype.   
$strSQL = "SELECT * FROM <tablename>  ORDER BY serviceType, serviceName ASC";

   // Execute the query (the recordset $rs contains the result)

$rs = mysql_query($strSQL);

    // Loop the recordset $rs

while($row = mysql_fetch_array($rs)) {
    //If the servicetype name has changed, display it and update the tracking variable
    if ($servicetype != $row['serviceType']){
    $servicetype = $row['serviceType'];

 //If this isn't the first category, end the previous list.
    if ($c>0) echo "</ul>";

    echo '<h3>'.$row['serviceType'].'</h3><ul>'; // subheading & related content.
    $c++;
}

    $strName = $row['serviceName'];
    $strLink = "<a href = 'detail.php?id = " . $row['ID'] . "'>" . $strName . "</a>";

 // List link

   echo "<li>" . $strLink . "</li>"; 
  }

// Close the database connection

mysql_close();

?>
 ====
 my detail.php code below
 =====
$strSQL = "SELECT * FROM gu_service_cat WHERE id = " . $_GET["id"];
  $rs = mysql_query($strSQL);

    // Loop the recordset $rs

while($row = mysql_fetch_array($rs)) {

      // Write the detail data of the ID

    echo '<h3>ID:</h3>' . $row['ID'] . ' ' . $row['guUrl'] . "</dd>";
    echo "<dt>availability:</dt><dd>" . $row["availability"] . "</dd>";

}

//echo '<h3>'.$row['serviceType'].'</h3><ul>';

 // Close the database connection
mysql_close();
?>
</dl>
   <p>
 <a href="main list webpage">Return to the list</a>

1 个答案:

答案 0 :(得分:0)

我确实看到你不情愿地使用变量。

这是不正确的:

$servicetype = '$brand';
if ($servicetype != $row['serviceType'])

您需要做的是为变量$servicetype分配一个字符串,在本例中为'brand',并在if语句中使用它:

$servicetype = 'brand';
if ($$servicetype != $row['serviceType'])

注意双美元符号。详细了解Variable Variables