douzai8285 2009-07-16 00:35
浏览 25
已采纳

低级PHP变量传递问题

I am new... to the site and to PHP in general. Please forgive my ineptitude.

Anyway, I tried poring over the tagged posts for "passing" "variables" etc. Got some bites, but not exactly what I need. Unfortunately, I learn things by reverse engineering, so like many, I've been going around stealing snippets of PHP and adapting to my needs. Makes for some huge gaps in the learning process that I need to fill in.

Anyway, I have a page that I put together and it's pulling a bunch of nicely ordered records from the DB I made. I have them displaying the way I like using ASC in the query.

I have navigation to filter those results by first letter like "../name.php?bbname=a" but due to my incompetence, it doesn't work.

I think the method I have for constructing the query may be too inflexible?? I am including my junky code below with commented out areas to show what I'm trying to get at. I donm't know why I have two queries included. It's as if I have one sitting there just "waiting" for the passed info. I assume I should just re-work the original query to lay in waiting for the GET stuff yet to still put together the large SELECT ALL

Sorry if my question posing methods are off... THANK YOU!

<?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\">
";
    echo "    <col id=\"bbNAME\" />
"; 
    echo "    <col id=\"bbIMG\" />
"; 
    echo "    <col id=\"bbDETAILS\" />
"; 
    echo "    <col id=\"bbHOURS\" />
"; 
    echo "    <col id=\"bbTYPE\" />
"; 
    echo "    <col id=\"bplacesEA\" />
"; 
    echo "    <col id=\"bbRATING\" />
"; 
    echo "    <thead>
"; 
    echo "      <tr>
"; 
    echo "        <th style=\"border: none;\">Name</th>
"; 
    echo "        <th>&nbsp;</th>
"; 
    echo "        <th>Details </th>
"; 
    echo "        <th>Hours</th>
"; 
    echo "        <th>Type</th>
"; 
    echo "        <th>Area</th>
"; 
    echo "        <th> Rating</th>
"; 
    echo "      </tr>
"; 
    echo "    </thead>
";
    echo "    <tbody>
";
    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 />
" .$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";?>
  • 写回答

1条回答 默认 最新

  • dsh1102 2009-07-16 00:42
    关注

    Try this:

        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 ")
        }
    

    Instead of what you had at that block.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)