titangf Posted March 28, 2006 Share Posted March 28, 2006 I have built a database that has 5 records in it and I have successfully been able to spit that information back out into a dynamic table with one exception. Here's the problem... When the data is displayed on the page, I am missing the content from the first record and the space where the information should be filled in is instead blank. Any ideas as to why this is happening? How do I fix it?oh, if you should need the code I don't mind posting it... But for some reason i'm thinking this is an easy problem that i'm overlooking. Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 29, 2006 Share Posted March 29, 2006 Sounds like a simple error, but there are millions of ways to mess up. Post some code and we'll see if we can find any problems. Quote Link to comment Share on other sites More sharing options...
fenway Posted March 29, 2006 Share Posted March 29, 2006 Agreed -- just a shot in the dark, but leaving off the first record of a result set is usually the result (no pun intended) of inadvertently incrementing the record set pointer outside the while loop. Quote Link to comment Share on other sites More sharing options...
titangf Posted March 29, 2006 Author Share Posted March 29, 2006 Actually I'm sure that fenway is right on the money with this one. I did set the loop outside of the first record. I'm posting my code that pertains to just the PHP/MySQL work. [code]<?php require_once('connection/data_connect.php'); ?><?phpmysql_select_db(ME_test);$query_ME_test = "SELECT P_ID, P_address, P_type, P_price FROM property ORDER BY P_ID='$P_ID'";//testing connection to see if it can see the database and code that I can omit later onif (!mysql_select_db(ME_test)) { die('Could not select database');}echo 'Connection successful!';$property = mysql_query($query_ME_test) or die(mysql_error());$row_proptery = mysql_fetch_assoc($property);$totalRows_property = mysql_num_rows($property);?><?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>[/code]and skipping down to the record recalls...[code] <?php do { ?> <tr class="td"> <td><?php echo $row_property['P_ID']; ?></td> <td><?php echo $row_property['P_address']; ?></td> <td><?php echo $row_property['P_type']; ?></td> <td>$ <?php echo number_format($row_property['P_price'],0); ?></td> </tr> <?php } while ($row_property = mysql_fetch_assoc($property)); ?>[/code]Would it help to do this in a For Each statement verses the While statment? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 29, 2006 Share Posted March 29, 2006 Indeed that's the problem. That's an interesting construct -- why not use the more common:[code]while( $row_property = mysql_fetch_assoc($property) ) { # your inner loop}[/code] Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 29, 2006 Share Posted March 29, 2006 Your code would work except that you misspelled $row_property as $row_proptery.I do agree with fenway though, the do { } while (); structure you are using is unnecessary and cumbersome. Quote Link to comment Share on other sites More sharing options...
titangf Posted March 29, 2006 Author Share Posted March 29, 2006 I'm going to blame late night coding with caffeine. Yes Fenway.... this works as well... But I was in the right ballpark, lol.[code]<?php while ($row_property = mysql_fetch_assoc($property)) {?> <tr class="td"> <td><?php echo $row_property['P_ID']; ?></td> <td><?php echo $row_property['P_address']; ?></td> <td><?php echo $row_property['P_type']; ?></td> <td>$ <?php echo number_format($row_property['P_price'],0); ?></td> </tr><?php }?>[/code]Now, instead of showing an empty row for the first record, it omits it completely from the list. I believe that this problem has to deal more directly with the database. For some reason I'm getting the funny feeling that it is omitting it because it is the first entry of the database (I don't know why... just a feeling). I promise you that there are a total of 6 records (I added on recently for testing purposes)you can see for yourself (please bear in mind... this is just for playing purposes so its not pretty... just functional/disfunctional)[a href=\"http://www.tornadopixel.com/MountainEast/\" target=\"_blank\"]http://www.tornadopixel.com/MountainEast/[/a]lol, well I missed that one... Thanks for the spell check.Lesson to all to check your spellings of your variables.Unfortunately... This doesn't solve the problem I was refering to... It still does not want to display the first record. I know I can duplicate the record to make it show up, but I don't understand why its not showing. Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 29, 2006 Share Posted March 29, 2006 Did you remove the mysql_fetch_assoc() that you were doing before the loop? Quote Link to comment Share on other sites More sharing options...
titangf Posted March 29, 2006 Author Share Posted March 29, 2006 lol, well I missed that one... Thanks for the [i]spell check[/i].[b]Lesson to all to check and [i]Double Check[/i] your spellings of your variables.[/b]Unfortunately... This doesn't solve the problem I was refering to... It still does not want to display the first record. I know I can duplicate the record to make it show up, but I don't understand why its not showing.Wickning1, Thanks. That was it...Thanks to you both Fenway and Wickning1, you've both been a great help. Its all working now.Final Code as it stands[code]<?php require_once('connection/data_connect.php'); ?><?phpmysql_select_db(ME_test);$query_ME_test = "SELECT P_ID, P_address, P_type, P_price FROM property ORDER BY P_ID='$P_ID'";//testing connection to see if it can see the databaseif (!mysql_select_db(ME_test)) { die('Could not select database');}echo 'Connection successful!';$property = mysql_query($query_ME_test) or die(mysql_error());$row_property = ($property);$totalRows_property = mysql_num_rows($property);?><?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>//skip to call of records <?php while ($row_property = mysql_fetch_assoc($property)) {?> <tr class="td"> <td><?php echo $row_property['P_ID']; ?></td> <td><?php echo $row_property['P_address']; ?></td> <td><?php echo $row_property['P_type']; ?></td> <td>$ <?php echo number_format($row_property['P_price'],0); ?></td> </tr> <?php }?>[/code][!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Did you remove the mysql_fetch_assoc() that you were doing before the loop?[/quote]By getting rid of the mysql_fetch_assoc() before the loop, I now don't have that hick-up that skips the first record. Thanks again to you both. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.