how do i select what to show from a query

Discussion in 'PHP' started by dougvcd, May 15, 2007.

  1. #1
    below is what i use at the moment to show fields from my database
    i was trying to get login to work but could not so what i did when peeps register i put a field in called active and made that field =1
    so what i want to do is when peeps click browse it just shows the fields below
    if active = 0 but if active = 1 then it will show extra fields
    hope you understand
    thanks Doug
    $result = mysql_query("SELECT * FROM exchange");
    
    echo "<table border='1'>
    <tr>
    <p align='center' class='bodytext'>
    <th>parkname</th>
    <p align='center' class='bodytext'>
    <th>parklocation</th>
    <p align='center' class='bodytext'>
    <th>caravandetails
    </tr>";while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>" . $row['parkname'] . "</td>";
      echo "<td>" . $row['parklocation'] . "</td>";
      echo "<td>" . $row['caravandetails'] . "</td>";
      echo "</tr>";
      }
    echo "</table>";mysql_close($con);
    ?>&nbsp; </p>
    </body>
    PHP:

     
    dougvcd, May 15, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    how do your users login, sesions or cookies, show me the login code .....
     
    krakjoe, May 15, 2007 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    dont have the login installed as i could not get to work

    cheers
    Doug
     
    dougvcd, May 15, 2007 IP
  4. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #4
    while($row = mysql_fetch_array($result))
    {
    $active=$row['active'];
    }

    if($active==0)
    {
    show normal fields
    }
    else
    {
    show extra fields
    }

    i hope you will understand this pseudocode :)
     
    coderbari, May 15, 2007 IP
  5. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    is this how you mean if i have done it right it didnt work

    $result = mysql_query("SELECT * FROM exchange");
    
    echo "<table border='1'>
    <tr>
    <p align='center' class='bodytext'>
    <th>parkname</th>
    <p align='center' class='bodytext'>
    <th>parklocation</th>
    <p align='center' class='bodytext'>
    <th>caravandetails</th>
    <p align='center' class= 'bodytext'>
    <th>email
    </tr>";while($row = mysql_fetch_array($result))
    {
    $active=$row['active'];
    }
    
    if($active==0)
    {
     echo "<tr>";
      echo "<td>" . $row['parkname'] . "</td>";
      echo "<td>" . $row['parklocation'] . "</td>";
      echo "<td>" . $row['caravandetails'] . "</td>";
      echo "</tr>";
    }
    else
    {
    echo "<tr>";
      echo "<td>" . $row['parkname'] . "</td>";
      echo "<td>" . $row['parklocation'] . "</td>";
      echo "<td>" . $row['caravandetails'] . "</td>";
      echo "<td>" . $row['email'] . "</td>";
      echo "</tr>";
    }
     
    echo "</table>";mysql_close($con);
    ?>&nbsp; </p>
    </body>
    </html>
    PHP:
     
    dougvcd, May 15, 2007 IP
  6. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #6
    ok, lines

    if($active==0)
    {
     echo "<tr>";
      echo "<td>" . $row['parkname'] . "</td>";
      echo "<td>" . $row['parklocation'] . "</td>";
      echo "<td>" . $row['caravandetails'] . "</td>";
      echo "</tr>";
    }
    else
    {
    echo "<tr>";
      echo "<td>" . $row['parkname'] . "</td>";
      echo "<td>" . $row['parklocation'] . "</td>";
      echo "<td>" . $row['caravandetails'] . "</td>";
      echo "<td>" . $row['email'] . "</td>";
      echo "</tr>";
    }
    PHP:
    must be in while loop after $active = ....

    like this:

    $result = mysql_query("SELECT * FROM exchange");
    
    echo "<table border='1'>
    <tr>
    <p align='center' class='bodytext'>
    <th>parkname</th>
    <p align='center' class='bodytext'>
    <th>parklocation</th>
    <p align='center' class='bodytext'>
    <th>caravandetails</th>
    <p align='center' class= 'bodytext'>
    <th>email
    </tr>";while($row = mysql_fetch_array($result))
    {
    
    if($row['active']==0)
    {
     echo "<tr>";
      echo "<td>" . $row['parkname'] . "</td>";
      echo "<td>" . $row['parklocation'] . "</td>";
      echo "<td>" . $row['caravandetails'] . "</td>";
      echo "</tr>";
    }
    else
    {
    echo "<tr>";
      echo "<td>" . $row['parkname'] . "</td>";
      echo "<td>" . $row['parklocation'] . "</td>";
      echo "<td>" . $row['caravandetails'] . "</td>";
      echo "<td>" . $row['email'] . "</td>";
      echo "</tr>";
    }
    
    }
    
    
     
    echo "</table>";mysql_close($con);
    ?>&nbsp; </p>
    </body>
    </html>
    PHP:
    on that if, I removed $active, there is no need for extra variables
     
    gibex, May 15, 2007 IP
  7. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks to all have now got it all to work
    still need some help later with presentation
    cheers
    Doug
     
    dougvcd, May 16, 2007 IP