|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2007-03-20 17:45 UTC] tony2001@php.net
  [2007-03-20 18:07 UTC] robert dot allen at unearthtravel dot com
  [2007-03-20 18:12 UTC] tony2001@php.net
  [2007-03-20 18:15 UTC] robert dot allen at unearthtravel dot com
  [2007-03-20 18:23 UTC] tony2001@php.net
  [2007-03-20 18:25 UTC] tony2001@php.net
  [2007-03-20 18:40 UTC] robert dot allen at unearthtravel dot com
  [2007-03-20 18:45 UTC] tony2001@php.net
  [2007-03-20 18:50 UTC] robert dot allen at unearthtravel dot com
  [2007-03-20 18:56 UTC] tony2001@php.net
  [2007-03-20 21:34 UTC] robert dot allen at unearthtravel dot com
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 02:00:02 2025 UTC | 
Description: ------------ Hi We are getting an odd result when submitting a query to a mysql server (4.1.10), we get a different result when performing the query through php (an incorrect result) as opposed to straight in to a mysql client. It seems to have performed the sub-query twice, so the variable @j has been incremented twice. A simplified version of our code is shown below and reproduces the problem, I have also included a sample table. I have seen it on both windows and linux. Reproduce code: --------------- mysql_query("SET @j=0;"); $sql = "select offset from (select @j:=@j+1 as offset, if(element_id=2,1,0) as result from element) as t1 WHERE t1.result=1 "; $result = mysql_query($sql); $row = mysql_fetch_row($result); echo $row[0]; /******************DATABASE****************/ CREATE TABLE `element` ( `element_id` int(10) unsigned NOT NULL auto_increment, `element_type_id` int(10) unsigned NOT NULL default '0', `lock_level` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`element_id`), KEY `new_index` (`element_type_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*Data for the table `element` */ insert into `element`(`element_id`,`element_type_id`,`lock_level`) values (1,1,0); insert into `element`(`element_id`,`element_type_id`,`lock_level`) values (2,10,0); insert into `element`(`element_id`,`element_type_id`,`lock_level`) values (3,2,0); insert into `element`(`element_id`,`element_type_id`,`lock_level`) values (4,10,1); insert into `element`(`element_id`,`element_type_id`,`lock_level`) values (5,2,0); Expected result: ---------------- 2 Actual result: -------------- 7