Buy Sell Discuss UK Domain Names at AcornDomains.co.uk domain name offers

Today's Drop Dates are: 07-11-2011 or 14-11-2011   All times are GMT. The time now is 07:59:07 PM.
Domain Name Sales Domain Software Calculate UK Domain Drop Dates Domain Registration NameDrive Domain Parking Subscribe to our Domains For Sale newsletter
Go Back   Domain Forum Acorn Domains Buy Sell Auction UK Domains > Website Design and Promotion > Website Design > Scripts and Coding
Connect with Facebook

Scripts and Coding PHP, MySQL, scripts

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 31-08-2009, 10:56:04 PM     #1 (permalink)

 
woopwoop's Avatar
 
Join Date: Jan 2007
Posts: 1,483
woopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond repute

php mysql loop question

Can anyone help? I have a mysql table with the following information:

Quote:
ID Name Chapter Description
1 uniqueName1 Ch1 Name uniqueDescription1
2 uniqueName2 Ch1 Name uniqueDescription2
3 uniqueName3 Ch1 Name uniqueDescription3
4 uniqueName4 Ch2 Name uniqueDescription4
5 uniqueName5 Ch2 Name uniqueDescription5
6 uniqueName6 Ch3 Name uniqueDescription6
7 uniqueName7 Ch3 Name uniqueDescription7

I have some php loop code which echos the rows in the following format:


Quote:
1 - uniqueName1 - uniqueDescription1

2 - uniqueName2 - uniqueDescription2

3 - uniqueName3 - uniqueDescription3

4 - uniqueName4 - uniqueDescription4

5 - uniqueName5 - uniqueDescription5

6 - uniqueName6 - uniqueDescription6

7 - uniqueName7 - uniqueDescription7

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:
Ch1 Name

1 - uniqueName1 - uniqueDescription1

2 - uniqueName2 - uniqueDescription2

3 - uniqueName3 - uniqueDescription3

Ch2 Name

4 - uniqueName4 - uniqueDescription4

5 - uniqueName5 - uniqueDescription5

Ch3 Name

6 - uniqueName6 - uniqueDescription6

7 - uniqueName7 - uniqueDescription7

Do you know how I could edit my loop below:



Quote:
$query = "SELECT * FROM tbl order by ID ASC";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo "<br />";
echo $row['id'];
echo " - ";
echo $row['Name'];
echo " - ";
echo $row['Description'];
echo "<br />";
}
woopwoop is offline  
Old 31-08-2009, 11:34:01 PM     #2 (permalink)

 
accelerator's Avatar
 
Join Date: Apr 2005
Location: England
Posts: 4,764
accelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond reputeaccelerator has a reputation beyond repute

If no-one comes to your assistance here, I recommend the PHP Freaks Forums.

Rgds
accelerator is offline  
Old 01-09-2009, 01:29:07 AM     #3 (permalink)

 
woopwoop's Avatar
 
Join Date: Jan 2007
Posts: 1,483
woopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond repute

Many thanks Accelerator - I've made a post over there now too. Looks like I can learn a lot over there.
woopwoop is offline  
Old 01-09-2009, 03:11:17 AM     #4 (permalink)

 
woopwoop's Avatar
 
Join Date: Jan 2007
Posts: 1,483
woopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond repute

someone from dnf helped. Here's the solution for anyone interested:

Quote:
$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 />";
}
added: a guy on phpfreaks also added this solution - looks like a really useful forum.

Last edited by woopwoop; 01-09-2009 at 03:15:36 AM.
woopwoop is offline  
Closed Thread



Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Domain Name Community Replies Last Post
PHP / MySQL data in a Smarty template admin Scripts and Coding 0 21-03-2009 05:52:59 PM
PHP / MySQL Developer admin Services Wanted 5 11-02-2009 10:41:40 AM
php mysql select query question woopwoop Scripts and Coding 6 06-02-2009 02:03:49 AM

Reseller Hosting


All times are GMT. The time now is 07:59:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 RC 2
All content on Acorn Domains is member generated and is not moderated before posting. All content is viewed and used by you at your own risk and AD does not warrant the accuracy or reliability of any of the information. The views expressed are those of the individual contributors and not necessarily those of AD. Please contact us to report any issues or send a PM to "Admin".