Akenatehm Posted March 14, 2009 Share Posted March 14, 2009 Hey Guys, I am trying to make a news script that echoes the results through a loop. CUrrently, nothing is coming up on the page. Here's index.php: <?php include 'functions.php'; ?> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Exclusive Mac - Home</title> <link rel="stylesheet" href="styles.css" type="text/css" /> <script type="text/javascript"> function mouseOver() { document.getElementById('entry').className = "hoverentry"; } function mouseOut() { document.getElementById('entry').className = "normalentry"; } </script> </head> <body> <div class="header"> <img src="images/header.png" alt="Header" /> </div> <ul id="nav"> <li><a href="#">Home</a></li> <li><a href="#">News</a></li> <li><a href="#">Forums</a></li> <li><a href="#">Applications</a></li> <li><a href="#">Other</a></li> </ul> <?php writeNewsEntry(); ?> </body> </html> and here's functions.php <?php function writeNewsEntry() { $user = "user"; $pass = "pass"; $host = "localhost"; $db = "exclusivemac"; $connect = mysql_connect($host,$user,$pass); $selectdatabase = mysql_select_db($db); $getentries = mysql_query("SELECT * FROM newsentries"); while($filterentries = mysql_fetch_assoc($getentries)) { $title = $filterentries['title']; $content = $filterentries['content']; $author = $filterentries['author']; $date = $filterentries['date']; echo '<div id="entry" class="normalentry" onMouseOver="mouseOver()" onMouseOut="mouseOut()">'; echo '<h3 class="newsentry">' . "$title - " . "</h3>"; echo '<p class="newsdate">' . "$date" . "</p> <br />"; echo '<p class="newsentry">' . "$content" . '</p>'; echo '<p class="newsposter">Posted By' . "$author" . "</p> </div>"; } } ?> Help Would be Appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/149349-solved-looping-and-echoing/ Share on other sites More sharing options...
fry2010 Posted March 14, 2009 Share Posted March 14, 2009 firstly putting your database connection details in that is a bad idea. Second is your while loop counting upward? what i mean is does the while loop ever end? You might want to use $i++ inside while loop. What error u getting? Quote Link to comment https://forums.phpfreaks.com/topic/149349-solved-looping-and-echoing/#findComment-784379 Share on other sites More sharing options...
Festy Posted March 14, 2009 Share Posted March 14, 2009 Second is your while loop counting upward? what i mean is does the while loop ever end? You might want to use $i++ inside while loop. What error u getting? That's being extremely ignorant. He's fetching rows from a table, so the while loop will end automatically when all the rows have fetched. Quote Link to comment https://forums.phpfreaks.com/topic/149349-solved-looping-and-echoing/#findComment-784380 Share on other sites More sharing options...
Akenatehm Posted March 14, 2009 Author Share Posted March 14, 2009 Thanks Festy. I was wondering what fry2010 was talking about? Where is a better place to connect? If I connect through another function, will it still be connected and ready to use in other functions? Or If I connect through a main php page, will that also be usable in other functions? Like I said, I am not getting errors, just blank white space with no echoed data. Quote Link to comment https://forums.phpfreaks.com/topic/149349-solved-looping-and-echoing/#findComment-784381 Share on other sites More sharing options...
Akenatehm Posted March 14, 2009 Author Share Posted March 14, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/149349-solved-looping-and-echoing/#findComment-784394 Share on other sites More sharing options...
.josh Posted March 14, 2009 Share Posted March 14, 2009 Turn your error reporting on. At the top of your page, put ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); Add ..or die(mysql_error()); to the end of all of your msql function calls. Any error messages display? The error messages from the ..die()'s are pretty straight forward. You should be able to fix it from there, no problem. If not, post the error message. No error messages? Make sure you are using the right column names when assigning the fetch_assoc array data to your "easier to handle" variables. Case sensitive!. Everything line up? Check your database directly to ensure that the data you expect to be there, is there. Run your query directly in the database. Expected info return? Still no dice? Obviously, what we have here is a case of spiderbots feasting on your data while its in transit from the db to your php script. True story. Quote Link to comment https://forums.phpfreaks.com/topic/149349-solved-looping-and-echoing/#findComment-784403 Share on other sites More sharing options...
Akenatehm Posted March 14, 2009 Author Share Posted March 14, 2009 Wow. I really am stupid LOL. I didn't have data in the DB...that was really dumb.... Thanks for your help...well making me thing about the obvious. Appreciate it. Cya Around. Quote Link to comment https://forums.phpfreaks.com/topic/149349-solved-looping-and-echoing/#findComment-784407 Share on other sites More sharing options...
fry2010 Posted March 14, 2009 Share Posted March 14, 2009 actually it wasnt ignorant because I had the problem before, the while loop didnt end even when it finished collecting data from database. What help did u offer? none. With the limited info available i offered at least some help, even if it wasnt appreciated. How stupid r u for not having any data in the database and not even realising it... Quote Link to comment https://forums.phpfreaks.com/topic/149349-solved-looping-and-echoing/#findComment-784419 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.