0

I did a SQL request with php and everything works fine, but when i do a SQL request inside the while loop i only get 1 results of the first 'kenmerk'.

// Per kenmerk
$query = "SELECT kenmerk FROM kenmerken WHERE user_id = ".$user."";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($result))
{
    $query = "SELECT gezette_vruchten, uitgroeiduur FROM gewasregistratie WHERE user_id = ".$user." AND kenmerk = '".$row["kenmerk"]."'";
    $result = mysqli_query($conn, $query);

    $week = 1;
    while($row = mysqli_fetch_assoc($result)) // Eerst van week 1 tot 52 de gezette_vruchten een lege waarde meegeven om zo te voorkomen dat ze niet gedefieneerd zijn.
    {
        echo ${'gezette_vruchten_week_'.$week}  = $row["gezette_vruchten"];
        echo ${'uitgroeiduur_week_'.$week}      = $row["uitgroeiduur"];

        $week++;
    }
}

The first query has 2 'kenmerk' results in the database: 'standaard' and 'natugro' the second query has 52 results in the database for each 'kenmerk' for example. 'gezette_vruchten' with 'kenmerk' 'standaard' has 52 weeks and 'gezette_vruchten' with 'kenmerk' 'natugro' has also 52 weeks. so i want for both 'kenmerk' the results of the week were in now.

i hope you can understand this

1
  • You should try to reduce the number of accesses to the database using more complex queries by using JOIN Commented Apr 8, 2014 at 12:54

1 Answer 1

3

change the name of second while loop..

while($row2 = mysqli_fetch_assoc($result)) // Eerst van week 1 tot 52 de gezette_vruchten een lege waarde meegeven om zo te voorkomen dat ze niet gedefieneerd zijn.
{
    echo ${'gezette_vruchten_week_'.$week}  = $row2["gezette_vruchten"];
    echo ${'uitgroeiduur_week_'.$week}      = $row2["uitgroeiduur"];

    $week++;
}

because your variable name for both while loop is same..so i think it is comflict. so change one of the variable name of while loop.

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

3 Comments

also change the name for $result.
change the name of $result aswell
Ah Thhx. this works now dindt know it was this simple... I accept answer in 1 minute.

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.