Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by Adamhumbug

  1. Hi, Thanks again for your response. So forgive me if i am missing the point here but, how do i run my php function from the buttons, currenlty it is on page load but i have read that you cannot run a function from a button without AJAX. Can i put an onclick on the button that will call the function. <div onclick="show_spirits()">show spirits</div> <div> onclick="show_soft_drinks()">show soft drinks</div> Where you have put how do i set the "?" to be the value that was pulled from the querey that set the button. If my sql looked something like $sql = "SELECT * FROM products WHERE product_catagory = $pro_cat"; and on clicking the button it set the $pro_cat to = the value of the div and then run the db querey? Is this possible or am i over complicating matters here. Kind Regards Adam
  2. Hi, This is the code that i have come up with. It fills the dropdown with all of the product types <?php include 'dbconn.php'; ?> <!DOCTYPE html> <html> <head> <title>Register</title> <link rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" src="java.js"></script> </head> <body> <div class="headerBar"> TOP </div> <div class="sideBar"> <?php require 'productCatagory.php' ?> </div> <div class="mainArea"> <form action="" method="post"> <p>Select category: <select name="category"> <?php $sql = "SELECT DISTINCT(product_catagory) FROM `products`"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $pro_cat = $row["product_catagory"]; echo <<< "EOT" <option value="$pro_cat">$pro_cat</option> EOT ; } } else { echo <<< "EOT" <option value="None_Found">No Products Found</option> EOT ; } // $conn->close(); ?> </select> <button type="submit" name="search">Search</button></p> </form> <div class="buttonArea"> <?php require 'productButtons.php' ?> </div> <div class="itemArea"> <div class="itemisedArea"> <textarea class="FormElement" name="term" id="term" style="width: 98%; height: 100%;"></textarea> </div> <div class="keypadArea"> </div> </div> </div> </body> </html> The original code that i had to create the buttons was <?php $sql = "SELECT DISTINCT(product_catagory) FROM `products`"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $pro_cat = $row["product_catagory"]; echo <<< "EOT" <div class="productCatagoryButton" id="$pro_cat">$pro_cat</div> EOT ; } } else { echo "0 results"; } // $conn->close(); ?> I was thinking/hoping that somehow, i could change the sql command (on a button click) sothat runs and pulls all of the product buttons for each catagory. I know how to pull for one catagory and i know how to pull for them all but the product buttons down the sidebar are generated pulling info from the database and echoing this with html to build the buttons can this set a variable to change SELECT * FROM products WHERE product_catagory = "Spirit" to SELECT * FROM products WHERE product_catagory = "Wine" Am i looking at this the right way?
  3. Hi. Firstly thanks for your help, i will take that code and see if i can get it going. In terms of getting the buttons - yes i have that working. I have buttons down the side as a sidebar and buttons in a grid as the main part of the screen - this works. The code that makes the buttons down the side looks for unique values in the product field and creates one button per unique catagory (spirits/soft drinks/etc) The code that makes the prroduct buttons also works. I will come back to you with what happens with the code that you have provided. Kind Regards Adam
  4. HI all, I am pretty new to php and am trying to teach myself - i dont have any massive project in mind and have just been playing around. I decided to make a POS like system. I was quite proud of my self, i created some php that got information from the db and displayed a box per record returned. The database is returning products that a bar might sell, beer, wine, spirits and each product regardless of catagory is being put in a box on the screen. I wanted to have a button that when pressed only shows the items in the database with the product_catagory of wine - same with spirits and softdrinks. I have added my buttons that i want to do the work but at this point i am stuck. After doing quite a lot of reading it seems that i am going to need to use "AJAX" - is this the case? Below is just a test page that has the button on that i will use to call the function <!DOCTYPE html> <html> <head> <title>page</title> <link rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" src="java.js"></script> </head> <body> <?php include "dbconn.php" ?> <?php include "testing.php" ?> <div id="spiritButton" style="width:100px;height:100px;background:red">Click Me</div> </body> </html> Below is the fucntion that pulls back all of the products, i wanted to change the sql command depending on which button is pressed (as in only show spirits when you click "spirits" but change with other product catagorys) <?php $sql = "SELECT * FROM products"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $pro_id = productButton.$row["product_id"]; $pro_display = $row["product_name"]. "<br/><br/>"."£". $row["product_price"]; echo <<< "EOT" <div class="productButton" id="$pro_id">$pro_display</div> EOT ; } } else { echo "No results found"; } $conn->close(); ?> I would really appreciate any help on this but please be as gentle as possible as my ability is likely much lesser than yours. Kind Regards Adam
  • 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.