Julian Posted November 14, 2006 Share Posted November 14, 2006 Hi Guys I have this query: $colname_prices = "1"; if (isset($_GET['id_sub'])) { $colname_prices = (get_magic_quotes_gpc()) ? $_GET['id_sub'] : addslashes($_GET['id_sub']); } mysql_select_db($database_bb, $bb); $query_prices = sprintf("SELECT * FROM prices WHERE id_sub = %s", $colname_prices); $prices = mysql_query($query_prices, $bb) or die(mysql_error()); $row_prices = mysql_fetch_assoc($prices); $totalRows_prices = mysql_num_rows($prices); When I call results from this query I do this: <?php echo $row_prices['price']; ?> Here's my problem: id_sub can be associated several times to the same id number(e.g. 4). What changes is the price column. I want to retrieve the price info in different parts of the page (e.g. Price 1: xxxx, then Price 2: xxxx). But when call the DB it show me only the first record. Any help will be appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/27264-obtain-mysql-different-results/ Share on other sites More sharing options...
marcus Posted November 14, 2006 Share Posted November 14, 2006 add this[code]while($row1 = mysql_fetch_assoc($prices)){echo "$row1[price], $row1[otherfield], $row1[anotherfield]";};mysql_free_result($prices);[/code]it should show all the records from 1-# Link to comment https://forums.phpfreaks.com/topic/27264-obtain-mysql-different-results/#findComment-124667 Share on other sites More sharing options...
Julian Posted November 14, 2006 Author Share Posted November 14, 2006 The problem is that I have the same field. Here's the database:| id_prices | id_sub | rate_type | rates_from || 1 | 4 | 1 | 500 || 2 | 4 | 2 | 540 || 3 | 4 | 3 | 600 |I want to retrieve all the rows from "rates_from" when id_sub =4In different parts of the page. Like on the top rate_type 1, on the bottom rate_type 3....Thanks again Link to comment https://forums.phpfreaks.com/topic/27264-obtain-mysql-different-results/#findComment-124676 Share on other sites More sharing options...
marcus Posted November 14, 2006 Share Posted November 14, 2006 Alright[code]$query_prices = sprintf("SELECT * FROM prices WHERE id_sub = %s ORDER BY `rate_type` ASC", $colname_prices);[/code] Link to comment https://forums.phpfreaks.com/topic/27264-obtain-mysql-different-results/#findComment-124677 Share on other sites More sharing options...
Julian Posted November 14, 2006 Author Share Posted November 14, 2006 Thanks mgallforeverI'm sorry for being so dumb....But I'm still don't get it.I'm using: <?php echo $row_prices['rates_from']; ?> for price #1 (rate_type = 1)What do I use to get price #2 (On the table 540)(rate_type = 3) and so on...Thanks Link to comment https://forums.phpfreaks.com/topic/27264-obtain-mysql-different-results/#findComment-124681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.