Author Topic: Need PHP help (language is being picky)  (Read 6306 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Need PHP help (language is being picky)
« 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?
« Last Edit: February 05, 2010, 06:19:51 pm by DJ Omnimaga »

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Need PHP help (language is being picky)
« Reply #1 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>
';
« Last Edit: February 05, 2010, 06:32:18 pm by Galandros »
Hobbing in calculator projects.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need PHP help (language is being picky)
« Reply #2 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.
« Last Edit: February 05, 2010, 06:36:28 pm by DJ Omnimaga »

Offline Tribal

  • The Fallen
  • LV5 Advanced (Next: 300)
  • *
  • Posts: 218
  • Rating: +15/-1
    • View Profile
Re: Need PHP help (language is being picky)
« Reply #3 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 :-[

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need PHP help (language is being picky)
« Reply #4 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?

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Need PHP help (language is being picky)
« Reply #5 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
Hobbing in calculator projects.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6266
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Need PHP help (language is being picky)
« Reply #6 on: February 05, 2010, 07:13:45 pm »
In php you use a . To add two strings together ie: "sting".$stringvar."string"
/e

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need PHP help (language is being picky)
« Reply #7 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?
« Last Edit: February 05, 2010, 08:55:28 pm by DJ Omnimaga »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need PHP help (language is being picky)
« Reply #8 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)