monkeybidz Posted February 21, 2008 Share Posted February 21, 2008 How can I get information for the Var "$category" for each row from this query? <?php $query = "select id, title, pict_url, category, photo_uploaded, city_details1, city_details2, state1, state2, miles, starts from PHPAUCTIONREVERSE_auctions WHERE closed='0' AND suspended=0 AND private='n' OR private='y' AND "; if($SETTINGS['adultonly']=='y' && !isset($_SESSION["PHPAUCTION_LOGGED_IN"])){ $query .= "adultonly='n' AND "; } $query .= "starts<=".$NOW." ORDER BY starts DESC LIMIT ".$SETTINGS['lastitemsnumber']; $result = mysql_query($query); if ( $result ) $num_auction = mysql_num_rows($result); else $num_auction = 0; $i = 0; $bgcolor = "#FFFFFF"; $TPL_last_auctions_value = ""; while($i < $num_auction) { if($bgcolor == "#FFFFFF") { $bgcolor = $FONTCOLOR[$SETTINGS['headercolor']]; } else { $bgcolor = "#FFFFFF"; } $title = mysql_result($result,$i,"title"); $category = mysql_result($result,$i,"category"); $city_details1 = mysql_result($result,$i,"city_details1"); $city_details2 = mysql_result($result,$i,"city_details2"); $state1 = mysql_result($result,$i,"state1"); $state2 = mysql_result($result,$i,"state2"); $miles = mysql_result($result,$i,"miles"); $id = mysql_result($result,$i,"id"); $date = mysql_result($result,$i,"starts"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/92235-get-information-for-each-row/ Share on other sites More sharing options...
sKunKbad Posted February 21, 2008 Share Posted February 21, 2008 echo $category; ? Quote Link to comment https://forums.phpfreaks.com/topic/92235-get-information-for-each-row/#findComment-472521 Share on other sites More sharing options...
monkeybidz Posted February 21, 2008 Author Share Posted February 21, 2008 It is already echoed here, but shows the same for all rows: <?php $TPL_last_auctions_value .=" <table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"10%\" align=\"center\"><p style=\"background-color:$bgcolor;display:block\"><center>".$category."</center></td> <td align=\"left\"> $city_details1, $state1</B> - to - <B>$city_details2, $state2</B><BR> <A HREF=\"./item.php?id=$id\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/92235-get-information-for-each-row/#findComment-472522 Share on other sites More sharing options...
bpops Posted February 21, 2008 Share Posted February 21, 2008 You have to increment $i in your while statment <?php <?php $query = "select id, title, pict_url, category, photo_uploaded, city_details1, city_details2, state1, state2, miles, starts from PHPAUCTIONREVERSE_auctions WHERE closed='0' AND suspended=0 AND private='n' OR private='y' AND "; if($SETTINGS['adultonly']=='y' && !isset($_SESSION["PHPAUCTION_LOGGED_IN"])){ $query .= "adultonly='n' AND "; } $query .= "starts<=".$NOW." ORDER BY starts DESC LIMIT ".$SETTINGS['lastitemsnumber']; $result = mysql_query($query); if ( $result ) $num_auction = mysql_num_rows($result); else $num_auction = 0; $i = 0; $bgcolor = "#FFFFFF"; $TPL_last_auctions_value = ""; while($i < $num_auction) { if($bgcolor == "#FFFFFF") { $bgcolor = $FONTCOLOR[$SETTINGS['headercolor']]; } else { $bgcolor = "#FFFFFF"; } $title = mysql_result($result,$i,"title"); $category = mysql_result($result,$i,"category"); $city_details1 = mysql_result($result,$i,"city_details1"); $city_details2 = mysql_result($result,$i,"city_details2"); $state1 = mysql_result($result,$i,"state1"); $state2 = mysql_result($result,$i,"state2"); $miles = mysql_result($result,$i,"miles"); $id = mysql_result($result,$i,"id"); $date = mysql_result($result,$i,"starts"); $i++; // <------------------------------------------------ } // <------------------------------------------------ ?> Quote Link to comment https://forums.phpfreaks.com/topic/92235-get-information-for-each-row/#findComment-472523 Share on other sites More sharing options...
monkeybidz Posted February 21, 2008 Author Share Posted February 21, 2008 That didn't work either, it's already mentioned further down the code. I found the problem. Here it goes. <?php $query = "select id, title, pict_url, category, photo_uploaded, city_details1, city_details2, state1, state2, miles, starts from PHPAUCTIONREVERSE_auctions WHERE closed='0' AND suspended=0 AND private='n' OR private='y' AND "; if($SETTINGS['adultonly']=='y' && !isset($_SESSION["PHPAUCTION_LOGGED_IN"])){ $query .= "adultonly='n' AND "; } $query .= "starts<=".$NOW." ORDER BY starts DESC LIMIT ".$SETTINGS['lastitemsnumber']; $result = mysql_query($query); if ( $result ) $num_auction = mysql_num_rows($result); else $num_auction = 0; $i = 0; $bgcolor = "#FFFFFF"; $TPL_last_auctions_value .= "";// <-------- <---------- <------------ Added a preiod '.' before '=' while($i < $num_auction) { if($bgcolor == "#FFFFFF") { $bgcolor = $FONTCOLOR[$SETTINGS['headercolor']]; } else { $bgcolor = "#FFFFFF"; } $title = mysql_result($result,$i,"title"); $category = mysql_result($result,$i,"category"); $city_details1 = mysql_result($result,$i,"city_details1"); $city_details2 = mysql_result($result,$i,"city_details2"); $state1 = mysql_result($result,$i,"state1"); $state2 = mysql_result($result,$i,"state2"); $miles = mysql_result($result,$i,"miles"); $id = mysql_result($result,$i,"id"); $date = mysql_result($result,$i,"starts"); ?> Your idea of $i++ prompted me to look there and sure enough, I found the problem. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/92235-get-information-for-each-row/#findComment-472527 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.