LiamH Posted July 6, 2009 Share Posted July 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 where is your $result=mysql_query("SELECT * FROM `db` WHERE 1"); ??? Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869663 Share on other sites More sharing options...
LiamH Posted July 6, 2009 Author Share Posted July 6, 2009 It's at the top of the page. The two sections use the same query and the article body area works. I've tried it with a separate query and still get the same result Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869665 Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869666 Share on other sites More sharing options...
LiamH Posted July 6, 2009 Author Share Posted July 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869668 Share on other sites More sharing options...
sasa Posted July 6, 2009 Share Posted July 6, 2009 insert mysql_data_seek($result,0); before 2nd while loop Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869671 Share on other sites More sharing options...
LiamH Posted July 6, 2009 Author Share Posted July 6, 2009 Nothing appears Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869673 Share on other sites More sharing options...
LiamH Posted July 6, 2009 Author Share Posted July 6, 2009 Does anyone have any idea? Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869683 Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869690 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2009 Share Posted July 6, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869698 Share on other sites More sharing options...
LiamH Posted July 6, 2009 Author Share Posted July 6, 2009 Sorry guys, I put the code from sasa in the wrong place. It works now. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/164923-solved-code-not-working-and-no-idea-why/#findComment-869703 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.