duanlong4890 2012-10-16 13:19
浏览 34
已采纳

使用ajax显示MySQL数据

hi i'm new with php and i really don't know ajax. i making a photo gallery site i used the code below to display my photos i need to make possible with ajax or any other language, when someone click on the photo in index.php with the title example:"happy day 2012" want the photo being displayed in another page example:"photo/happy-day-2012"

<?php 
$link = mysql_connect("localhost", "root","");
mysql_select_db("test", $link);
$query = "select * from post order by id DESC;";
$results = mysql_query($query, $link) or die ("error!".mysql_error());
if($results){
$i = 1;
while ($row = mysql_fetch_assoc($results)){
echo $row['title']. "<img src=/1/" . $row['location']."width=580px>"."<br/><br/><br/>";
}
}
?>

Please if possible can use lot of comments on the code.

  • 写回答

1条回答 默认 最新

  • dsfovbm931034814 2012-10-16 23:28
    关注

    According a previous comment, you don't need AJAX, what you actually need is mod_rewrite. mod_rewrite is a Apache Module, that let's you rewrite urls according some pattern or rule. To do this, it's common to use .htaccess file (that should be located on your site root). If you are in a development machine, make sure you've enabled AllowOverride on your Apache config file.

    After that you can easily do something like this

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule    ^photo/(.+)$ viewer.php?photo=$1 [L]
    </IfModule>
    

    This is a very rough example, but basically what it does is... detects when a URI starts with "photo/" and send everything after that to another URL ($1 reference to what is found).

    Later, you can determine on viewer.php what you want to show using $_GET['photo'] variable.

    But again, this is pretty advanced if you are new with PHP.

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

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)