news scriptje
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
$forumid = '4';
//how many news post you want to show
$topicrows = '5';
mysql_connect ($databaseip, $username, $password);
mysql_select_db ($databasename);
$topicq = mysql_query ("select* from ibf_topics where forum_id=".$forumid." order by start_date desc");
for ($i=0; $i <$topicrows; $i++)
{
$topicrow = mysql_fetch_array($topicq);
$titleid = $topicrow["tid"];
$topictitle = $topicrow["title"];
$postq = mysql_query ("SELECT * FROM `ibf_posts` where topic_id = ".$titleid." and new_topic = 1 order by post_date");
$postfetch = mysql_fetch_array($postq);
$postrow = $postfetch["post"];
$unixdate = $topicrow["start_date"];
$date = date("F jS, Y",$unixdate);
$writter = $topicrow["starter_name"];
$postrow = str_replace('<#EMO_DIR#>', $emoticons, $postrow);
$postrow = str_replace('<#IMG_DIR#>', $img_dir, $postrow);
echo ('
<p>'.$topictitle.'</p>
<p>'.$postrow.'</p>
<p>'.$writter.'</p>
<p>'.$date.'</p>
<p><a href="http://forums.yourwebsite.com/index.php?showtopic='.$titleid.'">Comments?</a></p>
<p><hr></p>
');
}
?>
$forumid = '4';
//how many news post you want to show
$topicrows = '5';
mysql_connect ($databaseip, $username, $password);
mysql_select_db ($databasename);
$topicq = mysql_query ("select* from ibf_topics where forum_id=".$forumid." order by start_date desc");
for ($i=0; $i <$topicrows; $i++)
{
$topicrow = mysql_fetch_array($topicq);
$titleid = $topicrow["tid"];
$topictitle = $topicrow["title"];
$postq = mysql_query ("SELECT * FROM `ibf_posts` where topic_id = ".$titleid." and new_topic = 1 order by post_date");
$postfetch = mysql_fetch_array($postq);
$postrow = $postfetch["post"];
$unixdate = $topicrow["start_date"];
$date = date("F jS, Y",$unixdate);
$writter = $topicrow["starter_name"];
$postrow = str_replace('<#EMO_DIR#>', $emoticons, $postrow);
$postrow = str_replace('<#IMG_DIR#>', $img_dir, $postrow);
echo ('
<p>'.$topictitle.'</p>
<p>'.$postrow.'</p>
<p>'.$writter.'</p>
<p>'.$date.'</p>
<p><a href="http://forums.yourwebsite.com/index.php?showtopic='.$titleid.'">Comments?</a></p>
<p><hr></p>
');
}
?>
Als ik dat gebruik en ik laadt de pagina werkt het niet helemaal. Als je minder 5 topicrows hebt dan krijg je deze error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\appserv\www\ipbnewsscript\newsscript.php on line 62
Gewijzigd op 01/01/1970 01:00:00 door Menno
mysql error...
hoe verhelp ik? :O
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
$out = mysql_query($sql);
while($row = mysql_fetch_assoc($out)){
echo rotzooi
}
?>
$out = mysql_query($sql);
while($row = mysql_fetch_assoc($out)){
echo rotzooi
}
?>
wert vaak beter
maar hoe fix ik dan? ...
ik heb nu gedaan maar nu laat ie maar 1 post zien terwijl er 2 staan >_>
Je code is nu?
while($row = mysql_fetch_object($topicq))
{
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
$forumid = '4';
$topicrows = '5';
mysql_connect ($databaseip, $username, $password);
mysql_select_db ($databasename);
$out = ("select * from ibf_topics where forum_id=".$forumid." order by start_date desc");
$out = mysql_query($out);
while($row = mysql_fetch_object($out)){
$topicrow = mysql_fetch_array($out);
$titleid = $topicrow["tid"];
$topictitle = $topicrow["title"];
$postq = mysql_query ("SELECT * FROM `ibf_posts` where topic_id = ".$titleid." and new_topic = 1 order by post_date");
$postfetch = mysql_fetch_array($postq);
$postrow = $postfetch["post"];
$unixdate = $topicrow["start_date"];
$date = date("F jS, Y",$unixdate);
$writter = $topicrow["starter_name"];
$postrow = str_replace('<#EMO_DIR#>', $emoticons, $postrow);
$postrow = str_replace('<#IMG_DIR#>', $img_dir, $postrow);
echo ('
<p>'.$topictitle.'</p>
<p>'.$postrow.'</p>
<p>'.$writter.'</p>
<p>'.$date.'</p>
<p><a href="http://forums.yourwebsite.com/index.php?showtopic='.$titleid.'">Comments?</a></p>
<p><hr></p>
');
}
?>
$forumid = '4';
$topicrows = '5';
mysql_connect ($databaseip, $username, $password);
mysql_select_db ($databasename);
$out = ("select * from ibf_topics where forum_id=".$forumid." order by start_date desc");
$out = mysql_query($out);
while($row = mysql_fetch_object($out)){
$topicrow = mysql_fetch_array($out);
$titleid = $topicrow["tid"];
$topictitle = $topicrow["title"];
$postq = mysql_query ("SELECT * FROM `ibf_posts` where topic_id = ".$titleid." and new_topic = 1 order by post_date");
$postfetch = mysql_fetch_array($postq);
$postrow = $postfetch["post"];
$unixdate = $topicrow["start_date"];
$date = date("F jS, Y",$unixdate);
$writter = $topicrow["starter_name"];
$postrow = str_replace('<#EMO_DIR#>', $emoticons, $postrow);
$postrow = str_replace('<#IMG_DIR#>', $img_dir, $postrow);
echo ('
<p>'.$topictitle.'</p>
<p>'.$postrow.'</p>
<p>'.$writter.'</p>
<p>'.$date.'</p>
<p><a href="http://forums.yourwebsite.com/index.php?showtopic='.$titleid.'">Comments?</a></p>
<p><hr></p>
');
}
?>
Gewijzigd op 01/01/1970 01:00:00 door menno
while($row = mysql_fetch_object($out)){
//deze regel weg
$titleid = $topicrow->tid;
$topictitle = $topicrow->title;
en zo ook alle andere variabelen aanpassen. tenminste, de variabelen die met fetch_object werken.
while($row = mysql_fetch_object($out)){
//deze regel weg
$titleid = $row->tid;
$topictitle = $row->title;