Hi all,
I just recently switched over to Zen Cart from OSC and need some help getting my layout for a custom page correct. This my code so far...I starred out the db bame, user name, and pw for obvious reasons...It collates all the data correctly, but it pushes all the sideboxes and what not to the bottom of the page...
Code:<?php /* $Id: shipping.php,v 1.22 2003/06/05 23:26:23 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ ?> <html> <body> <div class="centerColumn" id="privacy"> <h1 id="privacyDefaultHeading"><?php echo HEADING_TITLE; ?></h1> <div id="privacyDefaultMainContent" class="content"> <table align="center" border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td class="main"><table align="center" border="2" cellspacing="2" cellpadding="2"> <tr align="center"> Click a column header to sort the list. <?php // Make sure you setup the links here for the sorting. // Name column if ($_GET['sort_name'] == 1) { echo '<td><strong><a href="' . zen_href_link(FILENAME_TRADE_IN_VALUES). '?sort_name=2">Name</a></strong></td>'; } else { echo '<td><strong><a href="' . zen_href_link(FILENAME_TRADE_IN_VALUES). '?sort_name=1">Name</a></strong></td>'; } // Trade-In Value column if ($_GET['sort_tradeval'] == 1) { echo '<td><strong><a href="' . zen_href_link(FILENAME_TRADE_IN_VALUES). '?sort_tradeval=2">Trade-In Value</a></strong></td>'; } else { echo '<td><strong><a href="' . zen_href_link(FILENAME_TRADE_IN_VALUES). '?sort_tradeval=1">Trade-In Value</a></strong></td>'; } //System/Platform column if ($_GET['sort_system'] == 1) { echo '<td><strong><a href="' . zen_href_link(FILENAME_TRADE_IN_VALUES). '?sort_system=2">System/Platform</a></strong></td>'; } else { echo '<td><strong><a href="' . zen_href_link(FILENAME_TRADE_IN_VALUES). '?sort_system=1">System/Platform</a></strong></td>'; } // Make a MySQL Connection mysql_connect("localhost", "****", "******") or die(mysql_error()); mysql_select_db("************") or die(mysql_error()); // Retrieve all the data from the "example" table //$result = mysql_query("SELECT * FROM zen_products") //or die(mysql_error()); // store the record of the "example" table into $row //$row = mysql_fetch_array( $result ); // Print out the contents of the entry // Retrieve all the data from the "example" table // Put the SQL Statement in a string variable since we may or may not add to it before we send it to MySQL for execution $sql_fetch_statement = "SELECT * FROM zen_products INNER JOIN zen_products_description ON zen_products.products_id = zen_products_description.products_id WHERE products_trade_in_value > 0"; // Now we check for each variable we defined in the header section of the table and add to the SQL statement as appropriate if ($_GET['sort_name'] == 1 || $_GET['sort_name'] == 2) { // 1 means ASC, 2 means DESC $sql_fetch_statement = $sql_fetch_statement . " ORDER BY products_name "; if ($_GET['sort_name'] == 2) { $sql_fetch_statement = $sql_fetch_statement . " DESC"; } } if ($_GET['sort_tradeval'] == 1 || $_GET['sort_tradeval'] == 2) { // 1 means ASC, 2 means DESC $sql_fetch_statement = $sql_fetch_statement . " ORDER BY products_trade_in_value "; if ($_GET['sort_tradeval'] == 2) { $sql_fetch_statement = $sql_fetch_statement . " DESC"; } } if ($_GET['sort_system'] == 1 || $_GET['sort_system'] == 2) { // 1 means ASC, 2 means DESC $sql_fetch_statement = $sql_fetch_statement . " ORDER BY products_system "; if ($_GET['sort_system'] == 2) { $sql_fetch_statement = $sql_fetch_statement . " DESC"; } } // Execute the query $result = mysql_query($sql_fetch_statement) or die(mysql_error()); // *** The problem here is you're trying to link information from two tables, but you're not letting the database do that for you // *** While this could work with some tweaking it is bad practice. What you need to do is come up with a single query that links // *** these two tables together in a single query. I'm not sure what your table fields are, so I'm going to just make up some field names. // *** Lets say that both the products and products_description tables have a field called productid that is used to identify what product // *** a record in that table is tied to. In that case, we would write a query like so: // *** "SELECT * FROM products INNER JOIN products_description ON products.products_id = products_description.product_id" // *** No you have a single result set where each record contains all the fields from products and all the fields from products_description // *** and you just loop through that one result set and print out the field values you want. // store the record of the "example" table into $row $row = mysql_fetch_array( $result ); // Print out the contents of the entry // *** What you're actually doing here is every time through the loop you're gettting the next row for $result2, but you're constantly reusing the 1st record from $result // *** mysql_fetch_array() actually fetches the next record from a result set (which is what's returned from a mysql_query() call) while ( $row = mysql_fetch_array( $result )) { // Start a table row tag echo "<tr align='center'>"; // Now for each column above, echo it out here: echo "<td>".$row['products_name']."</td>"; $number = $row['products_trade_in_value']; $formatted = number_format($number, 2); echo "<td>"."$" .$formatted."</td>"; echo "<td>".$row['products_system']."</td>"; // Close the Table row tag echo "</tr>"; } ?> </td></tr></table> </div></div> </body> </html> <!-- body_text_eof //-->




