i have a data base with a table named "items" with a field "stock_num" that I want to search but just the stock_num field and return and show just a fiew fields like
"stock_num"
"qty"
"price"
"cost"
"discription"
don't care how they are displayed I have been trying alot of different scripts i have found on the net and have given up on them they all just seem to be just displaying all items in a list from the table so I have given up on them
simple search for sql data base
Moderator: General Moderators
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Tossed this together kind of fast, but I think its correct
Lite...
Code: Select all
<?PHP
// connect to database
$user="*****";
$password="*****";
$database="*****";
$conn = mysql_connect(localhost,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
// ----------------------------
// create the sql statement
$sql = "SELECT stocknum, qty, price, cost, description FROM items WHERE stock_num = $what_stock";
// execute the sql statement
$result = mysql_query($sql, $conn) or die("problem here");
// -----------------------------------
// loop thru and display the rows
?>
<table>
<tr>
<td>Stock Number</td>
<td>Qty</td>
<td>Price</td>
<td>Cost</td>
<td>Description</td>
</tr>
<?PHP
while ($row = mysql_fetch_array($result)) {
// get data from the current row
$qty = $rowї"qty"];
$price = $rowї"price"];
$cost = $rowї"cost"];
$description = $rowї"description"];
?>
<tr>
<td><?PHP echo $what_stock; ?></td>
<td><?PHP echo $qty; ?></td>
<td><?PHP echo $price; ?></td>
<td><?PHP echo $cost; ?></td>
<td><?PHP echo $description; ?></td>
</tr>
<?PHP
}
?>Think i got it
Code: Select all
<?PHP
// connect to database
$database = "******";
$table_name = "******";
$connection = @mysql_connect("localhost", "******", "*******")
or die("Couldn't connect.");
$db = @mysql_select_db($database, $connection)
or die("Couldn't select database.");
// ----------------------------
// create the sql statement
$sql = "SELECT stock_num, price, cost, item_type, item_disc
FROM $table_name WHERE stock_num = $what_stock";
// execute the sql statement
$result = mysql_query($sql, $connection) or die("problem here");
// -----------------------------------
// loop thru and display the rows
?>
<table>
<tr>
<td>Stock Number</td>
<td>Qty</td>
<td>Price</td>
<td>Cost</td>
<td>Description</td>
</tr>
<?PHP
while ($row = mysql_fetch_array($result)) {
// get data from the current row
$qty = $rowї"qty"];
$price = $rowї"price"];
$cost = $rowї"cost"];
$item_disc = $rowї"item_disc"];
?>
<tr>
<td><?PHP echo $what_stock; ?></td>
<td><?PHP echo $qty; ?></td>
<td><?PHP echo $price; ?></td>
<td><?PHP echo $cost; ?></td>
<td><?PHP echo $item_disc; ?></td>
</tr>
<?PHP
}
?>