Irish SEO,  Marketing & Webmaster Discussion

 

php question

This is a discussion on php question within the Coding Help forums, part of the Webmaster Help category; i am learning php at the moment and when i go to show a recordset if i have five records ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 17-08-2007, 09:50 AM
Frontpage User
 
Join Date: Apr 2007
Posts: 13
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Keewee6 will become famous soon enough
Default php question

i am learning php at the moment and when i go to show a recordset if i have five records in it - but it is only showing four and if add a sixth it only shows up five - why here is the code

<?php
mysql_connect("localhost", "emerald", "emerald247") or die(mysql_error());
mysql_select_db("emerald_db1") or die(mysql_error());

$query = ("SELECT * FROM names");

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);

while($row = mysql_fetch_array($result))
{
echo $row['name']. " - ". $row['surname'];
echo "<br />";
}

any help thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 17-08-2007, 10:48 AM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

try this:
PHP Code:
mysql_connect("localhost""emerald""emerald247") or die(mysql_error());
mysql_select_db("emerald_db1") or die(mysql_error());

$query = ("SELECT * FROM names"); 

$result mysql_query($query) or die(mysql_error());
$num_row mysql_num_rows($result);
  echo 
"we found $num_row records in the database<br />";
//start loop
while($row mysql_fetch_array($result)){
  echo 
$row['name']. " - "$row['surname']. "<br />";
}
//end while 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 17-08-2007, 12:51 PM
Forbairt's Avatar
respect my AW-THOR-IT-AYY
Recent Blog: Geansai Gorm
 
Join Date: Jun 2007
Location: My Office, Dublin
Posts: 2,101
Nominated 2 Times in 1 Post
Nominated TOTW/F/M Award(s): 1
Forbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enoughForbairt will become famous soon enough
Send a message via AIM to Forbairt Send a message via MSN to Forbairt Send a message via Yahoo to Forbairt Send a message via Skype™ to Forbairt
Default

$row = mysql_fetch_array($result);

while($row = mysql_fetch_array($result))

You've already pulled one row out ... then you start into your while loop and you're pulling the second ...

so get rid of your first $row = mysql_fetch_array($result);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
php, question

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
PHP includes - correct formatting EdenWeb Coding Help 6 16-08-2007 12:02 AM
HELP :: PHP regular expression question littleBird Coding Help 3 13-03-2007 10:33 PM
WTF - Some PHP Obfuscation. daviddoran General Chat 8 20-02-2007 05:45 PM
Bandwidth question JamesA Webmaster Discussion 4 28-01-2007 10:56 AM
PHP on windows louie Coding Help 20 22-02-2006 06:25 PM


Sponsored links

Paid On Results


All times are GMT +1. The time now is 04:40 AM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.2.0