Re: Problem With Inner Loop
| From: | Jasper Bryant-Greene | Date: | Tue, 30 Aug 2005 00:00:59 +0000 |
| Subject: | Re: Problem With Inner Loop | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-221558@lists.php.net to get a copy of this message | ||
Shaun wrote:
Hi, The following code is attempting to display a list of work types for all the users in my database. However it only loops through the inner loop once and I can't work out why, can anyone help here please? <table> <?php include('application.php'); $staff_qid = mysql_query('SELECTWell, if Project_ID is a primary key or unique key of some sort, as I would assume it was if it's an ID, then the $work_type_qid query will only return one row. And because the query is performed outside the outer while loop, it will only execute once, at the start of the request. If you want the same SELECT query to be executed over and over (why?) then you would need to move the mysql_query() inside the outer while loop. HTH -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ If you find my advice useful, please consider donating to a poor student! You can choose whatever amount you think my advice was worth to you. http://tinyurl.com/7oa5sU.User_ID, CONCAT_WS(" ", U.user_Firstname, U.User_Lastname) AS "User_Name" FROM Users U, Allocations A, Projects P WHERE U.User_ID = A.User_ID AND A.Project_ID = P.Project_ID AND P.Project_ID = 38 AND (U.User_Type = "Staff" OR U.User_Type = "Manager" OR U.User_Type = "Administrator") ORDER By User_Name');$work_type_qid = mysql_query('SELECTWork_Type_ID, Work_Type FROM Work_Types WHERE Project_ID = 38 ORDER BY Day_Type');?> <table> <?php while( $staff_r = mysql_fetch_object( $staff_qid ) ) { ?> <tr> <?php while( $work_type_r = mysql_fetch_object( $work_type_qid ) ) { ?> <td><?php echo $work_type_r->Work_Type; ?></td> <?php } ?> </tr> <?php } ?> </table>