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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.