dongxixia6399 2011-11-03 03:38
浏览 45

来自Mysql的PHP下拉,打印结果

I have created a dropdown list and populated it with Mysql. I am trying to fetch the results of the users selection to show on 2 different pages permanently but I can't get it to work.

here is my code:

<?php
    // Connect to the test datbase on localhost
    // That's where we created the countries table above
    mysql_connect('localhost','jakeray','pass');  mysql_select_db('wordpress');

    // Query the countries table and load all of the records
    // into an array.
    $sql = 'select * FROM manufacturers';
    $res = mysql_query($sql) or die(mysql_error());
    while ($rec = mysql_fetch_assoc($res))
    $manufacturers[] = $rec;
    ?>

    <?php
    echo '<select action="select.php" name="dropdown" class="select">';
    foreach ($manufacturers as $c)
    {       
    if ($c['id'] == $_GET['id'])
    echo "<option value=\"{$c['id']}\" selected=\"selected\">{$c['mfg']},               {$c['info']}</option>
";
    else
    echo "<option value=\"{$c['id']}\">{$c['mfg']} {$c['info']}</option>
";
    }
    echo '</select>';
    ?>

    <?php
    if(isset($_POST['select']))
    {
    $manufacturers=mysql_real_escape_string($_POST['dropdown']);
    $result=mysql_query("SELECT FROM manufacturers");
    $row=mysql_fetch_assoc($result);
    print $row['mfg'];
    }
    ?>

I need to display the manufacturer permanently on 2 pages. Not sure if this is right.

How do I fetch the results of the selection from the database on two different pages and make it stay longer after the session expires.

  • 写回答

1条回答 默认 最新

  • doudan5136 2011-11-03 03:54
    关注

    Change $_POST['select'] to $_POST['dropdown']. Once they choose the manufacturer, you can:

    1. Store their choice in the database, possibly associated with their user's row if they're logged in
    2. Store their choice in the $_SESSION, if you're using PHP sessions.
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看