dennismonsewicz Posted July 1, 2008 Share Posted July 1, 2008 I have a while loop that is only grabbing one entry out of the database when there are multiple that it should be grabbing... $query = mysql_query("SELECT * FROM devotionals WHERE writer = 'dennis'"); while($results = mysql_fetch_array($query)) { $devotional_query = '<li><a href="#">' . $results['devotional_title'] . '</a></li>'; } there are at least two from the writer dennis. and it is only displaying one Link to comment https://forums.phpfreaks.com/topic/112786-solved-mysql_fetch_array-only-grabbing-one-entry/ Share on other sites More sharing options...
revraz Posted July 1, 2008 Share Posted July 1, 2008 Appears you are overwriting $devotional_query with the last result. Link to comment https://forums.phpfreaks.com/topic/112786-solved-mysql_fetch_array-only-grabbing-one-entry/#findComment-579256 Share on other sites More sharing options...
dennismonsewicz Posted July 1, 2008 Author Share Posted July 1, 2008 hmmm, how do you suggest going about fixing this? Link to comment https://forums.phpfreaks.com/topic/112786-solved-mysql_fetch_array-only-grabbing-one-entry/#findComment-579261 Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Concatinate the strings: $devotional_query .= '<li><a href="#">' . $results['devotional_title'] .[...] Link to comment https://forums.phpfreaks.com/topic/112786-solved-mysql_fetch_array-only-grabbing-one-entry/#findComment-579265 Share on other sites More sharing options...
dennismonsewicz Posted July 1, 2008 Author Share Posted July 1, 2008 ok so here is all of the code I am using $query = mysql_query("SELECT * FROM devotionals WHERE writer = 'dennis'"); while($results = mysql_fetch_array($query)) { $devotional_query = '<li><a href="#">' . $results['devotional_title'] . '</a></li>'; } $login = '<a class="title">Login</a> <div> <form action="index.php?action=login" method="post"> <label>Username:</label> <input type="text" name="username" id="username" /> <label>Password: </label> <input type="password" name="password" id="password" /> <input type="image" src="images/login.jpg" id="submit" /> </form> </div>'; $logout = '<a class="title">My Profile</a> <div> <ul> <li><a href="index.php">Home</a></li> <li><a href="profile.php?tool=changepw">Change Password</a></li> <li><a href="profile.php?tool=addfriend">Signup A Friend</a></li> <li><a href="index.php?action=logout">Logout</a></li> </ul> </div> <a class="title">Devotionals</a> <div> <ul> ' . $devotional_query . ' </ul> </div> <a class="title">Topics</a> <div> <ul> <li><a href="#">Testing</a></li> </ul> </div>'; I thought I could just call the variable $devotional_query? Link to comment https://forums.phpfreaks.com/topic/112786-solved-mysql_fetch_array-only-grabbing-one-entry/#findComment-579272 Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 As revraz said, you are overwriting the $devotional_query variable every time it loops. Add a period (.) right before the equals sign as I showed in my last post. Link to comment https://forums.phpfreaks.com/topic/112786-solved-mysql_fetch_array-only-grabbing-one-entry/#findComment-579276 Share on other sites More sharing options...
dennismonsewicz Posted July 1, 2008 Author Share Posted July 1, 2008 ah gotcha... thanks for the help. Topic Solved! Link to comment https://forums.phpfreaks.com/topic/112786-solved-mysql_fetch_array-only-grabbing-one-entry/#findComment-579280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.