leroy Mckenzi Posted August 17, 2011 Share Posted August 17, 2011 In the following code i'm using If/else statement to display games played by the user. But the php code somewhere is wrong but i'm not able to figure it out, so far the logic according to me is right. The code explains that if the user has not played any games it should show the message as "you have not played any games please goto the link to play games.<a href="">Games</a>" The problem is in the if/else statement, Even if the user has played any games its still showing that you have not played any games. here is the code : <?php session_start(); include_once("includes/checksession.php"); include_once("includes/appconfig.inc.php"); include_once("common/meta.php"); require_once("includes/mysql.inc.php"); include_once("classes/dbconn.class.php"); include_once("classes/games.class.php"); $prefix = "p"; $uid = $_session['uid']; $games = new Games; ?> <body> <div > <!----------------------H-E-A-D-E-R----------------------> <?php include("common/maintop.php"); ?> <!----------------------H-E-A-D-E-R----------------------> <!----------------------M-E-N-U----------------------> <?php include("common/topnav3.php"); ?> <?php include("common/topsubnav.php"); ?> <!----------------------M-E-N-U----------------------> <div id="long"> <!----------------------M-A-I-N-B-O-D-Y----------------------> <!--UPPER--> <div class="main_p"> <!--Sidebar--> <?php if(isset($_SESSION['uid'])){ include("common/rightnavloggedin.php"); }else{ include("common/rightnav.php"); } $flipper = 0; $dice = 0; $arrGamescount = $games->myGamesCount($prefix, $uid); if(count($arrGamescount)>0) { foreach($arrGamescount as $rows) { if($rows['game_id'] == 1 || $rows['game_id'] == 2 || $rows['game_id'] == 3) { $flipper++; } if($rows['game_id'] == 4 || $rows['game_id'] == 5 || $rows['game_id'] == 6) { $dice++; } } } if($flipper > $dice) { $game1 = "<div id=\"game_thumb\"><div id=\"game_name\">Flipper Challenge</div> <a href=\"games/Flipper-Challenge/main/Intro.html\" onClick=\"return flipperpopup(this, 'Flipper-Challenge')\"><img src=\"images/thumbs/flipper.jpg\"></a></div>"; $game2 = "<div id=\"game_thumb\"><div id=\"game_name\">7 Up-Down: Dice Duel</div> <a href=\"games/7-Up-Down-Dice-Duel/main\" onClick=\"return dicepopup(this, '7-Up-Down-Dice-Duel')\"><img src=\"images/thumbs/7-up-down-dice-duel.jpg\"></a></div>"; } else { $game1 = "<div id=\"game_thumb\"><div id=\"game_name\">7 Up-Down: Dice Duel</div> <a href=\"games/7-Up-Down-Dice-Duel/main\" onClick=\"return dicepopup(this, '7-Up-Down-Dice-Duel')\"><img src=\"images/thumbs/7-up-down-dice-duel.jpg\"></a></div>"; $game2 = "<div id=\"game_thumb\"><div id=\"game_name\">Flipper Challenge</div> <a href=\"games/Flipper-Challenge/main/Intro.html\" onClick=\"return flipperpopup(this, 'Flipper-Challenge')\"><img src=\"images/thumbs/flipper.jpg\"></a></div>"; } ?> <!--Sidebar--> <!--Gellery--> <div id="box"> <div id="games_outer_case"> <?php if($flipper>0) { echo $game1; } elseif($dice>0) { echo $game2; } else { echo "<div >You din't play any games yet click on the link below to visit our games page</div>"."<br>"; echo '<a href="http://www.funterr.com/games.php">Games</a>'; } ?> </div> </div> ?> Quote Link to comment https://forums.phpfreaks.com/topic/245013-problem-in-executing-ifelse-statement/ Share on other sites More sharing options...
leroy Mckenzi Posted August 17, 2011 Author Share Posted August 17, 2011 in the section where code is $rows['game_id'] == 1 || $rows['game_id'] == 2 || $rows['game_id'] == 3 ........ 'game_id'1,2,3 are indicating flipper game played with Prediction , Predisclosed and Multiplayer same follows for dice game where 'game_id'= 4,5,6 are indicating dice game played with Prediction , Predisclosed and Multiplayer... Quote Link to comment https://forums.phpfreaks.com/topic/245013-problem-in-executing-ifelse-statement/#findComment-1258511 Share on other sites More sharing options...
@ Posted August 18, 2011 Share Posted August 18, 2011 add this print_r($arrGamescount); die(); below this line $arrGamescount = $games->myGamesCount($prefix, $uid); and post the output please Quote Link to comment https://forums.phpfreaks.com/topic/245013-problem-in-executing-ifelse-statement/#findComment-1258965 Share on other sites More sharing options...
leroy Mckenzi Posted August 18, 2011 Author Share Posted August 18, 2011 I tried and it printed the array, the output that I got is this Array ( [0] => Array ( [id] => 834 [uid] => leroy1260 [game_id] => 0 [txn] => 748915632 [combo] => [game_combo_hr] => 2011081714 [user_combo] => DD [prefix] => p [result] => [cdate] => 2011-08-17 05:13:22 [mdate] => 2011-08-17 05:13:22 ) [1] => Array ( [id] => 811 [uid] => leroy1260 [game_id] => 4 [txn] => 0 [combo] => [game_combo_hr] => 2011081015 [user_combo] => DDUDD [prefix] => p [result] => [cdate] => 2011-08-10 06:18:34 [mdate] => 2011-08-10 06:18:34 ) [2] => Array ( [id] => 813 [uid] => leroy1260 [game_id] => 4 [txn] => 0 [combo] => [game_combo_hr] => 2011081116 [user_combo] => DUU77 [prefix] => p [result] => [cdate] => 2011-08-11 06:52:11 [mdate] => 2011-08-11 06:52:11 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/245013-problem-in-executing-ifelse-statement/#findComment-1258973 Share on other sites More sharing options...
leroy Mckenzi Posted August 18, 2011 Author Share Posted August 18, 2011 @ The above output that I posted is shown only if the games are already played by the user. This not the case in new registered users i.e. the output shown is blank for new users when I use print_r(arrGamescount); die(); Quote Link to comment https://forums.phpfreaks.com/topic/245013-problem-in-executing-ifelse-statement/#findComment-1258976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.