/    Sign up×
Community /Pin to ProfileBookmark

script not print all of the information

[code=php]<?
$conn = mysql_connect(“xxxxx”,”xxxxx”,”xxxxx”);
$db = mysql_select_db(“xxxxxx”);
$query = ‘SELECT * FROM `news` ORDER BY `date` DESC;’;
$results = mysql_query($query);
$rows = mysql_fetch_array($results);
while ($rows = mysql_fetch_array($results)) {
echo $rows[‘date’]; print”<br>”;
echo $rows[‘message’];print”<br><br>”;} ?>[/code]

That script prints the first two entries in the database but not the third anyone have an idea why?

Its the script to load the news column on the site below and it does print the first two.
[url]http://dbzwars.freelinuxhost.com/[/url]

id date message

1 2004-09-23 Site Development Has Begun!
2 2004-09-24 Hopefully setting up the database, login scripts, …
3 2004-09-25 I have found a new host and have set up there. I f…

thats whats in the database

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Paul_JrSep 26.2004 — [font=palatino linotype]Try removing the line [i]$rows = mysql_fetch_array($results);[/i] (this is the line that is right before your [i]while[/i] loop). The reason being is that when calling [url=http://www.php.net/mysql-fetch-array]mysql_fetch_array();[/url] each subsequent call will return the next row of data. So what I think is that your first call, which does basically nothing, is returning the first row, which you do nothing with, and the subsequent calls in the [i]while[/i] loop are returning the last two rows.[/font]
[code=php]
<?
$conn = mysql_connect("xxxxx","xxxxx","xxxxx");
$db = mysql_select_db("xxxxxx");
$query = 'SELECT * FROM news ORDER BY date DESC;';
$results = mysql_query($query);
while ($rows = mysql_fetch_array($results)) {

echo $rows['date']; print"<br>";
echo $rows['message'];print"<br><br>";} ?>
[/code]
Copy linkTweet thisAlerts:
@daveyauthorSep 26.2004 — thank you for the help
Copy linkTweet thisAlerts:
@Paul_JrSep 26.2004 — [i]Originally posted by davey [/i]

[B]thank you for the help [/B][/QUOTE]

[font=palatino linotype]You&#8217;re welcome. ? I take it the script works now, yes?[/font]
Copy linkTweet thisAlerts:
@daveyauthorSep 26.2004 — yes it works
×

Success!

Help @davey 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.18,
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,
)...