Jump to content

[SOLVED] Code not working and no idea why!


LiamH

Recommended Posts

Hi all.

 

I have one bit of code that isn't working, and I have no idea why. It's for some reason not publishing the results from the table.

 

It's basically an article page. The article details publish with no problem in the main content area. But the content div to the left of it, for some reason won't publish the results from the table. Any ideas why?

 

<?php

       //this bit works

// see if any rows were returned
if (mysql_num_rows($result) > 0) {

	// if rows are returned, print them
	while($row = mysql_fetch_assoc($result)) {
	echo stripslashes("<div class='headline_text' id='headline_text'>".$row['Headline']."</div>");
	echo stripslashes("<div class='headline_preview' id='headline_preview'>".$row['ReviewPreview']."</div>");
	echo stripslashes("<div class='date_author' id='date_author'>".$row['Date']." by ".$row['Name']."</div>");
	echo stripslashes("<div class='article_image' id='article_image'><img src=".$row['ReviewImage']." alt=".$row['Headline']." width='550px' height='280px'></div>");
	echo stripslashes("<div class='article_text' id='article_text'>".$row['ReviewBody']."</div>");		
}

}

    
   	echo "</div>";
   	
   	echo "<div class='game_info' id='game_info'>";
     	echo "<div class='more_holder' id='more_holder'>";
     	

     	
     // but this bit doesn't work for some reason
// see if any rows were returned from the headline only query
if (mysql_num_rows($result) > 0) {

// if rows are returned
	while($row = mysql_fetch_assoc($result)) {

		echo stripslashes("".$row['Title']."");
		}
		echo "</div>";
		}
?>

</div>

 

Any ideas where I have gone wrong? It renders the page, but just doesn't display the data like it can't find anything

Link to comment
Share on other sites

have u filled the variables in your query and tried running it in phpMyAdmin with the sql tab?

 

and is there anything in your results?

 

do

 


$ok=mysql_num_rows($result);

echo "$ok";

 

right before that if check you have

 

A number 1 appears

Link to comment
Share on other sites

1. try running it in the sql tab of your DB.

 

2. try getting rid of the if statement, unless you are 100% sure it is passing

 

3. try getting rid of the stripslashes. I've never seen them used like that after an echo so i dont know if and how they'd impact your results.

 

4. try putting $row=mysql_fetch_assoc outside a while and just print_r($row); or, just put the print_r right after the while starts

Link to comment
Share on other sites

Define: Nothing appears?

 

A blank page? The first while() loop produces the expected results but the second one produces an empty <div></div>?

 

We only see the information you provide in your post, you must be specific about what you see in front of you to get any help with it.

 

If you are getting the expected results from the first while() loop, the line of code that sasa posted will reset the data pointer back to the beginning and the second while() loop will output any $row['Title'] values that exist. Are you sure the column name is Title? Are you sure there is data in the column in the database?

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.