Unsupported error operand types

Asked

Viewed 389 times

1

When I import the immovable xml it does the math according to the criteria. One of the criteria is the price, the most expensive appear first, for that I divided the price value by 10 million and sum the result in his ranking.

Ex: Property with 1500+ (price of 10,000,000/10,000,000) = 1501

But when I do this count, it stops the import and makes this mistake:

Unsupported error operand types on line 332

Which is the line where the code if ends below:

if ($tipo==Venda){
$ordem = $ordem + $preco/10000000;
}

Does anyone know what might be going on?

  • First: are there any quotation marks involving the term "Sale" in the condition? Second: what are the types of variables?

1 answer

2

To "debug" variables before the if do:

var_dump($ordem, $preco);
if ($tipo==Venda){

And then you’ll notice the problem, $ordem or $preco are not numbers, one of them must be a array or null and then it will not be possible to do the mathematical operation, which causes the error.

This must be happening because it is using in a while or for without checking the values being used added to $ordem and $preco, you may also be using the variable in different places, like trying to repurpose a variable to do two things, something that can actually cause a lot of problems.

Another problem, which may not have a direct connection, is the if that "seems" to be wrong:

if ($tipo==Venda){

The Venda it would have to be like this 'Venda', unless the sale is a constant (but this is another problem).

  • gave this here: int(1100) string(10) "1638000.00" int(1100) string(10) "6500000.00" int(1600) string(10) "4500000.00" int(100) array(0) { }

  • See @Leandroteraoka one of them showed array(0) { }, that is one of the calls this receiving array, have to fix inside your while (I believe it’s the bank’s results)

  • sorry, don’t understand, don’t manjo mt. has as I know who is coming as array?

  • Where does the value of $ordem? Is it from the database (of a while)? Put the whole code in Pastebin.com for me to see

  • Sorry, I said database, but in fact the problem must be in a xml content is, some of them must be the price and the XML parse must be taking as if it were an empty "tag", which is converted to an empty array. I’m just guessing, without the code, there’s no way to help more than this.

  • the code is giant...rs, the $price that is giving error. I set it to $price=4500000 before the if, then it did not give error and worked right. the $price is set thus $price = $Property['price'];. it takes the value of xml that is in <price>4500000.00</price> if I play the $price in the database price field, it appears the normal value (ex: 450000.00)

  • @Leandroteraoka try to create a minimum example that reproduces the error and send me.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.