Jump to content

therealwesfoster

Members
  • Posts

    345
  • Joined

  • Last visited

Contact Methods

  • Website URL
    https://www.wesfed.com

Profile Information

  • Gender
    Male
  • Location
    USA

therealwesfoster's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. First, you would need to send data to your website with either AJAX or a simple form. For this example, I'm using a form: <form action="" method="post"> Select your item: <input type="radio" name="item" value="1" /> Hammer <br /> <input type="radio" name="item" value="2" /> Arm <br/> <input type="submit" value="Submit" /> </form> All I did was create the radio buttons for each of the items in your database. I used the item's ID as the radio button's value, but you can use whatever you want. Next, I've altered your PHP code to this: <?PHP $server = 'localhost'; $user = 'root'; $password = ''; $mydb = 'Tools'; $table_name = 'Inventory'; if ( $_POST['Submit'] ) { /// Check if the form was submitted $item_id = mysql_real_escape_string($_POST['item']); /// Get the item's ID from the POST (form) $SQLcmd = "select * from $table_name WHERE item_id='{$item_id}' "; /// Add the "WHERE" clause $connect = mysql_connect($server, $user, $password); if (!$connect) { die ("Cannot connect to the $server using $user"); } else { mysql_select_db($mydb, $connect); $result = mysql_query($SQLcmd, $connect) or die(mysql_error()); print '<table border = 1>'; print '<tr><td>Item Name</td><td>Number Sold</td><td>Profit</td></tr>'; while($row = mysql_fetch_array($result)){ print '<tr>'; print "<td> {$row['Name']} </td>"; print "<td> {$row['Sold']} </td>"; $Profits = ($row['Price'] - $row['Cost']) * $row['Sold'] ; print "<td> $Profits </td>"; print '</tr>'; } print '</table>'; } mysql_close($connect); } /// END POST "IF" ?> I added comments to the lines that I altered. Simply put, I: 1. Check if a POST was sent (from the form) 2. Grabbed the $_POST['item'] value (which is the item's id) and filtered it using mysql_real_escape_string() 3. Altered your MySQL query to only grab records where the item_id is equal to what was sent in the form. You might need to change the name of your column name in the WHERE clause, but overall, that's how you get what you want. I hope I understood you correctly Wes
×
×
  • 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.