Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Creating a row with 6 records
Old 05-03-2009, 01:55 AM Creating a row with 6 records
Novice Talker

Posts: 6
Trades: 0
Hey guys

First off, I'm a php rookie, so go easy!

Basically, what I'm trying to do is this....

1. Call on a query with several hundred records.
2. Display 2 of these fields (FirstName & LastName) for each record
3. Use PHP to create a new row for every 6 records until all records are done

So the finished product will be a table with all of the people's names - with 6 columns, and many rows (record 1 in the first column, record 2 in the second column, 3 in the third etc).

I know how to call my database, perform the query I want to pull the information from. I just don't know how to set up this loop.

I need the PHP to basically say:

- while there are still records, perform this task
- for each 6 records, create a cell with first and last name in it, then move to the next line and start creating a new row with the next 6 records.

Thanks for any help you can lend me guys!!
RynMan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-03-2009, 04:07 AM Re: Creating a row with 6 records
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Not sure I got this. Do you mean something like this? (FN = First Name, LN = Last Name)

You pull these records
Code:
1: FN1, LN1
2: FN2, LN2
3: FN3, LN3
4: FN4, LN4
5: FN5, LN5
6: FN6, LN6
7: FN7, LN7
8: FN8, LN8
9: FN9, LN9
10: FN10, LN10
11: FN11, LN11
12: FN12, LN12
...
And you want to create a new table(?) with these?
Code:
1: FN1 + LN1, FN2 + LN2, FN3 + LN3, FN4 + LN4, FN5 + LN5, FN6 + LN6
2: FN7 + LN7, FN8 + LN8, FN9 + LN9, FN10 + LN10, FN11 + LN11, FN12 + LN12
...
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-03-2009, 08:37 AM Re: Creating a row with 6 records
Novice Talker

Posts: 6
Trades: 0
Quote:
Originally Posted by lizciz View Post
Not sure I got this. Do you mean something like this? (FN = First Name, LN = Last Name)

You pull these records
Code:
1: FN1, LN1
2: FN2, LN2
3: FN3, LN3
4: FN4, LN4
5: FN5, LN5
6: FN6, LN6
7: FN7, LN7
8: FN8, LN8
9: FN9, LN9
10: FN10, LN10
11: FN11, LN11
12: FN12, LN12
...
And you want to create a new table(?) with these?
Code:
1: FN1 + LN1, FN2 + LN2, FN3 + LN3, FN4 + LN4, FN5 + LN5, FN6 + LN6
2: FN7 + LN7, FN8 + LN8, FN9 + LN9, FN10 + LN10, FN11 + LN11, FN12 + LN12
...
Nah, Like this....

John Smith | Andrew Stevens | Jason Taylor
Andrea Moore | David Jones | Donald Johnson

so names move horizontally with a cell for each (above I've only done 3 wide, I want 6).
RynMan is offline
Reply With Quote
View Public Profile
 
Old 05-03-2009, 09:15 AM Re: Creating a row with 6 records
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
This is really about CSS as its about presenting your data.

Its a list of names so semantically you should be using <ul><li>FN LN</li></ul>. Then use a class to style the tags. 'Wide' would style the <ul> and 'list' the <li> tag. Result is a row of 6 records.

HTML Code:
<style type="text/css">
<!--
.wide{
width:1200px;
}
.list{
width:199px;
float:left;
border-right:1px solid #000;
list-style:none;
}
-->
</style>
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 05-03-2009, 12:35 PM Re: Creating a row with 6 records
Rad_Dev's Avatar
Experienced Talker

Posts: 37
Trades: 0
Quote:
Originally Posted by maxxximus View Post
This is really about CSS as its about presenting your data.

Its a list of names so semantically you should be using <ul><li>FN LN</li></ul>. Then use a class to style the tags. 'Wide' would style the <ul> and 'list' the <li> tag. Result is a row of 6 records.

HTML Code:
<style type="text/css">
<!--
.wide{
width:1200px;
}
.list{
width:199px;
float:left;
border-right:1px solid #000;
list-style:none;
}
-->
</style>
Your php code will look something like this:
PHP Code:
$query "SELECT firstname,lastname FROM _table"
$result mysql_query($query) or die(mysql_error());
while(
$row mysql_fetch_row($result)) { 
$array[$row[0]] = $row[1]; 

while(list(
$key,$value) = each($array)) { 
echo 
"<ul><li>$key $value</li></ul>";

__________________
My software never has bugs... It just has random features.

Please login or register to view this content. Registration is FREE
&
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Rad_Dev is offline
Reply With Quote
View Public Profile Visit Rad_Dev's homepage!
 
Reply     « Reply to Creating a row with 6 records
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39639 seconds with 11 queries