1

I am attempting to execute a php query with no results. I have been trying to get it to work for hours and figure another set of eyes would be helpful. Here is my script:

if(!empty($cLvl))
{
    $result = $conn->query("SELECT lvl" . $cLvl . " 
    FROM buyers WHERE buyer_id = $buyer");

    $comRate = $result->fetch_assoc();
}
print_r($comRate); die;

$buyer is found by:

$result = $conn->query("select source_id from inventory where sku = {$data[$n]['sku']}");
if($result) {$buyer = $result->fetch_assoc();}

and $cLvl is found by:

if($data[$n]['cost'] == 0 || $bookType3['book_type_3'] == "DMG")
{
    $cLvl = null;
}
elseif($bookType['book_code'] == "IE" || $bookType['book_code'] == "AIE")
{
    $cLvl = 3;
}
elseif($cId['condition_id'] == 1 || $cId['condition_id'] == 2 || $cId['condition_id'] == 3 || $cId['condition_id'] == 4 || $follett['class_code'] == "D" || strpos($follett['notes'],"(T)") == true)
{
    $cLvl = 2;
}
elseif($cId['condition_id'] == 5)
{
    $cLvl = 1;
}

in my testing $buyer = 263 and $cLvl = 3. However when I try to find $comRate, it returns nothing. If I hard code in the information I get a result, but this is going to run about 250 records and I can't be hardcoding each one.

Where am I going wrong with this??

1 Answer 1

1

A whole lot is wrong with this code, but what you're asking for is probably that your $buyer is an assoc array, you want to use {$buyer['source_id']} instead.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the info., I tried that and I am still not getting anything out of my print_r($comRate). Any other thoughts?
try printing out "SELECT lvl" . $cLvl . " FROM buyers WHERE buyer_id = $buyer" ?
I get SELECT lvl 3 FROM buyers WHERE buyer_id = 263 when I echo"SELECT lvl" . $cLvl . " FROM buyers WHERE buyer_id = $buyer['source_id']" which is the result I need, but that is as far as it is going.
What is this space between lvl and 3?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.