Jump to content

display text based on the value from the DB


Go to solution Solved by NotionCommotion,

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

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 by Thunder_Wolf
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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