Jump to content

MySQL Empty Rows?


fog_2003

Recommended Posts

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

[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]
Link to comment
https://forums.phpfreaks.com/topic/14101-mysql-empty-rows/
Share on other sites

[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
$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>

[/code]

This should work as long as there's nothing wrong with the database fields etc.
Link to comment
https://forums.phpfreaks.com/topic/14101-mysql-empty-rows/#findComment-55186
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/14101-mysql-empty-rows/#findComment-55187
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.