douyu3145 2019-03-27 06:30
浏览 60

PHP Smarty在SQL Query中爆炸foreach和foreach

The process I want to do; I'm breaking data from the database using the Explode process. "SELECT * FROM roomsFeatures WHERE slug = '$foreachItem'". Everything's up to here. For example there are 15 data, I need to implement foreach in smarty. Below are my codes

My Explode Code [roomsController.php]

$features =  explode("|", $getdata['roomFeatures']);


foreach($features as $feature){
    $getFeature = $connection->prepare("SELECT * FROM roomsFeatures WHERE slug = '$feature'");
    $getFeature->execute();
    $getFeature = $getFeature->fetch();

    print_r($getFeature);
}

##RESULT 15 ROW
Array
(
    [id] => 1
    [0] => 1
    [name] => Yatak Odası
    [1] => Yatak Odası
    [slug] => yatakodasi
    [2] => yatakodasi
    [miniDescription] => Çift ya da tek kişilik seçenekleri, konforlu ve ergonomik yatakları, ihtiyaç dahilindeki ek servisleri ile hizmetinizdedir.
    [3] => Çift ya da tek kişilik seçenekleri, konforlu ve ergonomik yatakları, ihtiyaç dahilindeki ek servisleri ile hizmetinizdedir.
    [icon] => fas fa-tv propertyIcons
    [4] => fas fa-tv propertyIcons
    [createAt] => 2019-03-26 21:12:34
    [5] => 2019-03-26 21:12:34
)
Array
(
    [id] => 2
    [0] => 2
    [name] => Banyo
    [1] => Banyo
    [slug] => banyo
    [2] => banyo
    [miniDescription] => Hijyenik yapısı ve konforlu kullanımı ile hizmetinizdedir. Tüm odalarda olduğu gibi Standart Oda banyolarında ihtiyacınız olabilecek tüm materyalleri bulabilirsiniz.
    [3] => Hijyenik yapısı ve konforlu kullanımı ile hizmetinizdedir. Tüm odalarda olduğu gibi Standart Oda banyolarında ihtiyacınız olabilecek tüm materyalleri bulabilirsiniz.
    [icon] => fas fa-shower propertyIcons
    [4] => fas fa-shower propertyIcons
    [createAt] => 2019-03-26 21:13:37
    [5] => 2019-03-26 21:13:37
)
..
.

How do I include the TPL file and the foreach query from the foreach? I couldn't make the connection between the controller and the TPL.

 <div class="col-xl-3 roomProperties">
    <div class="propertyFunctions"><i class="{$item.icon}"></i>
 <h4 class="propertyHeader">{$item.name}</h4>
 <p class="propertyText">{$item.miniDescription}</p>
     </div>
   </div>

Must be tpl File

{foreach $fromSomewhereArray as $item}
 <div class="col-xl-3 roomProperties">
    <div class="propertyFunctions"><i class="{$item.icon}"></i>
 <h4 class="propertyHeader">{$item.name}</h4>
 <p class="propertyText">{$item.miniDescription}</p>
     </div>
   </div>
{/endforeach}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据