Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 2008-03-15, 05:07 AM
Junior Member
 
Join Date: Mar 2008
Posts: 6
mattisdada is on a distinguished road
Default Im attempting at making my own comic engine

Im attempting at making my own comic engine...

This is what ive made so far. It half works....

Baiscly, the question is, how do i stop it excecuting the button scripts everytime the page loads(Thats my problem).(So when i have both Prev and Next on the page nothing happens, but when i have only 1, it excecutes fine(except if i refreash bthe page, it still does next/prev :P)

Code:
<?php
session_start();
session_register("comic");
if ($_SESSION['comic'] < 1){$_SESSION['comic'] = 1;}
echo $_SESSION['comic'];
?>
<body>
<img src="comic/<?=$_SESSION['comic']?>.jpg">

<form name="form1" method="post" action="<? $_SESSION['comic']++?>">
  <input type="submit" name="Next" id="Next" value="Next">
</form>
<form name="form2" method="post" action="<? $_SESSION['comic']--?>">
  <input type="submit" name="Prev" id="Prev" value="Prev">
</form>
</body>
Im really new to this sorry guys. This is the second script ive ever made.... (Although my first one is awesome, its a benchmarker for Server's and Browsers... My script found that Opera(9.5) is the fastest, then IE7 is second fastest, and Firefox(3 and 2) was slowest.)


Oh and making it a GET_ variable would be cool to if you guys could show me how to convert it .(You know, so if someone visits www.blahblah.com/blah.php?=5, it would be the 5th comic and stuff. Thanks! )

Last edited by mattisdada; 2008-03-15 at 05:24 AM.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2008-03-15, 05:25 PM
Junior Member
 
Join Date: Mar 2008
Posts: 6
mattisdada is on a distinguished road
Default

I had a huge long reply with explanation on everything(And then i accedentally quit opera), but anyway, for future refrence this is the solution.

Code:
<?php
session_start();
session_register("comic");
if ($_SESSION['comic'] < 1){$_SESSION['comic'] = 1;}

$Next_Prev = $_POST['Next_Prev'];
switch ($Next_Prev)
{
case 'Next':
$_SESSION['comic']++;
break;
case 'Prev':
if ($_SESSION['comic'] == 1){$_SESSION['comic'] = 1;}else {$_SESSION['comic']--;}
break;
}

echo $_SESSION['comic'];
?>

<body>
<img src="comic/<?=$_SESSION['comic']?>.jpg">

<form name="Next_Prev" method="post" action="">
  <input type="submit" name="Next_Prev" id="Next" value="Next">
  <input type="submit" name="Next_Prev" id="Prev" value="Prev">
</form>
</body>
My finnished comic engine project(Ill be making a theme engine for it soon enough)

comic.php
Code:
<?php
session_start();
session_register("comic");
require("config.php");
if ($_SESSION['comic'] < 1){$_SESSION['comic'] = 1;}
//print count(glob($comic_dir . "/*." . $ext . ""));
$Next_Prev = $_POST['Next_Prev'];
switch ($Next_Prev)
{
case 'Next':
$_SESSION['comic']++;
break;
case 'Prev':
if ($_SESSION['comic'] == 1){}else {$_SESSION['comic']--;}
break;
case 'First':
$_SESSION['comic'] = 1;
break;
case 'Latest':
$_SESSION['comic'] = count(glob($comic_dir . "/*." . $ext));
break;
}
echo $_SESSION['comic'];
?>
<body>
<img src="comic/<?=$_SESSION['comic']?>.jpg">
<form name="Next_Prev" method="post" action="">
  <input type="submit" name="Next_Prev" id="First" value="First">
  <input type="submit" name="Next_Prev" id="Prev" value="Prev">
  <input type="submit" name="Next_Prev" id="Next" value="Next">
  <input type="submit" name="Next_Prev" id="Latest" value="Latest">
</form>
</body>
config.php
Code:
<?php
// The directory of the comic's.
$comic_dir = "comic";
//The file extension your comics use.
$ext = "jpg";
?>
But for tyhis to be fully complete i need to know how to GET_ the comic variable.

Last edited by mattisdada; 2008-03-16 at 06:47 AM.
Reply With Quote
  #3 (permalink)  
Old 2008-03-16, 04:08 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,096
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

$_GET is just an array, so print_r($_GET); will show you everything in it.

You access it just like an array as well. so $_GET["comic"] is the value that is in the URI as comic=5. So $_GET["comic"] returns 5
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #4 (permalink)  
Old 2008-03-17, 06:32 AM
Junior Member
 
Join Date: Mar 2008
Posts: 6
mattisdada is on a distinguished road
Default

Yeah i understand that bit, but im not sure how to intergrate it with my buttons. Eg, when i press Next from comic 5, it will go to comic 6.

Ive sorta cheated out of it via session.

So how do i get around this?

Thanks in advance!
Reply With Quote
  #5 (permalink)  
Old 2008-03-18, 06:06 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,096
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

Its already done.

Instead of using $_SESSION["comic"] just use $_GET["comic"]. They do the same exact function in your case.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #6 (permalink)  
Old 2008-03-26, 01:32 AM
Junior Member
 
Join Date: Mar 2008
Posts: 6
mattisdada is on a distinguished road
Default

Uhhh, nah, it doesnt work
Code:
<?php
session_start();
session_register("comic");
require("config.php");
if ($_GET['comic'] < 1){$_GET['comic'] = 1;}
$count = count(glob($comic_dir . "/*" . $ext));
$Next_Prev = $_GET['Next_Prev'];
switch ($Next_Prev)
{
case 'Next':
$_GET['comic']++;
break;
case 'Prev':
if ($_GET['comic'] == 1){}else {$_GET['comic']--;}
break;
case 'First':
$_GET['comic'] = 1;
break;
case 'Latest':
$_GET['comic'] = $count;
break;
}
echo $_GET['comic'];
?>
<html>
<body>
<center>
<p><img src="comic/<?=$_GET['comic'] . $ext?>"></p>
<form name="Next_Prev" method="get" action="">
  <input name="Next_Prev" type="submit" class="test" id="First" value="First">
  <input type="submit" name="Next_Prev" id="Prev" value="Prev">
  <input type="submit" name="Next_Prev" id="Next" value="Next">
  <input type="submit" name="Next_Prev" id="Latest" value="Latest">
</form>
</center>
</body>
</html>
It does comic.php?Next_Prev=First, when i press First, and comic.php?Next_Prev=Next, when i press next.

Not comic.php?Comic=23
Reply With Quote
  #7 (permalink)  
Old 2008-04-08, 07:24 AM
Junior Member
 
Join Date: Mar 2008
Posts: 6
mattisdada is on a distinguished road
Wink

Some help would be greatly appricated.
Reply With Quote
  #8 (permalink)  
Old 2008-04-22, 07:17 AM
Junior Member
 
Join Date: Mar 2008
Posts: 6
mattisdada is on a distinguished road
Default

Anyone??! At all?
Reply With Quote
  #9 (permalink)  
Old 2008-04-22, 09:31 PM
Senior Member
 
Join Date: Dec 2004
Posts: 199
strasm is an unknown quantity at this point
Default

What is wrong specifically?
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:19 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.