/    Sign up×
Community /Pin to ProfileBookmark

Read MySQL table from bottom/insert into table at beginning

Hi,

I have a WHILE loop that reads out info from all the rows in a MySQL table, but it reads it from top to bottom, therefore the newest information in the table (which gets inserted at the bottom) is read last and end up at the bottom of my readout page. I’m trying to either read the table from bottom to top, or insert new information at the beginning of the table (preferably the former). I have a field called ‘chron’ with an auto-incrementing MEDINT if that matters.

Here’s the while loop:

[code=php]
$query = “SELECT name, date_q, question, date_a, answer FROM $table”;
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo “<tr>
<th>{$row[‘name’]}:<br><h5>{$row[‘date_q’]}</h5></th>
<td>{$row[‘question’]}</td>
</tr>
<tr bgcolor=”#e5e5e5″>
<th>Chef Roy Answered:<br><h5>{$row[‘date_a’]}</h5></th>
<td>{$row[‘answer’]}</td>
</tr>
<tr><td white=”yes” colspan=”2″></td></tr>”;
}

[/code]

Thank you!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bokehJun 05.2009 — [CODE]ORDER BY $primary_key DESC[/CODE]
×

Success!

Help @juststranded spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...