質問

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