Jump to content


Photo

MySQL Empty Rows?


  • Please log in to reply
2 replies to this topic

#1 fog_2003

fog_2003
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 July 2006 - 03:24 PM

I have a MySQL database and I am trying to retrieve multiple articles from it and parse it like this

Article Title
Article Content

Article Title
Article 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 title

I was wondering it anyone knows what I am doing wrong in this code.


This is the 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>

And this is the result




<html>
<head>
</head>

	<br>
	<br><br>
	
	Test2<br>
	This is another test<br><br>

	
	Test<br>
	This is a test<br><br>
	


</html>


#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 03:30 PM

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
$totalRows_Articles = mysql_num_rows($query_Articles);//Total Number of Rows Returned by Query Result, Used in Do While Loop
?>

<html>
<head>
</head>

<?php
if($totalRows_Articles > 0)
{
        while($row = mysql_fetch_assoc($queryresults_Articles))
        {
                        echo $row['ArtTitle'] . '<br />';
                        echo $row['ArtContent'] . '<br /><br />';
        }
}
?>

</html>


This should work as long as there's nothing wrong with the database fields etc.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 July 2006 - 03:31 PM

Change your loop to a while loop. Plus you don't need the number of rows, since you don't use it.
<?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>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users