douzai1074 2012-03-03 15:33
浏览 26
已采纳

PHP下拉菜单以检索结果

I wonder whether someone can help me please.

I've put together the script below that displays a list of dates from a mySQL database.

<?php
mysql_connect("host", "user", "password")or
die(mysql_error());
mysql_select_db("database");
?>
<form>
<select>

<?php 
$result = "SELECT userdetails.userid, finds.dateoftrip, detectinglocations.locationname, finds.findid, finds.userid, finds.locationid, detectinglocations.locationid, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 GROUP By dateoftrip ORDER BY dateoftrip DESC";     
$result =mysql_query($result);
while ($data=mysql_fetch_assoc($result)){
?>
<option value ="<?php echo $data['findid'] ?>" ><?php echo $data['dateoftrip'] ?></option>
<?php } ?>

</select>
</form>

What I'd now like to do is upon a date being selected, retrieve the associated values from the fields 'findname' and 'finddescription, inserting them in a table on my page.

I've spent hours trying to get this to work, without any success. I just wondered whether someone could perhaps give me a helping hand please and let me know what I need to do to retrieve the results.

Many thanks

Updated Code

<?php
mysql_connect("host", "user", "password")or
die(mysql_error());
mysql_select_db("database");
?>
<form>
<select>

<?php 
$result = "SELECT dateoftrip, findid, userid, locationid, findname, finddescription FROM finds GROUP By dateoftrip ORDER BY dateoftrip DESC";  

$result =mysql_query($result);
while ($data=mysql_fetch_assoc($result)){
?>
<option value ="<?php echo $data['findid'] ?>" ><?php echo $data['dateoftrip'] ?></option>
<?php } ?>

</select>
</form>
  • 写回答

4条回答 默认 最新

  • dongleiqiao2107 2012-03-03 15:54
    关注

    let me know what I need to do to retrieve the results

    what you need is:

    1.repair query

    SELECT 
       userdetails.userid AS userdetails_userid, 
       finds.dateoftrip, 
       detectinglocations.locationname, 
       finds.userid AS finds_userid, 
       finds.locationid AS finds_locationid , 
       detectinglocations.locationid AS detectinglocations_locationid ,
       finds.findname, 
       finds.finddescription 
    FROM 
       userdetails, 
       finds, 
       detectinglocations 
    WHERE 
       finds.userid=userdetails.userid AND 
       finds.locationid=detectinglocations.locationid AND 
       finds.userid = 1 
    GROUP By 
       finds.dateoftrip
    ORDER BY 
       finds.dateoftrip DESC
    

    2.insert generating code into variable and then echo

    while ($data=mysql_fetch_assoc($result)) {
       $options .="<option value =\"". $data['userdetails_userid'] ."\">". $data['finds_locationid'] ."</option>";
    }
    echo "<select>". $options ."</select>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答