• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP+SQL] Foreach news

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Reaction score
72
Location
Poland
I tried to make one but it don't work. Can someone write me the script?

PHP:
$news = $mysqli->query("SELECT * FROM `z_news_big`")->fetch_assoc();


    foreach ($news as $new)
    {
    echo "<td>" . $new['date'] . "</td>";    
    echo "<td>" . $new['author'] . "</td>";    
    echo "<td>" . $new['author_id'] . "</td>";    
    echo "<td>" . $new['image_id'] . "</td>";    
    echo "<td>" . $new['topic'] . "</td>";    
    echo "<td>" . $new['text'] . "</td>";    
    }

PHP:
CREATE TABLE IF NOT EXISTS `z_news_big` (
  `hide_news` tinyint(1) NOT NULL DEFAULT '0',
  `date` int(11) NOT NULL DEFAULT '0',
  `author` varchar(255) NOT NULL,
  `author_id` int(11) NOT NULL,
  `image_id` int(3) NOT NULL DEFAULT '0',
  `topic` varchar(255) NOT NULL,
  `text` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `z_news_big` (`hide_news`, `date`, `author`, `author_id`, `image_id`, `topic`, `text`) VALUES
(0, 1285342738, 'layouts.4za.pl', 1, 0, 'New account manager!', 'Gesior account manager 0.3.6 installed. All options should work fine. Report bugs in acc. maker thread'),
(0, 1285342792, 'As', 1, 4, 'Test', 'Test');
 
Change:
Code:
$news = $mysqli->query("SELECT * FROM `z_news_big`")->fetch_assoc();

To:
Code:
$news = $mysqli->query("SELECT * FROM `z_news_big`")->fetch_array();
 
Back
Top