Hi,

I am pretty new to HTML and brand new to PHP.
I am trying to put together a simple internal website on a Linux box to keep track of some inventory. I would like to be able to click a link in the sidebar and have it display that table from MySQL in the main div of the current page.

I am trying to set it up to where all of my queries will be in a single PHP script (right now this is php.config) and the links will have an ID that coincides with the correct select statement. Could someone offer some help? I am lost as to how I can accomplish this.

Here is the code for the index.html so far. I removed almost all of the links in the sidebar to make this easier to read.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
	
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" href="images/style.css" type="text/css" />	

<title>Inventory</title>
	
</head>

<body>
<!-- wrap starts here -->
<div id="wrap"> 

	<div id="header">	
			
		<img src="images/transparent.png" width="209" height="41" class="float-left" />
		<form method="post" class="searchform" action="search.php">
			<p><input type="text" value="I don't work yet" onfocus="if
(this.value==this.defaultValue) this.value='';" name="search_query" class="textbox" />
  			<input type="submit" name="search" class="button" value="Search" /></p>
		</form>
		
	</div>		
		
	<div id="menu">
		<ul>
			<li id="current"><a href="index.html">All</a></li>
			<li><a href="i1l2.html">I1L2</a></li>
			<li><a href="i1n2.html">I1N2</a></li>
            <li><a href="m1i2.html">M1I2</a></li>
            <li><a href="o1h2.html">O1H2</a></li>
			<li></li>
			<li></li>
			<li></li>			
		</ul>
	</div>
	
	<!-- content-wrap starts here -->	
	<div id="content-wrap">  
	
	  <div id="sidebar">
			
		<h1>I1l2</h1>
				<ul class="sidemenu">
					<li><a href="config.php?id=2">Extra</a></li>
					<li><a href="config.php?id=1">Lab</a></li>
					<li><a href="config.php?id=3">NNorth</a></li>
                    
		  <p></p>
          <ul class="sidemenu">
          </ul>
	    <p>&nbsp;</p>
				
	  </div>		
	
	  <div id="main"> 
				
				<a name="Title"></a>
				<h1>Inventory</h1>
				
				<p><strong>Description</strong> will be here.</p>
	  </div>

	  <!-- content-wrap ends here -->	
	</div>
	
<!-- wrap ends here -->
</div>		

<!-- footer starts here --><!-- footer ends here -->	

</body>
</html>

Here is the PHP script as it is right now. I only have one entry in there so far because it is no use putting them all in if they are not going to be able to work the way I want.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<br>
<body>
<br>
<?
$hostname = "xx.xx.xxx.xx";
$database = "xxxx";
$username = "xxxxxxx";
$password = "xxxxxxxxx";
mysql_connect($hostname,$username,$password) OR DIE ('Could not 
connect: ' . mysql_error());
mysql_select_db($database);
$result = mysql_query("SELECT * FROM I1L2_Lab");

echo "<table border='1'>
<tr>
<th>Slot</th>
<th>Description</th>
<th>Serial</th>
<th>Warranty</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Slot'] . "</td>";
  echo "<td>" . $row['Description'] . "</td>";
  echo "<td>" . $row['Serial'] . "</td>";
  echo "<td>" . $row['Warranty'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>
</body></html>

Recommended Answers

All 2 Replies

Since your side menu have links like xxx.php?id=x, all you need to do in your php script to get all information regarding that id is simply

$id = $_GET['id'];
$result = mysql_query("SELECT * FROM I1L2_Lab WHERE id=$id");

Assume you have a column in your database that contains the id.

I actually realized that I must have a different problem that I have to get through first. I do not have PHP installed on my windows computer. I have been doing this on a windows computer and testing it on here, then uploading to my Linux box. The problem is that when I put it on the Linux box and click a link that should pull from config.php & MySQL, I just see all of my code in the browser on a white page.

I know that PHP is installed correctly as I can do the phpinfo test just fine. So I need to figure out why it spits out my code instead of executing it...then figure out why if it was just going to spit it out, it wouldn't spit it out on the current page. Has anyone had this problem before?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.