douguan3470 2016-10-04 08:09
浏览 104

如果在smarty中它们不等于null时如何隐藏行

I have a question Because i want to now how i can hide rows when there not equal to null Because a player needs to have the item to go to that location ' So any help is appreciate

Index.php

<?php
session_start();
require_once ('inc/loadsmarty.php');
require_once ('inc/Location.class.php');
require_once ('inc/DBconnection.php');
require_once ('inc/Choice.class.php');
require_once ('inc/Inventory.class.php');

$location_id =  (isset($_GET['location_id']) ? $_GET['location_id'] : 1);   // kijk welke locatie wordt gevraagd
$errors = [];       // hou fouten bij in deze array
$loc = new Location();  // maak lege locatie aan
$did_load_work = $loc->LoadFromDb($mysqli, $location_id);       // laad locatie en choices vanuit de database
if ($did_load_work == false) {    // als het laden fout ging, voeg dan een error toe aan de array $errors
    array_push($errors, "This location does not exist in the database");
}

if($location_id == 22 ) {
    $_SESSION['Paddle'] = true;
}

if ($location_id == 23) {
    $_SESSION['Basebalbat'] = true;
}

if ($location_id == 24) {
    $_SESSION['Axe'] = true;
}

if ($location_id == 26) {
    $_SESSION['Hammer'] = true;
}

// Make Session End 2 when you reached location 27
if($location_id == 27) {
    $_SESSION['End2'] = true;
}

/*
if (isset($loc)) {
    if (is_null($loc->Choices)) {
        //  Load choice->to_id 25
        echo "Hello Friend";
    }
    var_dump($loc);
}
*/

$smarty->assign('pagetitle', 'Games to play');
$smarty->assign('errors', $errors);         // geef lege of gevulde array $errors mee
$smarty->assign('location', $loc);          // geef locatie (en daarin de choices) mee
$smarty->assign('location', $loc);          // geef locatie (en daarin de choices) mee
$smarty->display("tpl/index.html.tpl");

if (isset($_SESSION['Paddle']) || isset($_SESSION['End2']) || isset($_SESSION['Hammer']) || isset($_SESSION['Axe']) || isset($_SESSION['Basebalbat'])) {

            echo "<div id=\"msg\"> You have picked up the item";
            $converted = settype($location_id, 'integer');
            $converted = settype($loc->id, 'integer');
            echo "<br />";

    switch ($location_id) {
        case $location_id == 22:
            echo "You picked up the paddle";
            echo "<br />";
        break;
        case $location_id == 23;
            echo "You picked up the Basebalbat";
            echo "<br />";
        break;
        case $location_id == 24;
            echo "You picked up the Axe";
            echo "<br />";
            break;
        case $location_id == 26;
            echo "You picked up a hammer";
            echo "<br />";
            break;
        default:
            echo "no items has been picked up";
            echo "<br />";
    }
}

Index.tpl

<html>
<head>
    <title> {$pagetitle} </title>
    <link rel="stylesheet" href="css/style.css" type="text/css">
</head>

<body>
    <div class="plaatje">
    {if isset($errors) }
        <p style="border: 1px solid red;">
        <ul>
            {foreach $errors as $error}
                <li>{$error}</li>
            {/foreach}
        </ul>
    {/if}

    {if isset($location) }
        <h1>{$location->Title }</h1>
        <p>{$location->Story }</p>
        {$location->Foto_url }
        {/if}

        <ul>
            {foreach $location->Choices as $choice}
                <!-- change the string output to a int value  -->
                {$choice->to_id|intval}
                <!-- looks of  Choice->to_id  is equal to 22 or 23 or 24 or 25 then change them -->
                <!-- First looks of $_SESSION['Pickup'] Exist -->
                {if isset($smarty.session.Paddle)}
                {if $choice->to_id == 22}
                    <p class="hide"> Nothing Here Friend</p>
                {else}
                    <li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
                {/if}
                    {elseif isset($smarty.session.End2)}
                    {if $choice->to_id == 25}
                        <p class="hide"> Nothing Here Friend</p>
                    {/if}
                    {elseif isset($smarty.session.Basebalbat)}
                    {if $choice->to_id == 23}
                        <p class="hide"> Nothing Here friend</p>
                    {else}
                        <li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
                        {/if}
                    {elseif isset($smarty.session.Axe)}
                    {if $choice->to_id == 24}
                        <p class="hide"> Nothing Here friend</p>
                    {else}
                        <li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
                        {/if}
                    {elseif isset($smarty.session.Hammer)}
                    {if $choice->to_id == 26}
                        <p class="hide"> Nothing Here friend</p>
                    {else}
                        <li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
                        {/if}
                    {else}
                    <li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
                {/if}
                {if $location->id == 25}
                    {session_unset()}
                    {session_destroy()}
                {/if}
                {if $choice->need_item_id != ""}
                    <p> Hello </p>
                {/if}
                <!-- <li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li> -->
            {/foreach}
        </ul>

        <ul>
            {foreach $location->Inventory as $hello}
               <li> {$hello->player_id} {$hello->item_id} {$hello->space}</li>
            {/foreach}
        </ul>

    </div>
</body>
</html>

Player go by location for some locations is a item id needed As question i ask when the player has the item not in his inventory how do i hide that then

here is the class for the game

Location.class.php

<?php

require_once ("DBconnection.php");
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 300); //300 seconds = 5 minutes

class Location
{
    public $id;
    public $Title;
    public $Foto_url;
    public $Story;
    public $Choices = [];
    public $Inventory = [];

    function LoadFromDb($mysqli, $id)
    {
        $sql = "SELECT * FROM locations WHERE id=" . $id . ";";
        $results = $mysqli->query($sql);

        if ($results->num_rows >= 1) {
            $record = $results->fetch_assoc();
            $this->id = $record['id'];
            $this->Title = $record['Title'];
            $this->Foto_url = ('<img src="' . $record['Foto_url'] . '">');
            $this->Story = $record['Story'];

        }

        // load choices
        $sql = "SELECT * FROM choices WHERE from_id=" . $id . ";";
        $results2 = $mysqli->query($sql);

        while ($record = $results2->fetch_assoc()) {
                    $choice = new Choice();
                    $choice->id = $record['id'];
                    $choice->from_id = $record['from_id'];
                    $choice->to_id = $record['to_id'];
                    $choice->title = $record['title'];
                    $choice->need_item_id = $record ['need_item_id'];
                    array_push($this->Choices, $choice);
            }

    // Load inventory
        $sql = "SELECT * FROM inventory";
        $results3 = $mysqli->query($sql);

        while ($row = $results3->fetch_assoc())  {
            $item = new Inventory();
            $item->id = $row['id'];
            $item->player_id = $row['player_id'];
            $item->item_id = $row['item_id'];
            $item->space = $row['space'];
            array_push($this->Inventory, $item);
        }
        return true;
    }
}
  • 写回答

1条回答 默认 最新

  • drt5813 2016-10-06 07:21
    关注

    I closed bye this i have found a soultion on my own so apprecite for all the support

                {if $choice->need_item_id}
                    {foreach $location->Inventory as $itm}
                        {if $itm->item_id == $choice->need_item_id}
                            <p class="hide"> YOU HAVE IT  </p>
                        {else}
                        <p class="item"> Go search the item {$choice->need_item_id}</p>
                        {/if}
                    {/foreach}
                    <!-- So yes then show the choice -->
                {/if}
    
    评论

报告相同问题?

悬赏问题

  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗