0
while($testing = mysqli_fetch_array($sendPasswordQuery)){
echo "'$testing['name']'";
}

Hi, I know that the second line is wrong, but how would I print the name column. Thanks in advance.

2 Answers 2

1

Your second line needs to be formatted as one of the following:

echo $testing['name']; // will output Name directly
echo "'{$testing['name']}'"; // will output 'Name' inside a string
echo "'$testing[name]'"; // will output 'Name' in a string,
                         // however the second example is better practice.

If you are just echoing the variable and not adding any extra text to it, just use this:

echo $testing['name'];

Otherwise, I'd suggest the following:

echo "Lorem ipsum {$testing['name']} sit amet.";

That will output: Lorem ipsum Name sit amet.

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

2 Comments

Why is the first example best practice?
I've actually just switched it with the second example. Whilst $testing[name] will work within a string, some common characters used in array indexes will cause the parser to not match them. {$testing['name']} is unambiguous, and will always output the correct result inside a string.
1

Lots of quotes, all of them outside of the variable are unnecessary:

while($testing = mysqli_fetch_array($sendPasswordQuery)){
    echo $testing['name'];
}

Comments

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.