Jump to content

sql query only showing 1 row?


jacko_162

Recommended Posts

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

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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.