how to display an array variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    #1

    how to display an array variable

    Hi,

    In my script the {$a[0]}"; does not want to assing to $p1 at the $p1="{$a[0]}";
    line.


    [PHP]
    $result = mysql_query("SE LECT * FROM hole ORDER BY a5");

    $i = 0;
    $a = array();
    while($row = mysql_fetch_arr ay($result))
    {
    $a[$i] = $row['a5'];
    ++$i;
    }

    mysql_close($co n);

    echo "{$a[0]} {$a[1]} {$a[2]} {$a[8]}";

    /////////// hole 1 ////////////
    $p1="{$a[0]}"; //// ************ HELP******
    if ($p1=="on") /////Show not taken
    $p1="on"; /////show taken
    else
    $p1="off";
    [/PHP]
  • webandwe
    New Member
    • Oct 2006
    • 142

    #2
    I thin I got the problem...Just checking

    [PHP]
    $p1="{$a[0]}"; ////Check hole
    if ($p1=="{$a[0]}") /////Show not taken
    $p1="15"; /////show taken
    else
    $p1="off";
    [/PHP]

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by webandwe
      I thin I got the problem...Just checking

      [PHP]
      $p1="{$a[0]}"; ////Check hole
      if ($p1=="{$a[0]}") /////Show not taken
      $p1="15"; /////show taken
      else
      $p1="off";
      [/PHP]
      You dont always have to use quotes and curly brackets.
      [php]
      $p1 = $a[0];
      if($p1 == $a[0])
      $p1 = "15";
      else
      $p1 = "off";
      [/php]

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Variable not working can in no way be considered a meaningful title. Since when does a variable 'work'??

        Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

        This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

        MODERATOR

        Comment

        Working...