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!
Thanks
mysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. – njk Jan 2 at 19:53