PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,403 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,633 people online right now. Registration is fast and FREE... Join Now!




Main page for a feature

 

Main page for a feature

Decypher

26 Jun, 2009 - 01:05 PM
Post #1

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
Hey guys, I did have this working at one point but somehow I've broke it and unsure how to fix it as I've tried many methods but still not working.

I want to have it so on the front page if your not currently in a 'Heist' you see the main featue page which is some words, a start button and an invite section.

Then if you start a heist it should show a different page (heistinvite.php)

If you accept an invite it should send you to (heistaction.php)
if player 2 has accepted player one should go to (heistaction.php) instead of (heistinvite.php)

apologies in advance...btw I currently use dreamweaver while coding, is there any other softtware that would improve on my layout of coding?

CODE

if (isset($_SESSION['userid'])) {
    // this is because i dont like MySQL timestamp i like the UNIX style
    function revertheisttime($str) {
        list($date, $time) = explode(' ', $str);
        list($year, $month, $day) = explode('-', $date);
        list($hour, $minute, $second) = explode(':', $time);

        $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
        return $timestamp;
    }

    $q = "SELECT heisttimer FROM login WHERE id='".$_SESSION["userid"]."'";
    $r = mysql_query($q);
    $v = mysql_fetch_array($r);
    $lastActive = revertheisttime($v['heisttimer']);

    if (($lastActive + (60*60*12) - time() > 0)) { // 10*60 = 10 minutes change 10 to 5 if you want 5 min
        // session expired send to index
        $result = $lastActive + (60*60*12) - time();
        $result2 = $result / 60;
        echo 'You cannot commit another heist for '; echo ceil ($result2); echo' minutes.';
    } else { ?>

<?
$user ="SELECT username, id FROM login WHERE id= '".$_SESSION["userid"]."'";
$result = mysql_query($user);
$row = mysql_fetch_assoc ($result);

$username = $row['username'];

$heist="SELECT player1, invitation, player2, reward FROM heist WHERE player1 = '".$username."'";
$heistresult = mysql_query($heist);
while ($rowi = mysql_fetch_array($heistresult)){
    $player1 = $rowi['player1'];
    $player2 = $rowi['player2'];
    $invitation = $rowi['invitation'];
    $reward = $rowi['reward'];
    
    if ($player1 == $username && $player2 == ''){
        header ('Location: heistinvite.php');
    }else{
        
    if ($player2 == $invitation){
        header ('Location: heistaction.php');
           
$heist="SELECT player1, player2 FROM heist WHERE player2 = '".$username."'";
$heistresult = mysql_query($heist);
while ($rowi = mysql_fetch_array($heistresult)){
    $player1 = $rowi['player1'];
    $player2 = $rowi['player2'];
    
    if ($player2 == $username){
        header ('Location: heistaction.php');
    }else{

?>
(You must be at least rank 2 to attempt a Heist)<br><br>

To perform a Getaway, you and your partner must be in the same state. You must use a stabled animal of your choice as well as your partner purchasing extra equipment.
It will cost you $5,000 to start a Getaway. Please be advised that once started you will not be able to cancel unless you wish to lose your deposit.<br><br>
<form action="startheist.php" method="post">
<input type="submit" value="Begin Heist"></form>
<br><br><b>Invites</b><br>
<form action="heistaccept.php" method="post">
<table border="1" bordercolor="#000000">
<?php
$heist="SELECT player1, invitation FROM heist WHERE invitation = '".$username."'";
$heistresult = mysql_query($heist);
$rowi = mysql_fetch_array($heistresult);
    $player1 = $rowi['player1'];
    
echo'<tr><td>Invitation From</td><td><input type="checkbox" name="inviter" value="'.$player1.'"> ';echo $player1; echo'</td></tr>
'; ?><br><br></table>
<input type="submit" value="Accept!"><input type="submit" name="deny" value="Deny!"></form>
<? }} }}} }}?>




User is offlineProfile CardPM
+Quote Post


CTphpnwb

RE: Main Page For A Feature

27 Jun, 2009 - 04:55 AM
Post #2

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
1) Where is it failing?

2) Dreamweaver vs others: I use TextWrangler (Mac only) but any good text editor should do. Anything that's going to do things for you probably isn't a good idea until you've mastered the language, and that would apply to any language. In other words: be sure that you've worked on your skills before you look for something to help speed things up!
User is offlineProfile CardPM
+Quote Post

SilentRoss

RE: Main Page For A Feature

27 Jun, 2009 - 07:17 AM
Post #3

New D.I.C Head
*

Joined: 23 Jun, 2009
Posts: 11


My Contributions
If you told us the error or what its not doing would really help us understand your situation
smile.gif
User is offlineProfile CardPM
+Quote Post

Decypher

RE: Main Page For A Feature

29 Jun, 2009 - 09:01 AM
Post #4

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
hi, sorry for the late reply I've been at my girlfriends for the weekend so obviously not been able to check this site anime2.gif

Erm, I've decided that since I've done it before, I can obviously do it again...so going to completely re-do the page...Thanks for the advice thou about other softwares...

but the problem was the if statements weren't working as I wanted as I just got no result when I should of...
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: Main Page For A Feature

29 Jun, 2009 - 09:28 AM
Post #5

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
QUOTE(Decypher @ 29 Jun, 2009 - 01:01 PM) *

but the problem was the if statements weren't working as I wanted as I just got no result when I should of...

Engineers often talk about black boxes because they're very useful. The idea is that you have a bunch of black boxes which produce the results you want, and you don't care how they do it unless you're working on a box. Using this approach way you break up the system into smaller an smaller boxes which you can get working one at a time until the whole thing works. Do this with your if statements by running small sections of code in separate files so that you can debug them one at a time.

User is offlineProfile CardPM
+Quote Post

Decypher

RE: Main Page For A Feature

1 Jul, 2009 - 11:32 AM
Post #6

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
Thanks for the idea in the future but I don't think it'll work for what I'm stuck on now....

Ok after re-making the page, I've got it all to work again apart from if the user has already completed a heist and therefore already in the table...

if they haven't completed a heist before it'll send them straight to the heist page, However if they've already completed a heist it automatically sends them to the next page (heistaction.php) I'm unsure h0w tp resolve this and tried adding in the if statements:
&& reward == ''

but I've come to realise that won't work either...

any ideas?
CODE
$user="SELECT * FROM login WHERE id='".$_SESSION["userid"]."'";
$userresult = mysql_query($user);
$row = mysql_fetch_array($userresult);

$username = $row['username'];

$heist ="SELECT * FROM heist WHERE player1 = '".$username."'";
$heistresult = mysql_query($heist);
$row = mysql_fetch_array($heistresult);

$player1 = $row['player1'];
$player2 = $row['player2'];
$invitation = $row['invitation'];
$reward = $row['reward'];

// Making player 1 go to the player invite page if they haven't invited anyone or no-one
// has accepted the invite yet
if($player1 == $username && $invitation == ''){
    header('location: heistinvite.php');

} else {

// Making player 1 go to the page that involves the items if player one has got someone to accpet the invite.
if($player1 == $username && $player2 != ''){
    header ('location: heistaction.php');

} else {
// making player 2 go to the next page if they accept the invite
$heist2="SELECT * FROM heist WHERE player2 = '".$username."'";
$heist2result = mysql_query($heist2);
$rowi = mysql_fetch_array($heist2result);

$play2 = $rowi['player2'];

if ($play2 == $username){
    header ('location: heistaction.php');
} else {
    ?>
(You must be at least rank 2 to attempt a Heist)<br><br>

To perform a Getaway, you and your partner must be in the same state. You must use a stabled animal of your choice as well as your partner purchasing extra equipment.
It will cost you $5,000 to start a Getaway. Please be advised that once started you will not be able to cancel unless you wish to lose your deposit.<br><br>
<form action="startheist.php" method="post">
<input type="submit" value="Begin Heist"></form>
<br><br><b>Invites</b><br>
<form action="heistaccept.php" method="post">
<table border="1" bordercolor="#000000">
<?

$heist ="SELECT * FROM heist WHERE invitation = '".$username."'";
$heistresult = mysql_query($heist);
$row = mysql_fetch_array($heistresult);

$player1 = $row['player1'];

echo'
<tr><td>Invitation From</td><td><input type="checkbox" name="inviter" value="'.$player1.'"> ';echo $player1; echo'</td></tr>
<br><br></table>
<input type="submit" value="Accept!"><input type="submit" name="deny" value="Deny!"></form>';

} // end of first if statement
} // end of second if statement
} // end of third if statement


User is offlineProfile CardPM
+Quote Post

JBrace1990

RE: Main Page For A Feature

1 Jul, 2009 - 11:52 AM
Post #7

D.I.C Addict
Group Icon

Joined: 9 Mar, 2008
Posts: 599



Thanked: 45 times
Dream Kudos: 350
My Contributions
I use NuSphere =)
User is offlineProfile CardPM
+Quote Post

TTechGuy

RE: Main Page For A Feature

1 Jul, 2009 - 02:05 PM
Post #8

D.I.C Head
**

Joined: 24 Apr, 2009
Posts: 57



Thanked: 3 times
My Contributions
Are you creating a new heist record for each heist? If you are then all you have to do is to select where reward is null. Then you will not see previous completed heists but will see current active heists.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:30PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month