0

I'm creating currently database with tables and trying to do it using second normalization form for my school.

I have list of institutional partners which has to be displayed in two tables. I got this far that I have created database tables: The first one called "as_partners_id" which contain columns: "Partner_ID" (this is primary key INT) and "Partner" (just a VARCHAR). The other table called "as_partners" has some more columns, like: "Partner_ID, Country, EU terms, NON-EU terms, More info".

What I want to do is create drop down menu above first table from which you can choose ID from e.g. 1 to 30. After picking it will display the second table with more information about this particular ID. But I actually don't know how to do it properly. Here is the code that I have so far:

<?php
// Create connection
$con=mysqli_connect("localhost","easj_admin","","easj");

    // Check connection
    if (mysqli_connect_errno())

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  } else {
    echo "We are connected.";
    }

    $result = mysqli_query($con,"SELECT Partner_ID, Partner FROM as_partners_id");

?> 

BODY PART:

<table>
    <tr>
    <?php

     // Get field information for all fields
  while ($fieldinfo=mysqli_fetch_field($result))
    {
        echo "<th>" . $fieldinfo->name ."</th>";
    }
    echo "</tr>";

    // <form>
    // <input typ="select">
    // </form> 
  while($row = mysqli_fetch_array($result))
  {
    echo "<tr>";
  echo "<td>" . $row['Partner_ID'] . "</td><td>" . $row['Partner'] . "</td>" ;
  echo "</tr>";
  }

    ?>

    </table> 

How can I add to my code this drop down menu that will display the second table called as_partners? Please help.

1
  • Can you explain how your code doesn't work. We need you to show understanding of your problem first. Commented Dec 17, 2013 at 15:20

1 Answer 1

1
<form name="myform" method="get">
  <select name='whatever' onclick="if(this.value != ''){ myform.submit(); }">
  <?
    while($row = mysqli_fetch_array($result))
    {
      echo "<option value='" . $row['Partner_ID'] . "'>" . $row['Partner'] . "</option>";
    }
  ?>
  </select>
</form>

That will get you the drop down. Then from there you can submit the form using post or get and use the submitted id to generate the second table.

Then you'll need to add php code similar to this:

if(isset($_GET['whatever']))
{
    [build 2nd table here]
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your fast answer. Well I'm not really good at this, in fact I'm just starting to explore the whole php language but I thought of making something like this: $partner=$_GET['Partner_ID']; $qry="SELECT Partner_ID FROM as_partners_id WHERE Partner_ID=$partners"; But obviously it doesn't work. I think the way of my reasoning is not the proper one. Could you maybe help me a bit more with this? What should I put there to get the second table displaying after choosing an ID.
The code for the second table would be <table> <tr> <?php while ($fieldinfo=mysqli_fetch_field($result)) { echo "<th>" . $fieldinfo->name ."</th>"; } echo "</tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Partner_ID'] . "</td><td>" . $row['Country'] . "</td><td>" . $row['URL'] . "</td><td>" . $row['EU students'] . "</td><td>" . $row['NON-EU students'] . "</td><td>" . $row['Danish citizens'] . "</td><td>" . $row['More information'] ; echo "</tr>"; } ?> </table> But it doesn't work. I tried to put it somehow between these [].

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.