Jump to content

Forum and SQL Help


pctechtime

Recommended Posts

Below is what I have so far. My problem is I want select the clients name and number and view all of the infomation stored for that client in all the rows in the database. This must be in a table format with headers that I can name. Example clients_name would be Customers Name. Thanks for your help.

Mike   


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<?php
    $usr = "888";
    $pwd = "888";
    $db = "888";
    $host = "localhost";

  // # connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    mysql_select_db($db);
    if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

// Create the pull-down menu information.
$query1 = "SELECT order_number,client_name,test_ordered,salesperson,order_date FROM orders  ORDER BY order_number ASC";

$result1 = @mysql_query ($query1);

$pulldown1 = '<option>Select One</option>';

while ($row = mysql_fetch_array ($result1, MYSQL_ASSOC)) {

$pulldown1 .= "<option value=\"{$row['order_number']}\">{$row['order_number']}) {$row['test_ordered']}</option>\n";

}
?>

<form name="orders" action="orderlookup.php" method="POST">   
<table> <tr><td>Order Name: </td><td>
<select name="order_number">
<?php echo $pulldown1; ?> </select>
</td></tr></table>
<p><input type="submit" value="View Results"></p>
</th></tr></table>
</form>

<?php

// this is processed when the form is submitted
    // back on to this page (POST METHOD)
    if ($_SERVER['REQUEST_METHOD'] == "POST")
    {

        # escape data and set variables
        $order_number = addslashes($_POST["order_number"]);
        $client_name = addslashes($_POST["client_name"]);
        $test_ordered = addslashes($_POST["test_ordered"]);
        $salesperson = addslashes($_POST["salesperson"]);
        $order_date = addslashes($_POST["order_date"]);
       

}
?>

</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/35368-forum-and-sql-help/
Share on other sites

Hi. I'm a bit confused with the code since it appears that your form drop down selector is going to have one big choice of all three of those options in one option.

$pulldown1 = '<option>Select One</option>';

Then two lines down you concatenate it with two other choices:

$pulldown1 .= "<option value=\"{$row['order_number']}\">{$row['order_number']}) {$row['test_ordered']}</option>\n";

If I read this right it will produce a display of one option containing all three choices. Or maybe i'm not reading that right?

Getting information displayed about a particular row (or in this case a particular person) only requires you have the query specify a unique identifier...like an 'id' field.

[code]$query1 = "SELECT * FROM orders  WHERE id='$id' ";[/code]

Where the 'id' is passed in your search form. Or, the order_id or whatever you want to search by. Make sense?

Then, that query would work like this:

[code]<?php
$query1 = "SELECT * FROM orders  WHERE id='$id' ";
$results = mysql_query($query1);
echo "<table><tr>
        <th>Field 1</th><th>Field 2</th><th>Field 3</th><th>Field 4</th>
        </tr>";
while ($row = mysql_fetch_array($results))
{
      echo "<tr><td>" . $row['field1'] . "</td><td>" . $row['field2'] . "</td><td>" . $row['field3'] . "</td><td>" . $row['field4'] . "</td>
              </tr>";
}
echo "</table>\n";
?>
[/code]

That will produce a table with field names at the top (the <th> tags) and a row for each result (presumably one row).
Link to comment
https://forums.phpfreaks.com/topic/35368-forum-and-sql-help/#findComment-167298
Share on other sites

This still doesn't fix the problem here are my answeres to your questions


Hi. I'm a bit confused with the code since it appears that your form drop down selector is going to have one big choice of all three of those options in one option.

$pulldown1 = '<option>Select One</option>'; [b]This make the Select One show up first in the drop down menu.[/b]

Then two lines down you concatenate it with two other choices:

$pulldown1 .= "<option value=\"{$row['order_number']}\">{$row['order_number']}) {$row['test_ordered']}</option>\n"; [b]This make the all of the rows show up in the drop down to show up order_number first and then ) and then the test_ordered in the drop down menu. example " 4) Gold "[/b]

If I read this right it will produce a display of one option containing all three choices. Or maybe i'm not reading that right? This makes the above show up. Now I want to select number 4 Gold. When I press the button I want all the rows and colums data to show up in a list that where item_number 4 shows up only. remember 4 Gold was my selection above.

Below is the code I have now.

<?php
    $usr = "***";
    $pwd = "***";
    $db = "***";
    $host = "localhost";

  // # connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    mysql_select_db($db);
    if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

// Create the pull-down menu information.
$query1 = "SELECT order_number,client_name,test_ordered,salesperson,order_date FROM orders  ORDER BY order_number ASC";

$result1 = @mysql_query ($query1);

$pulldown1 = '<option>Select One</option>';


while ($row = mysql_fetch_array ($result1, MYSQL_ASSOC)) {
$pulldown1 .= "<option value=\"{$row['order_number']}\">{$row['order_number']}) {$row['test_ordered']}</option>\n";

}

?>

<form name="orders" action="orderlookup.php" method="POST">   
<table> <tr><td><b>Order Name: </b></td><td>
<select name="order_number">
<?php echo $pulldown1; ?> </select>
</td></tr></table>
<p><input type="submit" value="View Results"></p>
</th></tr></table>
</form>


<?php
$query1 = "SELECT * FROM orders  WHERE order_number='$order_number' ";
$results = mysql_query($query1);
echo "<table><tr>
        <th>Order Number</th>
        <th>Client Name</th>
        <th>Test Ordered</th>
        <th>Date Ordered</th>
        <th>Sales Person</th>
        </tr>";
while ($row = mysql_fetch_array($results))
{
      echo "<tr><td>" . $row['order_number'] . "</td><br><td>" . $row['client_name'] . "</td><td>" . $row['test_ordered'] . "</td><td>" . $row['order_date'] . "</td><td>" . $row['salesperson'] . "</td>
              </tr>";
}
echo "</table>\n";

?>

</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/35368-forum-and-sql-help/#findComment-168713
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.