boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Confusion on arrays, vars and php functions.. :p

 
Post new topic   Reply to topic    boardom Forum Index -> PHP help
View previous topic :: View next topic  
Author Message
Sigg3



Joined: 03 Jul 2003
Posts: 872
Location: Oslo, Norway

PostPosted: Tue Jan 25, 2005 11:07 pm    Post subject: Confusion on arrays, vars and php functions.. :p Reply with quote

Basically I'm looking for somewhat of what b2 offers, namely the ability to call/query data with a simple URI caller, e.g: http://what.com/index.php?var1=x&var2=y&var3=z

Now,
var 1 is an integer which - when called - will echo a small string of text (1 sentence out of 60).
var2 is an integer which will "echo" one of 15 images
var3 a boolean either displaying picture 1 or picture 2.

_Then_ I need a way of using ({i]+1) and -1 to navigate back and forth.

Any ideas on what I should look into? I love to learn from examples.
I'm a total php n00b, just so it's said.
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Sigg3



Joined: 03 Jul 2003
Posts: 872
Location: Oslo, Norway

PostPosted: Wed Jan 26, 2005 1:44 pm    Post subject: Reply with quote

Taking it one step further...

Thanks to netcode.net, I was able to find a script that would allow me to do this using a db table, for which I'm glad.

There are a few issues, though.
    1. Ever heard about $sql? ... I get a parse-error on that'n.
    2. I was wondering wether the php_next() and prev() could be used as navigation links (<< and >>) which will define the querystrings that I'll use for retrieving the correct data. Any ideas on how/if this could be done?

All help appreciated:)
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Sigg3



Joined: 03 Jul 2003
Posts: 872
Location: Oslo, Norway

PostPosted: Thu Jan 27, 2005 4:04 pm    Post subject: Reply with quote

Disregard last two:)

All I need to know is how I can make multiple querys as in b2.. (e.g. index.php?c=1&tb=1)

I have one file- middle.php - calling images by ?ch=X where x is a number between 0 and 15.
I have 2nd file - dialogue.php - defining integers 0-60 as text strings. (Doesn't work yet, but I'll get there..)

I need to include both of these in a third file (middle.php will be used in other files identical to the 2nd one, so it needs to be "absolute") without disrupting the arrays of the 2nd one. So, I checked b2's isset? Any tips on how to do this?
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
stevem



Joined: 15 Mar 2003
Posts: 351

PostPosted: Fri Jan 28, 2005 8:28 pm    Post subject: Reply with quote

I don't think I understand what you want but if it helps you can work with a single query if you like. So ch=10, somethingelse=30 becomes myvariable=10_30 as in
Code:
$myvariable=$ch."_".$somethingelse;

Then you can recover the 2 variables using explode:
Code:
$bang=explode("_",$myvariable);
$ch=$bang[0];
$somethingelse=$bang[1];
Back to top
View user's profile Send private message
Sigg3



Joined: 03 Jul 2003
Posts: 872
Location: Oslo, Norway

PostPosted: Mon Jan 31, 2005 10:35 am    Post subject: Reply with quote

That's actually alot of help, cheers:)

The concept is pretty simple, but the design is not.
There are 15 characters ($ch) and 60 lines ($say).
Instead of writing a fixed setup, I want to make a system that allows me to (more) easily add new "episodes" to the comic.
Of course I could've hacked b2 and used the db, but I already have 2 blogs on my server so I wanted to try something else.

At the time, I've got the lines of the script in one file (which I'll include with an isset or something, for security) the characters in another and a third frameset-file calling the cycle of steps, which again is a forth file.
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Sigg3



Joined: 03 Jul 2003
Posts: 872
Location: Oslo, Norway

PostPosted: Mon Jan 31, 2005 12:05 pm    Post subject: Reply with quote

Ok, here's the deal. Using this code:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
   
   $eistr=$char."_".$sayline;
   $bang=explode("_",$eistr);
   $char=$bang[0];
   $sayline=$bang[1];

# great tip by Stevem:)

# example: echo "Character $ch says $sayline".. just a note..

$what = Array('1' => 'So..',
'2' => 'Yep..',
'3' => 'Any news?',
'4' => 'What did he say?',
'5' => 'Andrew asked if there was any news',
'6' => 'Oh, he did, did he?',
'7' => 'Yes..',
'8' => 'Huh..',
'9' => 'Haven`t seen Logan for a while..',
'10' => 'He is still at the far right.',
'11' => 'LOGAN!?',
'12' => 'YES?!',
'13' => 'THIS IS LEONARD!!',
'14' => 'HI!!!',
'15' => 'Can you please shut up?',
'16' => 'IT`S BEEN A LONG TIME!!!',
'17' => 'What are they yelling about?',
'18' => 'YEAH! WHAT`S THE VIEW LIKE FROM THERE!??',
'19' => 'What did he say?',
'20' => 'Logan asked what the view was like from here.',
'21' => 'Oh! Tell him it`s good.',
'22' => 'IT`S GOOD!',
'23' => 'Do you mind?',
'24' => 'Shh!',
'25' => 'Ask him if he can see anything!',
'26' => 'CAN YOU SEE ANYTHING??!',
'27' => 'What`s all this noise about?',
'28' => 'Leonard is talking with Logan.',
'29' => 'Oh, they`re at it again, eh?',
'30' => 'NAAAHH! I SAW A SHIP TWO MONTHS AGO!!',
'31' => 'This is so lame.',
'32' => 'YOU DID?! SO DID WE!!',
'33' => 'OH? WHO`S WITH YOU?',
'34' => 'Can you stop shouting?',
'35' => 'Yeah! Shut up!',
'36' => 'You shut up! LOGAN! IT`S RICHARD HERE WITH ME! LIKE LAST TIME!!',
'37' => 'AAAAAHH..',
'38' => 'What did he say?',
'39' => 'I think he said ",Ahhhh",..',
'40' => 'Oh.',
'41' => 'That a plane?',
'42' => 'Naahh. Eagle again.',
'43' => 'Yup. That`s an eagle.',
'44' => 'Oh',
'45' => '*snif*',
'46' => 'Got a cold?',
'47' => 'Think I`ve got one coming. It`s quite brisky here, isn`t it?',
'48' => 'Yes, well, you know this time of year..',
'49' => 'Yes.. yes..',
'50' => 'IT WAS NICE TALKING TO YOU LEONARD!!',
'51' => 'Oh, I thought they were finished..',
'52' => 'Yeah, right.',
'53' => 'NICE TALKING TO YOU TOO LOGAN!!!',
'54' => 'Give him my best!',
'55' => 'AH.. RICHARD SAYS TO GIVE YOU HIS BEST!',
'56' => 'AHH YES! GOOD LUCK TO HIM TOO!',
'57' => 'He wished you good luck too.',
'58' => 'I heard.',
'59' => '*snif*',
'60' => '... I`ve got an itch..');


?>

<html>
<head>
<title>Easter Island Episodes</title>
<link rel="stylesheet" type="text/css" href="http://www.sigg3.net/blogger/EasterIsland/middle.css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</head>
<body>
<!-- // Mother centers enclosed contents -->
<div id="mother">

   <!-- // The dialogue bubble -->
   <div id="bubble<?php print($char); ?>">
      
      <!-- // The dialogue itself -->   
      <h3>
      <?php echo "{$what['$sayline']}"; ?>
      </h3>
   
   </div>   
</div>
</body>
</html>

And calling the file (base.php) by e.g. base.php?eistr=1_14
doesn't fetch anything..? No parse errors either..

Could $_GET be the thing?..

EDIT:
Live example up at..
http://www.sigg3.net/blogger/EasterIsland/base.php?eistr=1_14

Eventually I want the array to be included (the array in files named ep1.php, ep2.php etc.), but I'm aware of the risks so I also want to know the easiest yet safe way to do it:)
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
stevem



Joined: 15 Mar 2003
Posts: 351

PostPosted: Tue Feb 01, 2005 9:21 pm    Post subject: Reply with quote

Whoops! You need to take out the line
Code:
$eistr=$char."_".$sayline;
since you want to read $eistr not define it

Sigg3 wrote:
Eventually I want the array to be included (the array in files named ep1.php, ep2.php etc.), but I'm aware of the risks so I also want to know the easiest yet safe way to do it:)

Put an array in ep1.php which is included in base.php but when run makes some sort of check. Set a variable not easy to guess in base.php and if ep1.php doesn't find the right value of this variable it aborts. Should make things a little harder for the casual user to get in.
Back to top
View user's profile Send private message
Sigg3



Joined: 03 Jul 2003
Posts: 872
Location: Oslo, Norway

PostPosted: Wed Feb 02, 2005 11:51 am    Post subject: Reply with quote

Thanks alot, I'll give it a try!

On the include issue, I read that $isset is the right function to do this from a security point of view.

I don't want people to include external (and possible malicious) scripts.
But this might also be done by only allowing the call to be an INT.

EDIT:
Wohoo! It works! Had to change the last echo to print, but now it's on! Thanks alot!Smile
_________________
Sigg3.net - You know you're worth it! | b2 Cafelog Resource Center
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> PHP help All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group