php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29582 The Bug in if( xx && yy )
Submitted: 2004-08-09 08:43 UTC Modified: 2004-08-09 18:50 UTC
From: mydwin at msn dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.0.0 OS: Windows 2003 Enterprise
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mydwin at msn dot com
New email:
PHP Version: OS:

 

 [2004-08-09 08:43 UTC] mydwin at msn dot com
Description:
------------
-= The SQL is =-

CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `Name` varchar(50) collate utf8_bin NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=5 ;


INSERT INTO `test` VALUES (1, 0x61);
INSERT INTO `test` VALUES (2, 0x62);
INSERT INTO `test` VALUES (3, 0x63);
INSERT INTO `test` VALUES (4, 0x64);






-= the test.php code is =-

<pre><?php
$iFromID       = $_POST["FromID"]|0;
$iToID         = $_POST["ToID"]|0;

$DB = new mysqli( "localhost", "root", "", "testDB" );
if( $Temp_From=$DB->query( "SELECT * FROM test WHERE id=$iFromID" )->fetch_assoc() && $Temp_To=$DB->query( "SELECT * FROM test WHERE id=$iToID" )->fetch_object() )
{
	print_r($Temp_From);
	echo "\n\n\n";
	print_r($Temp_To);
}
?>
<form method="post" action="test.php">
<input name="FromID" value="1" />  <input name="ToID" value="2" />
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</form>
</pre>





Expected result:
----------------
Array
(
    [id] => 1
    [Name] => a
)



stdClass Object
(
    [id] => 2
    [Name] => b
)

Actual result:
--------------
1


stdClass Object
(
    [id] => 2
    [Name] => b
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-09 08:53 UTC] mydwin at msn dot com
By the Way.

We can't use this

$Temp_From=$DB->query( "SELECT * FROM test WHERE id=$iFromID"
)->fetch_assoc()[0];


but we can use it in this way
$Temp_From=$DB->query( "SELECT * FROM test WHERE id=$iFromID"
)->fetch_assoc();
$Temp_From=$Temp_From[0];
 [2004-08-09 18:50 UTC] pollita@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

This is expected behavior, use some parenthesis to separate your assignments from your boolean logic.

Also, take a look at DB::getOne(), it'll simplify what you're trying to do here.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 08:01:28 2024 UTC