开发者

The Select query I am using is not working.. Can Somebody Guide me to the Correct way?

开发者 https://www.devze.com 2022-12-28 00:14 出处:网络
I am using the Select query as SELECT id, ordering FROM `jos_menu` WHERE ordering=\'\".$rec[\'ordering\'] -\'1\' .\"\' AND parent = \'0\'

I am using the Select query as

SELECT id, ordering FROM `jos_menu` WHERE ordering='".$rec['ordering'] -'1' ."' AND parent = '0'

Here I need all the records whose ordering is less than 1 of the selected record's order($rec['ordering'] = getting from other select query ) when I am trying to echo the query I am not getting complete statement but getting only this -1' AND parent = '0'

here is the whole snippet

$where = ' WHERE (id = ' . implode( ' OR id = ', $cid ) . ')';//Pranav Dave Coded
    echo $selquery = "SELECT id, ordering FROM `jos_menu`".$where;          //Pranav Dave Coded
        $db->setQuery( $selquery );//Pranav Dave Coded
        $record = $db->loadAssocList(); //Pranav Dave Coded

    if ($model->orderItem($id, -1)) {
    echo "<pre>";
    print_r($model);
    /*exit;*/

    //echo $updorderup = mysql_escape_string($model->_db->_sql);//Pranav Dave Coded

        foreac开发者_开发百科h($record as $rec)//Pranav Dave Coded
        {
            echo $aboverow = "SELECT id, ordering FROM `jos_menu` WHERE ordering='".$rec['ordering'] -'1' ."' AND parent = '0'";
            $db->setQuery( $aboverow );
        $above = $db->loadAssoc();
        echo "<pre>";
    print_r($above);
                    }//end of foreach
                 }//end of if

Please suggest me where I am getting wrong.....


It looks like you may need to unwrap the -1 from the quotes:

WHERE ordering='".($rec['ordering'] - 1)."' AND parent = '0'";


Why do you trying to put everything inline?
Why not to make some preparations first?
Why not to compare resulting query with sample one?
Why don't you check every step if it return proper result?

$val = $rec['ordering'] - 1;
//let's see if $cal has proper value:
echo $val."<br>";
$sql = "SELECT id, ordering FROM `jos_menu` WHERE ordering = $val AND parent = 0";
//let's see if query looks good:
echo $sql;
//let's print sampe query to compare:
echo "<br>" ;
echo "SELECT id, ordering FROM `jos_menu` WHERE ordering = 1 AND parent = 0";


As Daniel said, you need to remove the quotes around the -1. Currently its trying to minus a string, which it wouldn't be happy with at all ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消