I need some assistance with creating a dropmenu that pulls a database field and displays the rest of information underneath it so i can print it. I am only having issues with after selecting the info in the field, the information doesn't change.

<?php


mysql_connect('host', 'user', 'password');
mysql_select_db('databasename');
$sql = "SELECT * FROM table1";
$result = mysql_query($sql);


echo "<form name='filterform' method='POST' action='test.php'>";
echo "<select name='filter' id='filter' onchange='this.form.submit();'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['created_time'] ."'>" . $row['created_time'] ."</option>";
}
echo "</select>";
echo "</form>";


?>


<?php 
$Search = isset($_REQUEST['filter']);

$query = "SELECT * FROM table1 WHERE created_time='$Search'";

$res = mysql_query($query);

while ($info = mysql_fetch_assoc($res)) {

   echo "<h4>End of Day Report</h4>";
  echo "Date Created:", " ". $info['created_time'];
    echo "<BR>";
  echo "Orders Total:", " ". $info['order_total'];
}

?>
Member Avatar for iamthwee

I'd say remove the word isset from line 23.

Also don't forget to include:

mysql_connect('host', 'user', 'password');mysql_select_db('databasename');`

In test.php if your db connection isn't persistant.

Another thing that struck me as odd is you have mysql_fetch_assoc on line 29. Although that could be still OK, but I would change that back to mysql_fetch_array

Oh yeah mysql is deprecated, use mysqli or PDO etc.

mysql_connect and mysql_select_db have to be added under line 22 correct?

that doesn't work...what i am trying to achieve is the dropdown menu pulls a database line. Once i select a line from the drop menu, all of the information for that database is displayed.

Member Avatar for iamthwee

Post your new code.

 <?php
    mysql_connect('host', 'user', 'password');
    mysql_select_db('databasename');
    $sql = "SELECT * FROM table1";
    $result = mysql_query($sql);
    echo "<form name='filterform' method='POST' action='test.php'>";
    echo "<select name='filter' id='filter' onchange='this.form.submit();'>";
    while ($row = mysql_fetch_array($result)) 
    {
    echo "<option value='" . $row['created_time'] ."'>" . $row['created_time'] ."</option>";
    }
    echo "</select>";
    echo "</form>";

    ?>


    <?php
    mysql_connect('host', 'user', 'password');
    mysql_select_db('databasename');
    $Search = ($_REQUEST['filter']);
    $query = "SELECT * FROM table1 WHERE created_time='$Search'";
    $res = mysql_query($query);
    while ($info = mysql_fetch_array($res)) 
    {
    echo "<h4>End of Day Report</h4>";
    echo "Date Created:", " ". $info['created_time'];
    echo "<BR>";
    echo "Orders Total:", " ". $info['order_total'];

    }
    ?>

im new to php... :(

Member Avatar for iamthwee

When you say it doesn't work, by that you mean you're not getting any output/ it is blank/ it is pulling some information but not all?

You have to be more specific.

No output is being shown. I cna still see the drop down menu with the database information though.

Member Avatar for iamthwee

Where did you put test.php in your folder is it in the same folder as your other php file?

Everything is done in this single acutal file name that contains the coding above. This file is test.php.

i want everythind done in one single file..

Member Avatar for iamthwee

No you need two files, one called index.php and the other called test.php

ok in the index.php file i need to put the code of the dropdown menu, so once is submitted it calls the test.php file.

Member Avatar for iamthwee

Yes it should be like this:
index.php

 <?php
    mysql_connect('host', 'user', 'password');
    mysql_select_db('databasename');
    $sql = "SELECT * FROM table1";
    $result = mysql_query($sql);
    echo "<form name='filterform' method='POST' action='test.php'>";
    echo "<select name='filter' id='filter' onchange='this.form.submit();'>";
    while ($row = mysql_fetch_array($result)) 
    {
    echo "<option value='" . $row['created_time'] ."'>" . $row['created_time'] ."</option>";
    }
    echo "</select>";
    echo "</form>";

    ?>

test.php

<?php
mysql_connect('host', 'user', 'password');
mysql_select_db('databasename');
$Search = ($_REQUEST['filter']);
$query = "SELECT * FROM table1 WHERE created_time='$Search'";
$res = mysql_query($query);
while ($info = mysql_fetch_array($res)) 
{
echo "<h4>End of Day Report</h4>";
echo "Date Created:", " ". $info['created_time'];
echo "<BR>";
echo "Orders Total:", " ". $info['order_total'];

}
?>

ok the test.php that suppose to display the results is blank.

Member Avatar for iamthwee

Are you using the same database and password connection?

This code here seems to break the page, causing the white page.

$query = "SELECT * FROM table1 WHERE created_time='$Search'";

yes using the same database and password, but it seems to show when i remove (WHERE created_time='$Search') from the $query line

Member Avatar for iamthwee

Can you try changing line 4 to:

$Search = trim(($_POST['filter']));

when i removed that it shows..all my database fields instead of a single one.

ok it works now

how can i combine these into one .php file?

Member Avatar for iamthwee

Please mark thread as solved thanks.

in my php code, a few of those fields display cash format "2.50" but it doesn't show the correct format. How can i correct this to display the number format?

Member Avatar for iamthwee

Please mark this as solved and start a new thread entitled 'How to format numbers'

ok i managed to get the code on one single php.file. I will try to figure out the number format. Thanks alot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.