Omnimaga

General Discussion => Technology and Development => Web Programming and Design => Topic started by: DJ Omnimaga on February 05, 2010, 06:17:21 pm

Title: Need PHP help (language is being picky)
Post by: DJ Omnimaga on February 05, 2010, 06:17:21 pm
Code: [Select]
global $context, $boarddir, $settings, $options, $scripturl, $user_info, $modSettings;


require($boarddir.'/SSI.php');

echo'
<div style="font-family: verdana, arial, sans-serif;">';

  // more stats
            echo 'Since Aug 25, 08, <b>' isset($modSettings['memberCount']) ?

$modSettings['memberCount'] : $modSettings['totalMembers'] , ' members</b> joined Omnimaga.
<br /><br />Since May 12, 05, <b>' .$modSettings['totalMessages']. ' posts</b> and
<b>' .$modSettings['totalTopics']. ' topics</b> were created.
<br />(<a href="http://www.omnimaga.org/index.php?action=stats">More Forum Statistics</a>)
<br /><br /><a href="http://www.omnimaga.org/index.php?action=downloads;sa=stats">Downloads Statistics</a>
';

This code is supposed to shows the total board postcount, topiccount and member count on the portal. It worked fine before, and then I simply edited some of the HTML text, and it stops working completly (syntax error). I did not even change anything in the PHP code and I checked for missing 's and I am fairly certain there's none missing or the opposite. I don't know PHP too much but it seems very picky. Are we limited in what text we can put in echo's commands? Seems like so to me, because it is fairly impossible that just a text change would break the code completly.

Anyway, can anyone with some PHP knowledge tell me what's wrong in the code?
Title: Re: Need PHP help (language is being picky)
Post by: Galandros on February 05, 2010, 06:31:23 pm
I analysed and only picked one small issue:
The problem seems to be missing a full point (to concatenate strings) or a comma (to pass multiple strings to echo), that is it, in this line before the isset(:

Code: [Select]
           echo 'Since Aug 25, 08, <b>' . isset($modSettings['memberCount']) ?

$modSettings['memberCount'] : $modSettings['totalMembers'] , ' members</b> joined Omnimaga.
<br /><br />Since May 12, 05, <b>' .$modSettings['totalMessages']. ' posts</b> and
<b>' .$modSettings['totalTopics']. ' topics</b> were created.
<br />(<a href="http://www.omnimaga.org/index.php?action=stats">More Forum Statistics</a>)
<br /><br /><a href="http://www.omnimaga.org/index.php?action=downloads;sa=stats">Downloads Statistics</a>
';
Title: Re: Need PHP help (language is being picky)
Post by: DJ Omnimaga on February 05, 2010, 06:35:50 pm
Where would I put that point, though? Could you actually post the code in a quote box and color the part that needs to be changed, even thought it means the HTML in the code will process? I am kinda confused

I also checked with a online PHP syntax checker at http://tools.sopili.net/php-syntax-check/?hl=en (Firefox-only) and it found no syntax error.
Title: Re: Need PHP help (language is being picky)
Post by: Tribal on February 05, 2010, 06:42:39 pm
DJ_Omni, it seems as though he added it for you  ;)

P.S. Sorry for seeming to ignore you, I kept being called away by my parents :-[
Title: Re: Need PHP help (language is being picky)
Post by: DJ Omnimaga on February 05, 2010, 06:50:18 pm
Actually, I think I spotted Galandros modification. He added a dot somewhere. Finally it turned out that it was a comma that was missing there, since with the dot the member count would not show up (altough the rest would work fine).

I am unsure if it is perfectly working, though, now. Seems like so to me, though.

Thanks people, though.

That said, does anyone know how I would actually display a value that is combined with another? I mean like in TI-BASIC you would do:

Disp "Posts since 05:",A+56401,"Topics:",B+3126

However, the other day, I searched during two hours through Google and couldn't even find any relevant result. Is that even possible at all in PHP?

In my case, the ' .$modSettings['totalMessages']. ' part of my code would have been like ' .$modSettings['totalMessages'] + 56401. ', but after trial and error, no combinations would work. Seems like PHP doesn't allow two added values to be displayed together.

What I want to do is display the current postcount PLUS the old board post count (this one is a fixed number.

Basically in pseudo code it would be:

Quote
Since Aug 25, 08, 272 members joined Omnimaga.

Since May 12, 05, CurrentBoardPostCount+56401 posts and CurrentBoardTopics+3126 topics were created.
(More Forum Statistics)

Downloads Statistics

Is it even possible to do such thing? Since my researches failed could anyone direct me how?
Title: Re: Need PHP help (language is being picky)
Post by: Galandros on February 05, 2010, 07:04:42 pm
That said, does anyone know how I would actually display a value that is combined with another? I mean like in TI-BASIC you would do:

Disp "Posts since 05:",A+56401,"Topics:",B+3126
echo command in PHP has the same behaviours as the Disp TI-BASIC command when comes to commas.
Example:
Ti-BASIC:
Disp "One string","another",A,B
PHP:
echo "One string","another",$A,$B

However, the other day, I searched during two hours through Google and couldn't even find any relevant result. Is that even possible at all in PHP?

In my case, the ' .$modSettings['totalMessages']. ' part of my code would have been like ' .$modSettings['totalMessages'] + 56401. ', but after trial and error, no combinations would work. Seems like PHP doesn't allow two added values to be displayed together.

What I want to do is display the current postcount PLUS the old board post count (this one is a fixed number.

Basically in pseudo code it would be:

Quote
Since Aug 25, 08, 272 members joined Omnimaga.

Since May 12, 05, CurrentBoardPostCount+56401 posts and CurrentBoardTopics+3126 topics were created.
(More Forum Statistics)

Downloads Statistics

Is it even possible to do such thing? Since my researches failed could anyone direct me how?
Yes, it is possible.

The pseudo code to PHP code: (I tried to predicted where to get the values from the code you gave)
Code: [Select]
echo 'Since Aug 25, 08, ', (isset($modSettings['memberCount']) ? $modSettings['memberCount'] :  modSettings['totalMembers']), ' members joined Omnimaga.';
echo 'Since May 12, 05, ', $modSettings['totalMessages']+56401 ,' posts and ', $modSettings['totalTopics']+3126, ' topics were created.';
// the rest of the page
Title: Re: Need PHP help (language is being picky)
Post by: Eeems on February 05, 2010, 07:13:45 pm
In php you use a . To add two strings together ie: "sting".$stringvar."string"
Title: Re: Need PHP help (language is being picky)
Post by: DJ Omnimaga on February 05, 2010, 08:54:41 pm
That said, does anyone know how I would actually display a value that is combined with another? I mean like in TI-BASIC you would do:

Disp "Posts since 05:",A+56401,"Topics:",B+3126
echo command in PHP has the same behaviours as the Disp TI-BASIC command when comes to commas.
Example:
Ti-BASIC:
Disp "One string","another",A,B
PHP:
echo "One string","another",$A,$B

However, the other day, I searched during two hours through Google and couldn't even find any relevant result. Is that even possible at all in PHP?

In my case, the ' .$modSettings['totalMessages']. ' part of my code would have been like ' .$modSettings['totalMessages'] + 56401. ', but after trial and error, no combinations would work. Seems like PHP doesn't allow two added values to be displayed together.

What I want to do is display the current postcount PLUS the old board post count (this one is a fixed number.

Basically in pseudo code it would be:

Quote
Since Aug 25, 08, 272 members joined Omnimaga.

Since May 12, 05, CurrentBoardPostCount+56401 posts and CurrentBoardTopics+3126 topics were created.
(More Forum Statistics)

Downloads Statistics

Is it even possible to do such thing? Since my researches failed could anyone direct me how?
Yes, it is possible.

The pseudo code to PHP code: (I tried to predicted where to get the values from the code you gave)
Code: [Select]
echo 'Since Aug 25, 08, ', (isset($modSettings['memberCount']) ? $modSettings['memberCount'] :  modSettings['totalMembers']), ' members joined Omnimaga.';
echo 'Since May 12, 05, ', $modSettings['totalMessages']+56401 ,' posts and ', $modSettings['totalTopics']+3126, ' topics were created.';
// the rest of the page

This doesn't work, it gives syntax error. I have

Code: [Select]
global $context, $boarddir, $settings, $options, $scripturl, $user_info, $modSettings;


require($boarddir.'/SSI.php');

echo'
<div style="font-family: verdana, arial, sans-serif;">';

echo 'Since Aug 25, 08, ', (isset($modSettings['memberCount']) ? $modSettings['memberCount'] :  modSettings['totalMembers']), ' members joined Omnimaga.';
echo 'Since May 12, 05, ', $modSettings['totalMessages']+56401 ,' posts and ', $modSettings['totalTopics']+3126, ' topics were created.<br />(<a href="http://www.omnimaga.org/index.php?action=stats">More Forum Statistics</a>)<br /><br /><a href="http://www.omnimaga.org/index.php?action=downloads;sa=stats">Downloads Statistics</a>
';

Are you sure this works under PHP 4.x?
Title: Re: Need PHP help (language is being picky)
Post by: DJ Omnimaga on February 06, 2010, 01:19:33 am
Ok nvm, I finally figured out which char was missing and the like. It works now, altough with your help I managed to modify it to have more stuff than what I desired at first. (see news)