Jump to content

2nd Query Wont Display


Levr0x0rz

Recommended Posts

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

Edited by Levr0x0rz
Link to comment
Share on other sites

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???

Edited by jcbones
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.