homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Confusion with mysql data seek
None or Double items displayed

 2:33 am on Aug 30, 2006 (gmt 0)

I just keep having trouble with this... Looking for a best approach:

mysql_data_seek($ODisplay, 0);
$row_ODisplay = mysql_fetch_assoc($ODisplay);


Display Stuff here (Hopefully the real stuff) - sometimes I get a blank display sometimes I get a duplicate item
I use: echo $row_ODisplay['FieldName'];
}while($row_ODisplay = mysql_fetch_assoc($ODisplay));

Should I be using foreach{} or something else?



 2:45 am on Aug 30, 2006 (gmt 0)

Generally I do something like this:

$link = mysql_connect("localhost","user","password") or die(mysql_error());

$query = "SELECT * FROM table_name";
$result = mysql_query($query,$link) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo $row['col_name1'].'<br />'.$row['col_name2'];//etc...

You may also want to look at our library [webmasterworld.com] for some good threads on Basics of extracting data from MySQL using PHP [webmasterworld.com]

Good luck!


 2:55 am on Aug 30, 2006 (gmt 0)

Kool, but what do you do the second time/Third/etc? How do you use:

mysql_data_seek($ODisplay, 0);

I think this is the source of my problem



 4:43 pm on Aug 30, 2006 (gmt 0)

you don't need the mysql_data_seek

what eelixduppy showed will loop through each result using the

while($row = mysql_fetch_array($result)) {

if you follow his lead and get rid of the data_seek you will figure it out


 1:07 am on Aug 31, 2006 (gmt 0)

? " you don't need the mysql_data_seek"?
When I try:

while($row = mysql_fetch_array($result)) {

it skips the first item in the found set. When I use "mysql_data_seek" before the "while" I get all of them, Guess I've solved the problem, I'd just like to understand.


 7:20 pm on Aug 31, 2006 (gmt 0)

You should get all results using mysql_fetch_array unless you change the internal pointer somewhere. If you want to understand more about these two functions, read up on their documentation and look at their examples.

Go to these links:

Good luck


 1:37 pm on Sep 1, 2006 (gmt 0)

if you have it like it is in your first post with
$row_ODisplay = mysql_fetch_assoc($ODisplay);

above the loop then that is why it skipping the first row, you already grabbed it. Remove the extra mysql_fetch above the loop and it should be fine


 5:41 pm on Sep 1, 2006 (gmt 0)

How do I handle using the "mysql_data_seek($ODisplay, 0); " when I do two (or more) of the "while($row = mysql_fetch_array($result)) { ". I still miss the first row sometimes and sometimes I get a duplicate row. Should I do the data_seek before each "while"? Does it mater how I use the $total_Rows result? (I've been using it to skip the "while" with a simple "if($total_Rows <> 0){"

Thanks tons! I really feel like I am in and endless spiral!



 9:38 pm on Sep 1, 2006 (gmt 0)

yes you could do a data seek before each while, though if you need to go through the reulst more than once you could read them into an array and then walk that

you can use the total_rows to skip the while if there are no results.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved