0
while($row = mysqli_fetch_array($getCropsInvestor)){
        $cropID = $row['CropID'];
        $selectCrop = mysqli_query($con, "SELECT * FROM Crops WHERE ID=$cropID");
        $fetchCropData = mysqli_fetch_array($selectCropData,MYSQLI_ASSOC);
        if($fetchCropData){
            echo 'Suc';
        }
        else{
            echo 'Fail';
        }
        $checkAvail = $fetchCropData['Availability'];

Can someone explain to me why this code returns Fail
and a solution on how to achieve this goal.

0

2 Answers 2

3

The query result stored in $selectCrop.

$selectCropData should be $selectCrop.

$fetchCropData = mysqli_fetch_array($selectCrop,MYSQLI_ASSOC);..

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

2 Comments

oh damn how can i be so dense. i didn't even notice that. i though fetching array inside a fetch is unavailable. thank you for this. i'll accept this after 10 mins
I would suggest you to use JOINs if possible.
0

When Query Executed

$selectCrop = mysqli_query($con, "SELECT * FROM Crops WHERE ID=$cropID");

this result is stored in $selectCrop so use $selectCrop instead of $selectCropData in mysqli_fetch_array

$fetchCropData = mysqli_fetch_array(**$selectCrop**,MYSQLI_ASSOC);

Thats all .... Happy coding

1 Comment

I suggest yo to use PDO to handle these errors better

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.