We had been to create the MySQL database and we wrote a draft page to manage the change of a single article. In this lesson we will create the list of goods for storage in the database MySQL, to extract the data we will use our class CMySQL created in the course of PHP that we have attended in the past (at least I hope they have attended, in case you are looking in the blog) . Build such a thing:
Obviously I manually entered 3 items in the table and then I wrote them on a page, let’s see how I did:
<html> <head><title>Items List</title></head> <?php include_once("../utility/mysqlconn.php"); include_once("../utility/mysql.php"); $strSQL = "SELECT items.IDTem, items.CodInt, items.BarCode, items.Description, "; $strSQL .= "unimis.Sign, categories.Category, items.Price "; $strSQL .= "FROM (items LEFT JOIN unimis ON items.IDUM = unimis.IDUM) "; $strSQL .= "LEFT JOIN categories ON items.IDCategory = categories.IDCategory "; $strSQL .= "ORDER BY items.Description, items.BarCode, items.CodInt"; $items = new CMySQL($hostname, $username, $password, $database); $items->OpenRowset($strSQL); ?> <body> <h1 align="center"><b>Cerberus</b></h1> <h2 align="center"><b>Items List</b></h2> <br><br> <table width="800" align="center" cellpadding="0" border="1" cellspacing="0"> <tr> <td width="100" height="50" align="center" valign="middle" bgcolor="eeeeee" style="color:#444444;font-family:trebuchet,Tahoma, Verdana;font-size:14px;font-weight:bold"> Code </td> <td width="100" height="50" align="center" valign="middle" bgcolor="eeeeee" style="color:#444444;font-family:trebuchet,Tahoma, Verdana;font-size:14px;font-weight:bold"> BarCode </td> <td width="200" height="50" align="center" valign="middle" bgcolor="eeeeee" style="color:#444444;font-family:trebuchet,Tahoma, Verdana;font-size:14px;font-weight:bold"> Item </td> <td width="200" height="50" align="center" valign="middle" bgcolor="eeeeee" style="color:#444444;font-family:trebuchet,Tahoma, Verdana;font-size:14px;font-weight:bold"> Category </td> <td width="150" height="50" align="center" valign="middle" bgcolor="eeeeee" style="color:#444444;font-family:trebuchet,Tahoma, Verdana;font-size:14px;font-weight:bold"> Price </td> <td width="100" bgcolor="eeeeee"> </td> </tr> <?php do { if ($items->GetData("Description") != NULL) { echo '<tr>'; echo '<td height="30" valign="middle" style="color:#444444;font-family:trebuchet,Tahoma, Verdana;font-size:12px;font-weight:normal">'; echo ' '.$items->GetData("CodInt").'</td>'; echo '<td valign="middle" style="color:#444444; font-family:trebuchet,Tahoma,Verdana;font-size:12px; font-weight:normal">'; echo ' '.$items->GetData("BarCode").'</td>'; echo '<td valign="middle" style="color:#444444; font-family:trebuchet,Tahoma,Verdana;font-size:12px; font-weight:normal">'; echo ' '.$items->GetData("Description").'</td>'; echo '<td valign="middle" style="color:#444444; font-family:trebuchet,Tahoma,Verdana;font-size:12px; font-weight:normal">'; echo ' '.$items->GetData("Category").'</td>'; echo '<td valign="middle" style="color:#444444; font-family:trebuchet,Tahoma,Verdana;font-size:12px; font-weight:normal">'; echo ' €. '.number_format( $items->GetData("Price"), 2, ",", ".").'</td>'; echo '<td align="center" valign="middle"> <img src="../immagini/delete.gif"> <img src="../immagini/edit.gif"></td>'; echo '</tr>'; } } while ($items->MoveNext()); ?> </table> </body> </html>
As always I tried to do my best to insert the code with the correct indentation, but I hope you understand, however, where eliminating sending. If you followed my courses definitely will too understand the query with the join.
As you can see from the code, with the use of our class is very easy to extract data from the database, I do not think there are problems in implementing a similar page in PHP.
In the next lesson we will cover include paging, see for example, only 20 rows at a time. In other lessons allow to delete the row and change the values.