Jump to content

display text based on the value from the DB


Thunder_Wolf

Recommended Posts

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);
}
?>	

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.