1

i'm building this little function,

what i need is this query to print me values. Which means, i have this array named $checked1 which i need to print each of it inside a query.

My code up to now is:

$result = mysql_query("SELECT $checked FROM hostess");


while($row = mysql_fetch_array($result))
  {foreach( $checked1 as $key => $value){

      echo "<td>" . $row['$value'] . "</td>";


}

But it's not working.

Can you tell me what's wrong?

Thanks..

5
  • 2
    What are the value of $checked and $checked1? And what do you mean by "not working"? What's happening when you try to run the code? Commented Jun 22, 2012 at 16:33
  • There is this hostess table which has fields like id,name etc etc.. Commented Jun 22, 2012 at 16:33
  • Aleks, so the $checked is just an implode of the $checked1 array...., it doesn't print anything.. Commented Jun 22, 2012 at 16:34
  • Or the error you're getting...? 'It be broke' isn't much to go on. Commented Jun 22, 2012 at 16:35
  • Please don't use mysql_* functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information. Commented Jun 22, 2012 at 16:58

1 Answer 1

4
echo "<td>" . $row['$value'] . "</td>";

should be

echo "<td>" . $row[$value] . "</td>";
Sign up to request clarification or add additional context in comments.

1 Comment

Hey, i can't believe i didn't see this option, i've been struggling for this, many many thanks...

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.