我是新的...到网站和PHP一般。请原谅我的无能。
无论如何,我尝试在标记的帖子上仔细研究“传递”“变量”等等。有点咬,但不完全是我需要的。不幸的是,我通过逆向工程学习东西,所以很多,我一直在偷窃PHP的片段并适应我的需求。在我需要填写的学习过程中造成一些巨大的差距。
无论如何,我有一个页面,我把它放在一起,它从我制作的数据库中提取了一堆很好的有序记录。我让他们在查询中显示我喜欢使用ASC的方式。
我有导航按照首字母“../name.php?bbname=a”过滤这些结果,但由于我的无能,它不起作用。
我认为构建查询的方法可能太不灵活了?我将下面的垃圾代码包含在注释区域中,以显示我想要了解的内容。我不知道为什么我要包含两个查询。就好像我坐在那里只是“等待”传递的信息。我假设我应该重新处理原始查询以等待GET的东西,但仍然把大的SELECT ALL放在一起
对不起,如果我提出的问题摆脱方法......谢谢!
<?php include "header.php";?>
<?php include "wrap.php";?>
<?php include "left.php";?>
<div id="content">
<div id="ad728x90">
<?php include "ad728x90.php";?>
</div>
<?php include "utilplaces.php";?>
<h1>Places by Name</h1>
<div id="horizon"><a href="?bbname=a">A</a> <a href="?bbname=b">B</a> <a href="?bbname=c">C</a> <a href="?bbname=d">D</a> <a href="?bbname=e">E</a> <a href="?bbname=f">F</a> <a href="?bbname=g">G</a> <a href="?bbname=h">H</a> <a href="?bbname=i">I</a> <a href="?bbname=j">J</a> <a href="?bbname=k">K</a> <a href="?bbname=l">L</a> <a href="?bbname=m">M</a> <a href="?bbname=n">N</a> <a href="?bbname=o">O</a> <a href="?bbname=p">P</a> <a href="?bbname=q">Q</a> <a href="?bbname=r">R</a> <a href="?bbname=s">S</a> <a href="?bbname=t">T</a> <a href="?bbname=u">U</a> <a href="?bbname=v">V</a> <a href="?bbname=w">W</a> <a href="?bbname=x">X</a> <a href="?bbname=y">Y</a> <a href="?bbname=z">Z</a> <a href="?bbname=0">0-9</a></div>
<div class="cnp"></div>
</div>
<div id="biggun">
<?php
// Connects to the Database
mysql_connect("localhost","user","password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
// I AM TRYING TO GRAB THE VARIABLES FROM THE URL BUT HAVE NO CLUE
$bbname = $_GET['bbname'];
// THIS IS THE STANDARD DB QUERY TO SETUP THE PAGE IN DEFAULT LOAD
$data = mysql_query("SELECT * FROM places ORDER BY `places`.`name` ASC LIMIT 0, 30 ")
or die(mysql_error());
echo "<table id=\"placesstable\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
echo " <col id=\"bbNAME\" />\n";
echo " <col id=\"bbIMG\" />\n";
echo " <col id=\"bbDETAILS\" />\n";
echo " <col id=\"bbHOURS\" />\n";
echo " <col id=\"bbTYPE\" />\n";
echo " <col id=\"bplacesEA\" />\n";
echo " <col id=\"bbRATING\" />\n";
echo " <thead>\n";
echo " <tr>\n";
echo " <th style=\"border: none;\">Name</th>\n";
echo " <th> </th>\n";
echo " <th>Details </th>\n";
echo " <th>Hours</th>\n";
echo " <th>Type</th>\n";
echo " <th>Area</th>\n";
echo " <th> Rating</th>\n";
echo " </tr>\n";
echo " </thead>\n";
echo " <tbody>\n";
while($info = mysql_fetch_array( $data ))
{
echo "<tr>";
echo "<td><p class=\"placesnametable\"><a href=\"#\">".$info['name'] . "</a></p></td> ";
echo "<td><img src=\"".$info['tmbimg']."\" alt=\"\" name=\"placesthumb\" width=\"100\" height=\"67\" class=\"placesthumb\" /></td> ";
echo "<td>".$info['address'] . "<br />\n" .$info['phonenumber'] . "</td>";
echo "<td>".$info['hours'] . "</td> ";
echo "<td>".$info['type'] . "</td> ";
echo "<td>".$info['district'] . "</td> ";
echo "<td>Pending<!--RATING--></td></tr>";
}
echo "</tbody>";
echo "</table>";
?>
</div>
<?php include "feetie.php";?>
答案 0 :(得分:0)
试试这个:
if(isset($_GET['bbname'])) {
$name = mysql_real_escape_string($_GET['bbname']);
$query = mysql_query("SELECT * FROM places ORDER BY name ASC LIMIT 0,30 WHERE name LIKE '$name'") OR die(mysql_error());
}
else {
$data = mysql_query("SELECT * FROM places ORDER BY `places`.`name` ASC LIMIT 0, 30 ")
}
而不是你在那个街区所拥有的。