jodyanne Posted November 10, 2009 Share Posted November 10, 2009 Hello, I am having trouble as i am new to php. I have connected to the database and I have displayed the fields i want on my page. I need to access certain fields by links to each letter. For example A will link to the products starting with A and so on. I am using PHP ad MySQL. The database is however on a different server. I only have the .php file at the moment and want to display the data on a HTML page. I am just unsure of how to make a link to the product field and the price field and display them within a table. My code is this so far.. <?php // Connect to the database server mysql_connect("host", "username", "psssword") or die(mysql_error()); // Open to the database mysql_select_db("telephon_cscartrestore") or die(mysql_error()); //select records from table $result = mysql_query("SELECT cscart_product_descriptions.product, cscart_product_prices.price FROM cscart_product_descriptions, cscart_product_prices ORDER BY cscart_product_descriptions.product ASC") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Product</th> <th>Price</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['product']; echo "</td><td>"; echo $row['price']; echo "</td></tr>"; } echo "</table>"; ?> I want a link 'A' that opens all records starting in A and so on. Is this possible? thanks in advance Link to comment https://forums.phpfreaks.com/topic/180943-hyperlink-in-php-to-mysql-record/ Share on other sites More sharing options...
Zyx Posted November 10, 2009 Share Posted November 10, 2009 Yes, it is possible. The best way is to store the letter in an extra field, put an index on it and simply add an extra condition: AND `letter` = 'A' If you can't do it for some reason, then you must use LIKE clause: AND `title` LIKE 'A%' Anyway, for performance reasons, you really should an index to the title field, too. Link to comment https://forums.phpfreaks.com/topic/180943-hyperlink-in-php-to-mysql-record/#findComment-954630 Share on other sites More sharing options...
Mchl Posted November 10, 2009 Share Posted November 10, 2009 Yes, it is possible. The best way is to store the letter in an extra field, put an index on it and simply add an extra condition: I'll disagree that this is the best way Link to comment https://forums.phpfreaks.com/topic/180943-hyperlink-in-php-to-mysql-record/#findComment-954694 Share on other sites More sharing options...
Adam Posted November 10, 2009 Share Posted November 10, 2009 I agree. Using a function like LEFT() would be faster than LIKE. For example: where left(field_name, 1) = 'A' Link to comment https://forums.phpfreaks.com/topic/180943-hyperlink-in-php-to-mysql-record/#findComment-954703 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.