1

Tables structure:

TESTLINKS

  • id
  • source
  • projectid
  • clientid
  • qa
  • stg
  • prod
  • username
  • password

PROJECTS

  • id
  • projectname
  • clientid
  • projectdescription
  • projectmanager
  • qbid
  • aetid
  • uatdate
  • targetreleasedate
  • status

PRODUCTS

  • id
  • productname
  • projectmanageruserid

TESTLINKSPRODUCTS

  • id
  • testlinksid
  • productsid

CLIENTS

  • id
  • clientname
  • clientmanager

My goal is to create a system to input testing links and to enable the user to pull the appropriate testing links based on multiple options which they can select in a series of dropdown boxes.

I have setup the PHP and HTML pages to input data into the tables listed above. Now I am trying to setup the MySQL query and PHP required to pull the data into the webpage.

I would like the user to be able to query the results based on 1) projects.id 2) testlinks.source 3) products.id 4) clients.id

these would be selected from 4 separate dropdown boxes

I was easily able to successfully pull results based on projects.id and testlinks.source because these two tables have 'projectid' in common. However I am now having an issue pulling results based on 'productid' because the products are associated to the testlinks and not to the projects. The 'testlinksproducts' table handles the association of products to testlinks but I do not know how to add this to the query because when I run the query I get rows repeated several times and doesn't achieve the results that I want.

Here is my PHP file which is working for pulling testlinks based on project.id and testlinks.source --

$query = "SELECT testlinks.id,
                 testlinks.source,
                 testlinks.projectid,
                 testlinks.clientid,
                 testlinks.qa,
                 testlinks.stg, 
                 testlinks.prod, 
                 testlinks.username,
                 testlinks.password, 
                 projects.id, 
                 projects.projectname 
          FROM testlinks , projects 
          WHERE testlinks.projectid = projects.id 
            AND (testlinks.projectid='$projectid' 
                 OR testlinks.source='$source')
          ;"; 

$result = mysql_query($query) or die(mysql_error()); 

echo "<table class=\"zebra\">"; 
echo "<thead><tr>
    <th>ID</th>
    <th>Source</th>
    <th>Project Name</th>
    <th>QA</th>
    <th>STG</th>
    <th>Prod</th>
    </tr></thead>";
while($row = mysql_fetch_array($result))
{
    echo "<tr>"; 
    echo "<td>".$row['id']."</td>
        <td>".$row['source']."</td>
        <td>".$row['projectname']."  </td>
        <td>"."<a href=\"".$row['qa']."\" target=\"new\">
            <button>QA</button></a></td>
        <td>"."<a href=\"".$row['stg']."\" target=\"new\">
            <button>STG</button></a></td>
        <td>"." <a href=\"".$row['prod']."\" target=\"new\">
            <button>PROD</button></a></td>
        </tr>";
}
echo "</table>";

Can someone help with adding query functionality to pull testlinks based on productsid (contained in 'testlinksproducts' table) ?

Help would be very much appreciated on this one!

2

1 Answer 1

1

The query could be something like:

SELECT testlinks.id,
                 testlinks.source,
                 testlinks.projectid,
                 testlinks.clientid,
                 testlinks.qa,
                 testlinks.stg,
                 testlinks.prod,
                 testlinks.username,
                 testlinks.password,
                 projects.id,
                 projects.projectname
          FROM testlinks , projects , TESTLINKSPRODUCTS
          WHERE testlinks.projectid = projects.id
            AND testlinks.id = TESTLINKSPRODUCTS.testlinksid
            AND (testlinks.projectid='$projectid'
                 OR testlinks.source='$source'
                 OR TESTLINKSPRODUCTS.productsid = '$productid')
          GROUP BY testlinks.id

Note: The group-by may not be necessary if a testlink can only be in one project, product and client. A group_concat() might help if a testlink is in more than one project.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey ebyrob, thanks for the quick reply! Unfortunately this query isn't working for me. I do not have a 'testlinksclients' table. I tried removing references to this table name in the query you provided and performed a quick test by selecting a 'source' value but now I cannot search by 'source' or any other fields (I was able to search by projectid and source previously using the query included in my initial post)
@user1504519 Hopefully fixed. That's what I get for trying to think ahead :-/

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.