Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/86311-break-out-of-a-loop/
Share on other sites

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 ;

}
}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/86311-break-out-of-a-loop/#findComment-441041
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.