/    Sign up×
Community /Pin to ProfileBookmark

Displaying only one row from a database

I have a number of different php pages. Each one I want to load a different row from the same table in a database.

I am currently using:

[code=php]
<?php
$con = mysql_connect(“localhost”,”root”,”apple123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“silent-auction”, $con);

$result = mysql_query(“SELECT * FROM lots LIMIT 1”);
mysql_data_seek($result,2);

while($row = mysql_fetch_array($result))
{
echo “<p>Lot Number:” . $row[‘lot-number’] . “</p>”;
echo “<p>Bid: £” . $row[‘bid’] . “</p>”;
}

mysql_close($con);
?>
[/code]

This works fine for the first page, just displaying the first row in the table.
The second and thrid pages contiue to only show the first row from the database, but with the following error:

[CODE]Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 2 is invalid for MySQL result index 3 (or the query data is unbuffered) in C:Program Filesxampphtdocssilent-auction3.php on line 22[/CODE]

Anyone have any ideas?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 17.2011 — Add your offset to the LIMIT clause of your query instead of trying to do a data_seek.
<i>
</i>. . . LIMIT 1 OFFSET 2

Also, if applicable, I'd recommend using an ORDER BY clause in the query, as with no ORDER BY, you are not 100&#37; guaranteed it will sort the same each time.
×

Success!

Help @gromituk2k 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.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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