PHP frustrations

I have to go back and revisit some of the bare-bones PHP scripting. Just when I think I have a reasonable understanding, reality kicks me in the teeth. When I write SQL, thinks make sense. I know what I’m looking for and I can get the information I want. When I have to get PHP to do things with my results, that is where I encounter my frustrations. So, for example, if I need to get a value from a row, I can write:

Select color from socks where item = ‘1’

Ok, so now I have the color of of the socks in my inventory where my key (item) is one. Pretty straight forward.

Now lets make magic happen.

//$sql5 = ” Select color from socks where item = ‘1’

//$result3 = mysqli_query($conn,$sql5);

//$row3 = mysqli_fetch_assoc( $result3 );

//echo “Result: STATUS ” . $row3;

The result is red, which is the color form sock item 1. Good right? But what if I change my item to the number 2 in the database? Bad news, the result from my SQL shows me the color from item 1. What!? I re-checked my sql and ran it through the SQL client, everything is correct from that end. So obviously my code is fubared. Nothing is more humbling than realizing your understanding of how things should be isn’t really how they are. Back to the PHP manual I guess.

Leave a comment