Jump to content

Show more than 1 rows in a order


Go to solution Solved by Ch0cu3r,

Recommended Posts

Hello, my name is Casper.

 

I'm createing a site where you can upload articles.

But for now I onley can show 1 article on the pages.

Does anyone knows how to show more articles?

 

My script what posts 1 article:

 

 

 

<?php

 

$username = "";

$db = "";

$hostname = ""; 

$password = "";

 

@mysql_connect($hostname, $username, '') or die("connectie mislukt");

 

@mysql_select_db("$db") or die ("could not connect dattabase");

 

$sql = mysql_query('SELECT * FROM home ORDER BY Date') or die ('Database Error()');

 

$id = 'ID';

$date = 'Date';

$title = 'Title';

$article = 'Article';

 

$rows = mysql_fetch_assoc($sql) or die ('Fetch Data Error()');

 

 

echo $rows[$title], '-', $rows[$date];

echo '</br>';

echo '</br>';

echo $rows[$article];

?>

 

and here's a ss of my DB table:


 

every article has to be in this order:

 

title - date

 

article

 

 

thank you in advance,

 

Casper Hollemans.

Link to comment
https://forums.phpfreaks.com/topic/290511-show-more-than-1-rows-in-a-order/
Share on other sites

  • Solution

 

But for now I onley can show 1 article on the pages.

Does anyone knows how to show more articles?

To show all the articles returned by your query you need to use a while loop passing mysql_fetch_array as the condition, Example

while($rows = mysql_fetch_assoc($sql))
{
    echo '<p>' . $rows[$title]. '-'. $rows[$date];
    echo '</br>';
    echo '</br>';
    echo $rows[$article] .'</p>';
}

NOTE: You should update your code to use either PDO or MySQLi now. The mysql_* functions are deprecated meaning they are no longer supported and could be removed from future versions of PHP.

Edited by Ch0cu3r
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.