0

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'];
}

?>
2
Contributors
26
Replies
26
Views
2 Years
Discussion Span
Last Post by polodon242
0

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.

Edited by iamthwee

0

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

Edited by polodon242: correction

0

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.

0
 <?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'];

    }
    ?>
0

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.

0

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

0

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

0

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.

0

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'];

}
?>

Edited by iamthwee

0

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

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

0

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

0

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

0

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?

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.