Hi all,

I have a query to return only 10 records:

$result = mysql_query ("SELECT * FROM sm_Solves ORDER BY solved_stamp DESC LIMIT 10;") or die ("error in query. ".mysql_error());

In this table, the "solved_stamp" is a timestamp result and there is a field called "username". I want to take the result of my query, set the FIRST record's "username" and set it to a variable:

$Auto1 = RECORD1_Username

Then display the remaining records to a variable in a numbered list:

$Auto2_9 = 
2. RECORD2_Username <br_/>
3. RECORD3_Username <br_/>
4. RECORD4_Username <br_/>
5. RECORD5_Username <br_/>
6. RECORD6_Username <br_/>
7. RECORD7_Username <br_/>
8. RECORD8_Username <br_/>
9. RECORD9_Username

I would like to a take into account that there may be LESS than 10 records found and possiblly NO RECORDS found (producing no code).

Appreciate any help anyone can offer ;-)

if ($result) {
    echo '<ol>';
    while ($row = mysql_fetch_assoc($result)) {
        echo '<li>' . $row['username'] . '</li>';
    }
    echo '</ol>';
}
else {
    echo 'no records found';
}
if ($result) {
    echo '<ol>';
    while ($row = mysql_fetch_assoc($result)) {
        echo '<li>' . $row['username'] . '</li>';
    }
    echo '</ol>';
}
else {
    echo 'no records found';
}

This works perfectly on the HTML side but I was hoping to get them into Variables and use the variables in my HTML.

I want to the first line's Username in a variable called $Auto1 and then line 2 thru 9 lines Username looking like this:

$Auto2_9 =
2 Username2
3 Username3
4 Username4
etc...

Thanks!

<?php
$result = array("user1","user2","user3","user4","user5","user6");
$user1 = $result[0];
for($i=1;$i < count($result);$i++)
{
    $userall[] = $result[$i]."<br>";
}
?>

Take this as an example and try to solve urz

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.