Levr0x0rz Posted July 1, 2013 Share Posted July 1, 2013 Hello, I've been a few years remove from working with PHP & MySQL, and even then I would only consider my skill a 2 of 10, but I've decided to get back into it. I'm able to get a query to display on my page for navigation of the page, but when I try to pull data for a new post, nothing posts, but also no error. Here is the code: <?php require('config.php'); ?> <div class="container"> <div class="header"> <img src="images/header.gif" alt="Veterans Of War, A Day of Defeat Squad"> </div> <div class="sidebar_left"> <table class="sidebar_left"> <tr> <td class="sidebar_header">Navigation</td> </tr> <?php // Start Navigation Data $sql = "SELECT * FROM navigation"; $result = mysql_query($sql); $row = mysql_fetch_array($result); if(mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { ?> <tr> <td class="sidebar_row"><a href="<?php echo $row['url']; ?>"><?php echo $row['text']; ?></a></td> </tr> <?php } } else { echo "No data to return"; } // End Navigation Data ?> </table> </div> <div class="content"> <table class="content"> <?php // Start News Data $sql2 = "SELECT * FROM news"; $result2 = mysql_query($sql2); $row2 = mysql_fetch_array($result2); if(mysql_num_rows($result2)) { while ($row2 = mysql_fetch_assoc($result2)) { ?> <tr> <td class="content_header"><?php echo $row2['title']; ?></td> </tr> <td class="content_highlight">Posted by <?php echo $row2['author']; ?> on <?php echo $row2['date']; ?></td> <tr> <td class="content_data"><?php echo $row2['content']; ?></td> </tr> <?php } } else { echo "No data to return"; } // End News Data ?> I changed the second query variables to things like row2 and query2, thinking running row and query was still trying to associate with the navigation pull just above it. I can't even get table row or data information to display, all that outputs is the <table> and </table>, none of the PHP or HTML within. Oddly (at least odd to me), if I change the SELECT FROM to pull from navigation, I can display info from that table. I'm working on learning more, but this I've been looking at for a good hour, and just cannot see why it won't work. Any guidance would be appreciated very much. Jon Linux Support Tech / Aspiring Web Developer Link to comment https://forums.phpfreaks.com/topic/279744-2nd-query-wont-display/ Share on other sites More sharing options...
jcbones Posted July 1, 2013 Share Posted July 1, 2013 REMOVE these 2 lines: $row = mysql_fetch_array($result); //and $row2 = mysql_fetch_array($result2); They are moving the internal index pointer to the second row. So if you only have 1 news row, then you wouldn't see it. Also, PHP will not show MySQL errors, unless you return them from the MySQL server. $result2 = mysql_query($sql2) or trigger_error(mysql_error); Finally, for safer, more secure coding, you should migrate to PDO or mysqli classes. Edit: URL BBCODE not working??? Link to comment https://forums.phpfreaks.com/topic/279744-2nd-query-wont-display/#findComment-1438755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.