travisco87 Posted December 11, 2014 Share Posted December 11, 2014 I have been working on a blog program with a tag system. When I add tags and ask to display them to a certain webpage they all appear on my WAMP environment but not my live server. Any thoughts as to why this might be? Here is the code needed to display the tags. I am not sure if maybe live servers have restrictions that might be stopping it from displaying. This is on the main page to display the tags. <div class="widget"> <?php echo '<h2>Tags</h2>'; echo '<ul>'; getTagCount($DBH); echo '</ul>'; ?> </div> Next here is the function from the includes file. function getTagCount($DBH) { //Make the connection and grab all the tag's TAG TABLE HAS TWO FIELDS id and name $stmt = $DBH->query("SELECT * FROM tags"); $stmt->execute(); $result = array(); $result = $stmt->fetchAll(); //For each row pulled do the following foreach ($result as $row){ //set the tagId and tagName to the id and name fields from the tags table $tagId = $row['id']; $tagName = ucfirst($row['name']); //Next grab the list of used tags BLOG_POST_TAGS TABLE HAS TWO FILEDS blog_post_id and tag_id $stmt2 = $DBH->query("SELECT count(*) FROM blog_post_tags WHERE tag_id = " . $tagId); $stmt2->execute(); $tagCount = $stmt2->fetchColumn(); //Print the following list echo '<li><a href="blog_tags.php?tagId=' . $tagId . '"title="' . $tagName . '">' . $tagName . '(' . $tagCount . ')</a></li></form>'; //End of loop - start again } } The "tags" database is structured like so id, name The "blog_post_tags" is structured like so, blog_post_id, tag_id On the WAMP server it returns all of tags while the live server only returns the first one. Any suggestions on what is going on? If you need any other info please let me know. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted December 11, 2014 Share Posted December 11, 2014 other than a mismatched closing </form> tag (there's no opening <form> tag in sight) being output inside of a loop and running queries inside of that same loop, there's nothing obviously wrong. it would help if you did a 'view source' of the page in your browser, on both systems, so that you could tell what the actual html looks like. perhaps some broken html is hiding the results in the source on the page and causing the content to not be displayed. have you validated the resulting html page at validator.w3.org so that you know if the html is all valid? it would also help if you looked in your database table using a tool like phpmyadmin on your live server to conform you actually have the data that you think. 1 Quote Link to comment Share on other sites More sharing options...
travisco87 Posted December 12, 2014 Author Share Posted December 12, 2014 Ok looking over both sources I found that the live server stops and does not load the rest of the page. I ran it through the validation site and think I found the error. Line 127, column 74: Element input not allowed as child of element ul in this context. (Suppressing further errors from this subtree.) <input id="newsbutton" type="submit" name="Submit" value="Signup"> This is the section directly above it. Quote Link to comment Share on other sites More sharing options...
travisco87 Posted December 12, 2014 Author Share Posted December 12, 2014 I have even copied the database from my live server to my local server and the information is there. Somehow it is just stopping the query and not loading the rest of the page. Quote Link to comment Share on other sites More sharing options...
hansford Posted December 12, 2014 Share Posted December 12, 2014 (edited) You just found your answer from validation. <input id="newsbutton" type="submit" name="Submit" value="Signup"> </ul> </form> You can't put a submit button in an Unordered list as a child element as it is expecting a list element. Place it after the Unordered list. Edited December 12, 2014 by hansford Quote Link to comment Share on other sites More sharing options...
travisco87 Posted December 12, 2014 Author Share Posted December 12, 2014 Made the correct changes but it still stops at the first tag. Again on my WAMP server it is just fine, it is the live server that is having the problem. I use BlueHost, are there server settings that can limit the amount of information you can pull? Quote Link to comment Share on other sites More sharing options...
Solution travisco87 Posted December 12, 2014 Author Solution Share Posted December 12, 2014 FOUND IT!!! ok so the issue was with my calling statement with PDO::fetchColumn. I did a little more research and found that this is what you need to use to count elements in MySQL. Instead of this //Next grab the list of used tags BLOG_POST_TAGS TABLE HAS TWO FILEDS blog_post_id and tag_id $stmt2 = $DBH->query("SELECT count(*) FROM blog_post_tags WHERE tag_id = " . $tagId); $stmt2->execute(); $tagCount = $stmt2->fetchColumn(); I used this and it fixed my issue. $tagCount = $DBH->query("SELECT count(*) FROM blog_post_tags WHERE tag_id = " . $tagId)->fetchColumn(); Thank you guys for all your help, I learned a couple new features such as validator.w3.org and about using PDO statements. Keep it up! Quote Link to comment Share on other sites More sharing options...
hansford Posted December 12, 2014 Share Posted December 12, 2014 Congratulation Travisco87 - you kept working the problem. We can only assist with what we see code-wise. We cannot see your environment and anything you don't show us. You have a good future because you keep working the problem regardless. 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.