fog_2003 Posted July 9, 2006 Share Posted July 9, 2006 I have a MySQL database and I am trying to retrieve multiple articles from it and parse it like thisArticle TitleArticle ContentArticle TitleArticle Content...When I retrieve the article contents and title I get a blank article title and a blank article content and then the article title and content I want I am using html br's to break up the article title from the article content, and the article content from the next titleI was wondering it anyone knows what I am doing wrong in this code.This is the code[code]<?php // Query TblArticles mysql_select_db($database_conn_skatemanitowoc, $conn_skatemanitowoc) or die("Unable to Select Database"); $query_Articles = "Select * from TblArticles Order By ArtID Desc";//The Query $queryresults_Articles = mysql_query($query_Articles, $conn_skatemanitowoc) or die(QueryResults);//The Results $currentrow_Articles = mysql_fetch_assoc($query_Articles);//Current Row of the Loop, Used in the Do While Loop $totalRows_Articles = mysql_num_rows($query_Articles);//Total Number of Rows Returned by Query Result, Used in Do While Loop?><html><head></head><?php do { ?> <?php echo $currentrow_Articles['ArtTitle']; ?><br> <?php echo $currentrow_Articles['ArtContent']; ?><br><br> <?php } while ($currentrow_Articles = mysql_fetch_assoc($queryresults_Articles)); ?></html>[/code]And this is the result[code]<html><head></head> <br> <br><br> Test2<br> This is another test<br><br> Test<br> This is a test<br><br> </html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14101-mysql-empty-rows/ Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 [code]Code:<?php// Query TblArticlesmysql_select_db($database_conn_skatemanitowoc, $conn_skatemanitowoc) or die("Unable to Select Database");$query_Articles = "Select * from TblArticles Order By ArtID Desc";//The Query$queryresults_Articles = mysql_query($query_Articles, $conn_skatemanitowoc) or die(QueryResults);//The Results$totalRows_Articles = mysql_num_rows($query_Articles);//Total Number of Rows Returned by Query Result, Used in Do While Loop?><html><head></head><?phpif($totalRows_Articles > 0){ while($row = mysql_fetch_assoc($queryresults_Articles)) { echo $row['ArtTitle'] . '<br />'; echo $row['ArtContent'] . '<br /><br />'; }}?></html>[/code]This should work as long as there's nothing wrong with the database fields etc. Quote Link to comment https://forums.phpfreaks.com/topic/14101-mysql-empty-rows/#findComment-55186 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2006 Share Posted July 9, 2006 Change your loop to a while loop. Plus you don't need the number of rows, since you don't use it.[code]<?php mysql_select_db($database_conn_skatemanitowoc, $conn_skatemanitowoc) or die("Unable to Select Database");?><html><head></head><body><?php $query_Articles = "Select * from TblArticles Order By ArtID Desc";//The Query $queryresults_Articles = mysql_query($query_Articles, $conn_skatemanitowoc) or die(QueryResults);//The Results while ($currentrow_Articles = mysql_fetch_assoc($query_Articles)) { echo $currentrow_Articles['ArtTitle']. "<br>\n"; echo $currentrow_Articles['ArtContent'] . "<br><br>\n"; }?></body></html>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/14101-mysql-empty-rows/#findComment-55187 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.