문제

I need 2 index pages 1. index.php 2. index2.php

that render depend on if the query return back any result.

something like this:

    $sql = 'id = $id AND field LIKE ¥'%word%¥' ';

    $sql = 'id = $id and MATCH(field) AGAINST (¥'word' IN BOOLEAN MODE)';

    $query=$connection->createCommand($sql)->queryRow();

    if ($query== true) {
    $this->render('index1', array()
    } else {
    $this->render('index', array()
    }
도움이 되었습니까?

해결책

You can do this. But it seems you are getting error in lines before rendering your view. The problem is here that you are writing bad string. In php when you want to add variable into string directly you must use double quotation instead of single.

for example:

$name="test";

// RIGHT
$test="hello $name";
//WRONG
$test='hello $name';

if you want to add variable with a single quotation you must devide your string and variable by using dot(.);

for example:

$name="test";
$test='hello '.$name;

So this is the reason you give an error before rendering your views.

다른 팁

dear friend beside single quotation mistake you got there and not putting % for LIKE commad you forgot closing brackets and semicolon! use a better IDE man!

if ($query== true) {
    $this->render('index1', array());
} else {
    $this->render('index', array());
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top