sylunt1 Posted January 16, 2008 Share Posted January 16, 2008 Hello... What I want to do is print the $tse_name once above the output from the if statements. If I do another if statement it prints out 1 set of data - not everything as it does without the name. $id = $_GET['id']; $result = mysql_query ("SELECT tse.tse_id, tse.tse_name, tasks.tasks_id, tasks.tasks_task, tasks.tasks_week, tasks.tasks_day, tasks.tasks_order FROM tse, tasks WHERE tse.tse_id = $id ORDER BY tasks.tasks_week, tasks.tasks_day, tasks.tasks_order") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $tasksans_id = $row['tasksans_id']; $tasks_tsedone = $row['tasks_tsedone']; $tasks_date = $row['tasks_date']; $tasks_mdone = $row['tasks_mdone']; $tasks_id = $row['tasks_id']; $tasks_task = $row['tasks_task']; $tasks_week = $row['tasks_week']; $tasks_day = $row['tasks_day']; $tasks_order = $row['tasks_order']; $tasks_add1 = $row['tasks_add1']; $tasks_add2 = $row['tasks_add2']; $tasks_add3 = $row['tasks_add3']; $tasks_add4 = $row['tasks_add4']; $tse_id = $row['tse_id']; $tse_name = $row['tse_name']; $tse_weekorder = $row['tse_weekorder']; $weeks_id = $row['weeks_id']; $weeks_1 = $row['weeks_1']; $weeks_2 = $row['weeks_2']; $weeks_3 = $row['weeks_3']; $weeks_4 = $row['weeks_4']; if ($tasks_week != $previous_tasks_week){ print '<br /><br /><H3>Week ' . $tasks_week . '</H3><br />'; $previous_tasks_week = $tasks_week ; } if ($tasks_day != $previous_tasks_day){ print '<br /><b>Day ' . $tasks_day . '</b><br />'; $previous_tasks_day = $tasks_day ; } if ($tasks_id != $previous_tasks_id){ print '<br />' . $tasks_task . '<br />'; $previous_tasks_id = $tasks_id ; } } Any help is appreciated - Im sure it's something easy but I'm braindead at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/86311-break-out-of-a-loop/ Share on other sites More sharing options...
rbrown Posted January 16, 2008 Share Posted January 16, 2008 try this: $id = $_GET['id']; $result = mysql_query ("SELECT tse.tse_id, tse.tse_name, tasks.tasks_id, tasks.tasks_task, tasks.tasks_week, tasks.tasks_day, tasks.tasks_order FROM tse, tasks WHERE tse.tse_id = $id ORDER BY tasks.tasks_week, tasks.tasks_day, tasks.tasks_order") or die(mysql_error()); $count=0; while($row = mysql_fetch_array($result)) { $tasksans_id = $row['tasksans_id']; $tasks_tsedone = $row['tasks_tsedone']; $tasks_date = $row['tasks_date']; $tasks_mdone = $row['tasks_mdone']; $tasks_id = $row['tasks_id']; $tasks_task = $row['tasks_task']; $tasks_week = $row['tasks_week']; $tasks_day = $row['tasks_day']; $tasks_order = $row['tasks_order']; $tasks_add1 = $row['tasks_add1']; $tasks_add2 = $row['tasks_add2']; $tasks_add3 = $row['tasks_add3']; $tasks_add4 = $row['tasks_add4']; $tse_id = $row['tse_id']; $tse_name = $row['tse_name']; $tse_weekorder = $row['tse_weekorder']; $weeks_id = $row['weeks_id']; $weeks_1 = $row['weeks_1']; $weeks_2 = $row['weeks_2']; $weeks_3 = $row['weeks_3']; $weeks_4 = $row['weeks_4']; if($count==0){ print'<br /><br /><H3>Name '.$tse_name.'</H3><br />'; $count=1; } if ($tasks_week != $previous_tasks_week){ print '<br /><br /><H3>Week ' . $tasks_week . '</H3><br />'; $previous_tasks_week = $tasks_week ; } if ($tasks_day != $previous_tasks_day){ print '<br /><b>Day ' . $tasks_day . '</b><br />'; $previous_tasks_day = $tasks_day ; } if ($tasks_id != $previous_tasks_id){ print '<br />' . $tasks_task . '<br />'; $previous_tasks_id = $tasks_id ; } } Quote Link to comment https://forums.phpfreaks.com/topic/86311-break-out-of-a-loop/#findComment-441041 Share on other sites More sharing options...
sylunt1 Posted January 16, 2008 Author Share Posted January 16, 2008 awesome - thank you that did it. Quote Link to comment https://forums.phpfreaks.com/topic/86311-break-out-of-a-loop/#findComment-441061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.