PHP News Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Code: Select all

<table border"1"><?php
$db = mysql_connect("localhost", "Gappa", " "); 
mysql_select_db("Gappa",$db); 
$date_formats = array('d/m/y', 'd/m/Y', 'd/m/Y H:i:s', 'D d-M-y', 'D d-M-Y', 'D d-M-Y H:i:s', 'l d F Y', 'l d F Y H:i:s');

$query = 'SELECT topic_title, FROM_UNIXTIME(topic_time,"%W the %D of %M %r") AS Topic_Date, post_text, username FROM phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id RIGHT JOIN phpbb_users ON topic_poster=user_id WHERE forum_id=6 ORDER BY topic_time DESC'; 
$result = mysql_query($query, $db) or die ($query .': '.mysql_error()); 

while($row = mysql_fetch_assoc($result)) 
{ 
   echo $row['topic_title'];
   echo " posted by ";
   echo $row['username'];
   echo " at ";
   echo $row['topic_time'], '<br/>';
   echo $row ['post_text'];
}

?></table>
Ok.. so got rid of some of the pointless code i think... still getting errors.

Parse error: parse error, unexpected T_STRING in /data/hosted/Gappa/test3.php on line 1
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Sorry its not line 1... its line 11

Parse error: parse error, unexpected T_STRING in /data/hosted/Gappa/test3.php on line 11
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Are you sure that's test3.php?

Also, it would be good to tell us which line is line 11, because with the text wrapping and all, I was at first thinking while($row = mysql_fetch_assoc($result)) was line 11.

P.S. Use the PHP button, it's there for a reason. =)
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

I think this is line 11

Code: Select all

   echo $row&#1111;'topic_title'];
and yes im sure the above code is test3.php ...

I know this is gonna be some stupid little coding error... well i hope
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what happens if you use

Code: Select all

echo "$row[topic_title] posted by $row[username] at $row[topic_time] <br/> $row[post_text]";
as loop-body? (ugly but just to test...)
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

The only reason I ask is that I ran the script, and I didn't get a parse error anywhere. Are you sure you uploaded the script?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

me neither.
But there was another topic that ran into the same problem. Can't find it anymore and can't remember the outcome :?
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Ok this code works... kinda ungly out come but it technically works

Code: Select all

<table border"1"><?php
$db = mysql_connect("localhost", "Gappa", "xocunino"); 
mysql_select_db("Gappa",$db); 
$date_formats = array('d/m/y', 'd/m/Y', 'd/m/Y H:i:s', 'D d-M-y', 'D d-M-Y', 'D d-M-Y H:i:s', 'l d F Y', 'l d F Y H:i:s');

$query = 'SELECT topic_title, FROM_UNIXTIME(topic_time,"%W the %D of %M %r") AS Topic_Date, post_text, username FROM phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id RIGHT JOIN phpbb_users ON topic_poster=user_id WHERE forum_id=6 ORDER BY topic_time DESC'; 
$result = mysql_query($query, $db) or die ($query .': '.mysql_error()); 

while($row = mysql_fetch_assoc($result)) 
{ 
echo "$row[topic_title] posted by $row[username] at $row[topic_time] <br/> $row[post_text]";
}

?></table>
Now i been fulling around with adding html tags like ><b><FONT FACE=Arial SIZE=-1 COLOR=#FF9900
> but I dont know where to add them, everytime I do add them it changes my out put to just give me topic_title and nothing else...

Sooo was wondering how do I add such tags... just to make everything look pretty :)
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

If you're trying to output HTML tags within <?php ?> tags, use the "echo" command to output your code.

i.e.-

echo "<a href=\"haha.html\">HAHA!</a>";

/ i.e ;)
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Code: Select all

<HTML>
<table border"1"><?php
$db = mysql_connect("localhost", "Gappa", " "); 
mysql_select_db("Gappa",$db); 
$date_formats = array('d/m/y', 'd/m/Y', 'd/m/Y H:i:s', 'D d-M-y', 'D d-M-Y', 'D d-M-Y H:i:s', 'l d F Y', 'l d F Y H:i:s');

$query = 'SELECT topic_title, FROM_UNIXTIME(topic_time,"%W the %D of %M %r") AS Topic_Date, post_text, username FROM phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id RIGHT JOIN phpbb_users ON topic_poster=user_id WHERE forum_id=6 ORDER BY topic_time DESC'; 
$result = mysql_query($query, $db) or die ($query .': '.mysql_error()); 

while($row = mysql_fetch_assoc($result)) 
{ 
echo "<b><FONT FACE=Arial SIZE=-1 COLOR=#FF9900>";
echo "$row[topic_title]</b>";
echo "<FONT SIZE=-2 COLOR=#666666 posted by $row[username]";
echo " at $row[topic_time]<br/>";
echo "<FONT SIZE=-1 COLOR=#FFFFFF $row[post_text]";
echo "<br/><br/>";
}

?></table>
</HTML>
OK think this is right... but its not working.. still only displaying the topic_title and nothing else.

see here > http://www.hostultra.com/~Gappa/test3.php

what have i done wrong?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

echo "<FONT SIZE=-2 COLOR=#666666 posted by $row[username]";
you didn't end the font open-tag, so posted, by and the value of $row[username]
try

Code: Select all

<?php
...
echo "<b><FONT FACE=Arial SIZE=-1 COLOR=#FF9900>";
echo "$row[topic_title]</FONT></b>";
echo "<FONT SIZE=-2 COLOR=#666666> posted by $row[username]";
echo " at $row[topic_time]</FONT><br/>";
echo "<FONT SIZE=-1 COLOR=#FFFFFF> $row[post_text]</FONT>";
echo "<br/><br/>";
...
?>
and just a style suggestion

Code: Select all

<html>
	<head>
		<style type="text/css">
			body { background-color: darkblue; }
			fieldset { color: white; font-size: small; }
			legend { color: #FF9900;}
			fieldset span { color: silver; font-size: x-small; display: block}
		</style>
	</head>
	<body>
<?php
	...
	while($row = mysql_fetch_assoc($result))
	{
?>
		<fieldset>
			<legend><?php echo $row["topic_title"]; ?></legend>
			<span>
				posted by <?php echo $row["username"]; ?>
			</span>
			<?php echo $row["post_text"]; ?>
		</fieldset>
<?php
	}
?>
	</body>
</html>
(only a suggestion. Yes, I like fieldsets ;) )
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Code: Select all

<html> 
   <head> 
   </head> 
   <body>
<?php
$db = mysql_connect("localhost", "Gappa", "xocunino"); 
mysql_select_db("Gappa",$db); 
$date_formats = array('d/m/y', 'd/m/Y', 'd/m/Y H:i:s', 'D d-M-y', 'D d-M-Y', 'D d-M-Y H:i:s', 'l d F Y', 'l d F Y H:i:s');

$query = 'SELECT topic_title, FROM_UNIXTIME(topic_time,"%W the %D of %M %r") AS Topic_Date, post_text, username FROM phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id RIGHT JOIN phpbb_users ON topic_poster=user_id WHERE forum_id=6 ORDER BY topic_time DESC'; 
$result = mysql_query($query, $db) or die ($query .': '.mysql_error()); 

while($row = mysql_fetch_assoc($result)) 
   { 
echo "<b><FONT FACE=Arial SIZE=-1 COLOR=#FF9900>"; 
echo "$row[topic_title]</FONT></b>"; 
echo "<FONT SIZE=-2 COLOR=#666666> posted by $row[username]"; 
echo " at $row[topic_time]</FONT><br/>"; 
echo "<FONT FACE=Arail SIZE=-1 COLOR=#000000> $row[post_text]</FONT>"; 
echo "<br/><br/>";   } 
?> 
   </body> 
</html>
Hehe styles nice man, but i'll work on that after i get a baisc layout to work... this in general is working apart from the topic_time is no longer working! eeeekkk!!! 8O any suggestions!?
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Every one think the above should be working???

Its just refusing to give me the date!!!...
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Ok got the time thing worked out... had to change from topic_time to topic_date...

now any way with getting the comments kinda thing going (link to the forum topic)... im getting an error on line 18... which is.

Code: Select all

echo "<a href="http://www.hostultra/~Gappa/phpBB2/viewtopic.php?t=$row[topic_id]">Read more</a>";
Hmmm problem?

Parse error: parse error, expecting `','' or `';'' in /data/hosted/Gappa/test3.php on line 18
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have a read of:
http://www.php.net/manual/en/language.types.string.php

You need to escape those double quotes in the HTML otherwise PHP thinks you've ended the string and then put a bunch of random characters it doesn't understand after it - you can see the difference in the syntax colouring of the code you posted and this below:

Code: Select all

echo "<a href="http://www.hostultra/~Gappa/phpBB2/viewtopic.php?t=$row[topic_id]">Read more</a>";
Mac
Post Reply