Search the Community
Showing results for tags 'sql php'.
-
I am trying to show all the whiskies from my database with the dates alongside it , from the URL. I have several whiskies with the same names and want to show the price changes over the years. My current code is as below , but at the moment it is just showing one date , name and price. I am happy to show the one name at the top, but I would like to show all the prices and dates. if (isset($_GET['id'])) { $sql = "SELECT date , name , price FROM test_db WHERE name = :id ORDER BY name ASC"; $stmt = $conn->prepare($sql); $stmt->execute( [ 'id' => $_GET['id'] ] ); $row = $stmt->fetch(); echo "<div class='details'>"; echo "<br>"; echo $row['name']; echo "<br><br>"; echo $row ['date']; echo"<br><br>"; echo " £"; echo floor ($row ['price']); echo "<br>"; echo "<br>"; echo "<br>"; echo "</div>";
-
Hi everyone, first time poster. Hope this is ok. I have a table that has 100's of car records. I am creating a form where the dropdown list option selected will sort them into groups of 4 cars based on their year and make. After this the groups will need to have a group id (For example NIS1101). The first 3 letters are the make of the car, first two numbers are the year and the last numbers are the group number. Hope this isn't confusing. How would you sort and allocate a group id to each group? Would it be best to ORDER BY or GROUP BY then make a function to allocate this id? I'm not sure how I would go about this. I appreciate any help I could get. Thanks in advance CREATE TABLE cars ( CarID int (10), Make varchar (255), Model varchar(255), Year varchar(4), EngineSize varchar ( , ); Example Data CarID , Make , Model , Year , EngineSize 16528454, Toyota, Prius, 2007 1.8 45619810, Toyota, AE-86, 2012, 2.0 32541811, Nissan, Skyline, 2008, 3.0 25856181, Mitsubishi, Nimbus, 2000, 2.4 29519815, Toyota, Celica, 2007, 1.8 16916598, Holden, Barina, 2011, 1.6 65619818, Mitsubishi, Evolution, 2008, 2.4 15616518, Holden, Commoodore, 2011, 6.0 Group Data (based on group of 4) GroupID , Make , Model , Year , EngineSize TOY101, Toyota, Prius, 2013, 1.8 TOY101, Toyota, AE-86, 2013, 2.0 TOY101, Toyota, Celica, 2013, 1.8 TOY101, Toyota, Prius, 2012, 1.8 TOY102, Toyota, AE-86, 2012, 2.0 TOY102, Toyota, Celica, 2012, 1.8 NIS201, Nissan, Skyline, 2013, 3.0 NIS201, Nissan, Skyline, 2013, 3.0 NIS201, Nissan, Silvia, 2013, 2.0 NIS201, Nissan, Skyline, 2013, 3.0 NIS202, Nissan, Pulsar, 2013, 2.0 NIS202, Nissan, Skyline, 2012, 3.0 NIS202, Nissan, Pulsar, 2009, 2.0 NIS202, Nissan, Skyline, 2008, 3.0 MIT301, Mitsubishi, Nimbus, 2012, 2.4 MIT301, Mitsubishi, Evolution, 2013, 2.4 MIT301, Mitsubishi, Nimbus, 2012, 2.4 MIT301, Mitsubishi, Evolution, 2008, 2.4 HOL401, Holden, Barina, 2013, 1.6 HOL401, Holden, Commoodore, 2012, 6.0 HOL401, Holden, Barina, 2011, 1.6 HOL401, Holden, Commoodore, 2011, 6.0 HOL402, Holden, Barina, 2010, 1.6 HOL402, Holden, Commoodore, 2007, 6.0
-
I have never done any calculations with sql query, so I have no idea how to do this so please help. well i have two tables acc_tbl and ledger_tbl ( screenshots ) i need to find the the difference between total debit and total credit of that particular ledger debit (Dr) and credit(Cr) everything in screenshot. All i know was to join the table and select all thr columns available.