0

My problem: When the second while loop runs I get an Undefined Index: first and last. I get the right number of first and last Notice messages in each loop. So everything is good except it wont give me the actual names.

I am new to this so I am sure I am just not clear on some rules or something.

$sql = "SELECT * FROM practice WHERE tid='$tid' ORDER BY date";
$result = mysqli_query($conn, $sql);

while ($row = mysqli_fetch_assoc($result)) {
    echo "<br> ". $row["date"]. " @ " . $row["time"] ." ". $row["pid"] ." 
        <form action='includes/joinpractice.inc.php' method='POST'> 
        <input type='hidden' name='pid' value='". $row["pid"] ."'>
        <input type='hidden' name='uid' value='". $id ."'>
        <button type='submit'>Join Practice</button>
        </form> <br>";

    $sql = "SELECT user.first, user.last 
            FROM user 
                INNER JOIN practice_part ON user.id=practice_part.uid
            WHERE pid = '". $row["pid"] ."'";

    $innerresult = mysqli_query($conn, $sql);

    while ($innerrow = mysqli_fetch_assoc($innerresult)) {
        echo "<br> ". $row["first"] ." ". $row["last"] .""; 
    }
}

I have tried using . $row["user.first"] ." ". $row["user.last"] . but this made no difference. Thank you for any input.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
BL10s
  • 43
  • 7
  • You are pointing to the former result, your code should be: – LMC Feb 23 '17 at 23:05
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Feb 23 '17 at 23:45

1 Answers1

6

change this:

echo "<br> ". $row["first"] ." ". $row["last"] .""; 

for this:

echo "<br> ". $innerrow["first"] ." ". $innerrow["last"] .""; 
Danilo Bustos
  • 1,083
  • 1
  • 7
  • 9