lill77 Posted November 25, 2008 Share Posted November 25, 2008 Hello Im trying to find the best way to pull in products by category into my page. i have the following code is this the best way or correct ? thanks <?php include 'admin/db.php'; include 'header-home.php'; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM `category` ORDER BY 'CAT' ASC"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another while($row = mysql_fetch_array($result)) { echo "<tr><td align='left' valign='top'><a href='search.php?cat=$row[iD]'>$row[CAT]</a> </tr>"; } } else { // no // print status message echo "<p align='center'><font color='#808080' face='Arial'>No records found.</font></p>"; } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 Does it work? Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 25, 2008 Author Share Posted November 25, 2008 Hello does not seem to!! Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 25, 2008 Share Posted November 25, 2008 What is/is not happening compared to what you want to happen? You state you want a list of products, but it appears the query is only pulling the categories. Although I see what appears to be an error in that. There are strait, single quotes around the field name in the ORDER BY parameter. I'm pretty sure it should be using the slanted quotes. $query = "SELECT * FROM `category` ORDER BY `CAT` ASC"; Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 25, 2008 Author Share Posted November 25, 2008 Hello I think i want to display the products maybe 4 across the page and list by abc . . . Thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.