jacko_162 Posted February 13, 2011 Share Posted February 13, 2011 i have the following code: <?php session_start(); include "connect.php"; $queryFinished = mysql_query("SELECT * FROM `finished` ORDER BY auctionID DESC LIMIT 10;") or die(mysql_error()); $queryAdmin = mysql_query("SELECT maxClosed FROM `admin`;") or die(mysql_error()); //echo $queryAuctionID." = Auction ID<br />"; $username = mysql_fetch_assoc($queryFinished); $queryShip = mysql_query("SELECT * FROM ships WHERE typeName='$username[itemName]';") or die(mysql_error()); $getShip = mysql_fetch_assoc($queryShip); $shipID = $getShip[typeID]; echo "<img src='http://image.eveonline.com/Character/".$username[charid]."_32.jpg'> <span class='eveyellow'>".$username[username]."</span> has won a <img src='/images/types/shiptypes_png/32_32/".$shipID.".png'/> ".$username[itemName]." with ticket number #".$username[ticketNumber]."<br />"; ?> it basically lists the most recent auctions that have won, but even though i set the query to LIMIT by 10 it still only shows the 1? is something above sticking out to anyone? i know it looks messy but im still learning. Link to comment https://forums.phpfreaks.com/topic/227556-sql-query-only-showing-1-row/ Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2011 Share Posted February 13, 2011 You aren't looping through the results by having your fetch in a while loop. Link to comment https://forums.phpfreaks.com/topic/227556-sql-query-only-showing-1-row/#findComment-1173774 Share on other sites More sharing options...
jacko_162 Posted February 13, 2011 Author Share Posted February 13, 2011 ok how do i loop the fetch? Link to comment https://forums.phpfreaks.com/topic/227556-sql-query-only-showing-1-row/#findComment-1173776 Share on other sites More sharing options...
cunoodle2 Posted February 13, 2011 Share Posted February 13, 2011 Try google. Do a search for.. "using mysql_fetch_assoc to loop" The first result is from the manual.. http://php.net/manual/en/function.mysql-fetch-assoc.php Scrolling town a little but will show you "Example 1" In there is the following code.. <?php $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result); ?> Link to comment https://forums.phpfreaks.com/topic/227556-sql-query-only-showing-1-row/#findComment-1173778 Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2011 Share Posted February 13, 2011 Posting from phone, so pardon my brevity, but . . . while( $array = mysql_fetch_assoc($result) ) { // action to be performed for each record returned. } [/code] Link to comment https://forums.phpfreaks.com/topic/227556-sql-query-only-showing-1-row/#findComment-1173779 Share on other sites More sharing options...
jacko_162 Posted February 13, 2011 Author Share Posted February 13, 2011 thanks guys, problem solved =) Link to comment https://forums.phpfreaks.com/topic/227556-sql-query-only-showing-1-row/#findComment-1173785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.