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 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗