homepage Welcome to WebmasterWorld Guest from 54.234.141.47
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Not linking correctly
My php script is not filling in the variable
riotfire

10+ Year Member



 
Msg#: 5054 posted 4:29 pm on Sep 15, 2004 (gmt 0)

I have a script that displays the lastest 5 topics from my phpbb message board on my home page.

However, the links comeup as
...viewtopic.php?t=$topic_id instead of the actual URL. The topic names display correctly.

Here is the script

<?php

$topic_length = '30';// length of topic title
$topic_limit = '5';// limit of displayed topics
$special_forums = '0';// specify forums ('0' = no; '1' = yes)
$forum_ids = '';// IDs of forums; separate them with a comma

$root_path = '/forum/';// board folder

$path = dirname(__FILE__);
include_once($path.$root_path .'config.php');
mysql_connect($dbhost, $dbuser, $dbpasswd) OR die('Unable to select server.');
mysql_select_db($dbname) OR die('Unable to select database.');

// ############## output ##############
echo '<table width="200" cellpadding="1" cellspacing="1" border="0" align="right">
<tr height="25">
<td valign="top"><h5>'. $topic_limit .' last topics</h5></td>
</tr>';
// ############## output ##############

$where_forums = ( $special_forums == '0' )? '' : 't.forum_id IN ('. $forum_ids .') AND ';
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time
FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2
WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id
ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
$result = mysql_query($sql);
if(!$result )
{
die('SQL Statement Error: '. mysql_error());
exit();
}

$line = array();
while( $row = mysql_fetch_array($result) )
{
$line[] = $row;
}

for( $i = 0; $i < count($line); $i++ )
{
$forum_id = $line[$i]['forum_id'];
$forum_url = $root_path .'viewforum.php?f=$forum_id';
$topic_id = $line[$i]['topic_id'];
$topic_url = $root_path .'viewtopic.php?t=$topic_id';

$topic_title = ( strlen($line[$i]['topic_title']) < $topic_length )? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...';

$topic_type = ( $line[$i]['topic_type'] == '2' )? 'Announcement ': '';
$topic_type .= ( $line[$i]['topic_type'] == '3' )? 'Global Announcement ': '';
$topic_type .= ( $line[$i]['topic_type'] == '1' )? 'Sticky ': '';
$topic_type .= ( $line[$i]['topic_vote'] )? 'Poll ': '';

$views = $line[$i]['topic_views'];
$replies = $line[$i]['topic_replies'];

$first_time = date('d.m.Y', $line[$i]['topic_time']);
$first_author = ( $line[$i]['first_poster_id']!= '-1' )? '<a href="'. $root_path .'profile.php?mode=viewprofile&amp;u='. $line[$i]['first_poster_id'] .'">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name']!= '' )? $line[$i]['first_poster_name'] : 'guest' );
$last_time = date('d.m.Y', $line[$i]['post_time']);
$last_author = ( $line[$i]['last_poster_id']!= '-1' )? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name']!= '' )? $line[$i]['last_poster_name'] : 'guest' );
$last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'">'. $last_author .'</a>';

// ############## output ##############
echo '<tr>
<td align="top"><h5>'. $topic_type .'<a href="'. $topic_url .'">'. $topic_title .'</a></h5></td>
</tr>';
// ############## output ##############
}

echo '</table>';
mysql_close();
?>

 

jamie

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 5054 posted 4:33 pm on Sep 15, 2004 (gmt 0)

hi,

i think it's a quotes problem. your line

$topic_url = $root_path .'viewtopic.php?t=$topic_id';

should be enclosed in double quotes not single, single quotes mean the content will be displayed literally - so it should be:

$topic_url = $root_path ."viewtopic.php?t=$topic_id";

hth

jezra

10+ Year Member



 
Msg#: 5054 posted 4:42 pm on Sep 15, 2004 (gmt 0)

It would appear to be an issue with single quoted string.
suppose I have the variable
$my_name="jezra";

echo "$my_name"; //will output jezra

echo '$my_name'; //will output $my_name

documentation can be found at
[php.net...]

Knowles

10+ Year Member



 
Msg#: 5054 posted 5:11 pm on Sep 15, 2004 (gmt 0)

Is this the code that you are asking about:
// ############## output ##############
echo '<tr>
<td align="top"><h5>'. $topic_type .'<a href="'. $topic_url .'">'. $topic_title .'</a></h5></td>
</tr>';
// ############## output ##############

I dont see anything wrong with it. Does $topic_type and $topic_title show up correctly?

riotfire

10+ Year Member



 
Msg#: 5054 posted 5:25 pm on Sep 15, 2004 (gmt 0)

Yes both $topic_type and $topic_title show up correctly. I changed the single quote (') to a double (") and it worked correctly. Should I change the other variables as well? It appears to work ok.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved