Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

taha kazi
taha kazi
1,376 Points

Use results from SQL as criteria to query another request via php

I am grabbing a list of school names from a database. When the user clicks on the school name, i want the code to fetch 2-3 other attributes related to the school name that the user has clicked on.

My code for the single school name list:

$query = mysql_query("Select schoolname, product, username, password from credentials c join products p on p.productid = c.productid join schools s on s.schoolid = c.schoolid join icons i on i.productid = p.productid order by s.schoolname");

echo '<ul>'; while($row = mysql_fetch_array($query)) {
echo "<li> <a href='#'>" . $row['schoolname'] . "</a> </li>"; } echo '</ul>';

Current Results: School A School A School B School B School B School C School C

Expected Results:

  1. School name displayed only once (distinct won't work because each school name has 2-3 product credentials School A School B School C

  2. Ability for User to click on a school and see product, username and password displayed (for example: user clicked on School A)

School A: product , username, password

School B School C

1 Answer

taha kazi
taha kazi
1,376 Points

anyone, help?