Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.