Thunder_Wolf Posted October 22, 2014 Share Posted October 22, 2014 (edited) Hello, I have started a DB for simple web based inventory system, I have only dabbled in PHP before 6 weeks ago, within the last 6 weeks with some help and going through countless tutorials and asking questions when I need. At this time setup an insert, delete and update function for this db and are working perfectly, now what I need to know is there a way to display something like 'in stock' and 'out of stock' using php, based on the value of the quantity in my db next to the item in a table? Example : when the table is generated it will display: | Part number | Description | Stock | (normally Stock would show the quantity of each part, I just wish to |10-1111 | Some info | In Stock | display In or out os stock) |10-1112 | Some Info | Out of Stock | I the only code I have is the tables and just not sure what to do next to get the results I have described above. So I will include the table code I have and see where we can go from there. Or if you have some webs site that I can read through that will be great as well as long as it can give me basic instruction on how to do this. Reminder, I am self taught and still learning. <?php $con = mysqli_connect("localhost","user","pass","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20"); echo "<table border='1'> <tr> <th>ID</th> <th>Part number</th> <th>description</th> <th>location</th> <th>Quantity</th> </tr>"; while ($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['amp20ptid'] . "</td>"; echo "<td>" . $row['partnum'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $row['location'] . "</td>"; echo "<td>" . $row['quantity'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); } ?> Edited October 22, 2014 by Thunder_Wolf Quote Link to comment Share on other sites More sharing options...
Solution NotionCommotion Posted October 22, 2014 Solution Share Posted October 22, 2014 What about the following? Also, you might wish to consider a template engine like Twig. echo "<td>" . ($row['quantity']?'In Stock':'Out of Stock') . "</td>"; Quote Link to comment Share on other sites More sharing options...
Thunder_Wolf Posted October 22, 2014 Author Share Posted October 22, 2014 (edited) Thank you very much that looks like its working like l need it to, would you suggest any other tutorials and web pages that will increase my knowledge? I still plan on reading through a few more php web pages. so any suggestions are always welcome and thank you again. that answer was very simple. I will be checking out tiig as well Edited October 22, 2014 by Thunder_Wolf Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted October 22, 2014 Share Posted October 22, 2014 Start using PDO for your database interface. Also, try to separate your HTML generation and your database and logic. OOP makes it a little more straight forward, but isn't necessary. Quote Link to comment Share on other sites More sharing options...
Thunder_Wolf Posted October 22, 2014 Author Share Posted October 22, 2014 ok thank you again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.