Search the Community
Showing results for tags '#sql'.
-
Hey! I'm fetching data frmo my database and displaying it in a table. Now I want to be able to display that data but sorted in different ways. Right now it's sorted by id ASC. I want to make the <th> links, so when i press one of them, the page will sort the data in that way. How can I make this without writing a lot of new querys? I want to use the one query i already have made. Here is my code: <?php if(isset($_GET['hpid'])) { $hpid = (int)$_GET['hpid']; $test = mysql_query("SELECT * FROM `project`, `users`, `projectStatus` WHERE `projectHuvudId` = $hpid AND project.projectCreatorId = users.user_Id AND project.projectStatusId = projectStatus.statusId"); $test2 = mysql_query("SELECT p.projektName , p.projectId , s1.statusName , u1.username as creatorName , u2.username as ansvarig , p.projectDescription , p.projectCreateDate , p.projectStartDate , p.projectEndDate FROM project p INNER JOIN users u1 ON p.projectCreatorId = u1.user_Id INNER JOIN users u2 ON p.projectAnsvarig = u2.user_Id INNER JOIN projectStatus s1 ON p.projectStatusId = s1.statusId WHERE `projectHuvudId` = $hpid ORDER BY p.projectId ASC"); ?> <table class="display"> <th>ID</th> <th>Skapat</th> <th>Namn</th> <th>Start</th> <th>Slut</th> <th>Skapare</th> <th>Ansvarig</th> <th>Status</th> <?php while($row = mysql_fetch_assoc($test2)) { ?> <tr> <td><?php echo "<a href='project.php?pid=" . $row['projectId'] . "'>" . $row['projectId'] . "</a>"; ?></td> <td><?php echo $row['projectCreateDate'] ?></td> <td><?php echo $row['projektName'] ?></td> <td><?php echo $row['projectStartDate'] ?></td> <td><?php echo $row['projectEndDate'] ?></td> <td><?php echo $row['creatorName'] ?></td> <td><?php echo $row['ansvarig'] ?></td> <td><?php echo $row['statusName'] ?></td> </tr> <?php } ?> </table><?php } ?>
-
Hey! I have these tables: Project: name - name of project creatorId - id which is related to id 'userId' in table called Users. This table also have name of user and surname of user. statusId - id which is related to id 'statusId' in table called Status. This table also have Started, Ended, Closed. assigneId - id which is related to id 'userId' in table called Users. This table also have name of user and surname of user. (relation same as creatorId). I think I have given you everything relevant. Now to my question.. How can I query this so I can get all information I want? I'm getting what I want really, but problem is that I want name of creatorId and assigneId, not just ID. How can I do this in 1 query?