

![]() |
| ![]() | |||||||
|
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) | ||||
| Platinum Lifetime Member Last Online: 10-17-2009 01:44 PM iTrader: (2) Join Date: Sep 2006
Posts: 241
DNF$: 352 Location: New York
Country: | php mysql loop question Can anyone help? I have a mysql table with the following information: Quote:
I have some php loop code which echos the rows in the following format: Quote:
What I would like to do is to get the Chapter Name above the lines with the same chapter. But not above every line. See below: Quote:
Do you know how I could edit my loop below: Quote:
__________________ cheap textbooks | ||||
| | |
| Sponsored Ads |
| | #3 (permalink) | |
| Platinum Lifetime Member Last Online: 10-17-2009 01:44 PM iTrader: (2) Join Date: Sep 2006
Posts: 241
DNF$: 352 Location: New York
Country: | Quote:
My problem is that I only want the chapter name to be echoed once above the corresponding lines (but importantly not above each line). That's where I'm having some trouble. As shown ID 1-3 are all part of chapter1, ID 4-5 are chapter2, ID 6-7 are chapter3 - so in this batch of rows I'd only need 3 chapter headings. Could you give me an example of an if else which could work to echo the chapter name only once for each group that chapter name? Many thanks.
__________________ cheap textbooks | |
| | |
| | #4 (permalink) |
| Jedi Master Name: Bob Last Online: Yesterday 08:54 AM iTrader: (74) Join Date: Apr 2002
Posts: 2,980
DNF$: 140 Location: Massachusetts
Country: | Try this: Code:
$query = "SELECT * FROM tbl order by ID ASC";
$result = mysql_query($query) or die(mysql_error());
$currentChapter = ''; // added line
while($row = mysql_fetch_array($result)) {
if($currentChapter!=$row['Chapter']) {echo "<b><font color='red'>".$row['Chapter']."</font></b><br>";} // added line
$currentChapter=$row['Chapter']; // added line
echo "<br />";
echo $row['id'];
echo " - ";
echo $row['Name'];
echo " - ";
echo $row['Description'];
echo "<br />";
}
__________________ The massive purge has begun. |
| | |
| | #5 (permalink) |
| Platinum Lifetime Member Last Online: 10-17-2009 01:44 PM iTrader: (2) Join Date: Sep 2006
Posts: 241
DNF$: 352 Location: New York
Country: | Bob - I owe you. Your method was a really smart solution and I'm grateful for your help. If our paths cross in future and I can help you in some way let me know (you have saved me many hours!) Thanks again.
__________________ cheap textbooks |
| | |
| | #6 (permalink) |
| Jedi Master Name: Bob Last Online: Yesterday 08:54 AM iTrader: (74) Join Date: Apr 2002
Posts: 2,980
DNF$: 140 Location: Massachusetts
Country: | Welcome. When and if we ever cross path, you can buy me a free glass of water. -Bob
__________________ The massive purge has begun. |
| | |
| | #7 (permalink) |
| Platinum Lifetime Member Last Online: 10-17-2009 01:44 PM iTrader: (2) Join Date: Sep 2006
Posts: 241
DNF$: 352 Location: New York
Country: | My pleasure. I'll buy you 2 !
__________________ cheap textbooks |
| | |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |