开发者

Selecting fields using variables for the fields

I have created a dropdown list where the user can selec开发者_开发技巧t the fields they wish to have displayed. I can create a variable, say $field_list which then has 3 (user selected) fields, say title, first_name,last_name. So my SELECT statement would read (as a php statement)

$sql=" SELECT $field_list from my_table "; 

which operates as "SELECT title, first_name,last_name from my_table ";

The problem then arises when trying to display the data from each of these fields. I am trying to use the stucture as follows

  $result=mysql_query("$sql");
  while ($myrow = mysql_fetch_array($result))
  {
  echo "the data is $myrow["x"];
  }

Howvere, I want to be able to use different values for x which are extracted from the $field_list using substr(). Normaly I would do this by using $x and changing the values as appropriate, but this syntax does not work. Any help would be appreciated.


Careful with quoting. Try echo "the data is " . $myrow[$x]; or echo "the data is {$myrow[$x]}";

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜