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
Repeating an element a given number of times
Old 02-18-2009, 05:53 PM Repeating an element a given number of times
Junior Talker

Posts: 1
Trades: 0
Hi everyone. I'm new at this and was just wondering if you could point me in the right direction.

I'm selling tickets on a website. On a database I have saved how many tickets each person wants.

I want to create a page that displays that number of tickets. So if the database says a person wants 5 tickets, I want 5 tickets to appear (an image, a table, or whatever) and I want them numbered 1-5.

How do you recommend I start going about this? With loops? An array? Again, I'm pretty new.

Thanks!
johnsully517 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-19-2009, 07:15 AM Re: Repeating an element a given number of times
EdB
Skilled Talker

Posts: 79
Name: Ed Barnett
Trades: 0
Quote:
Originally Posted by johnsully517 View Post
Hi everyone. I'm new at this and was just wondering if you could point me in the right direction.

I'm selling tickets on a website. On a database I have saved how many tickets each person wants.

I want to create a page that displays that number of tickets. So if the database says a person wants 5 tickets, I want 5 tickets to appear (an image, a table, or whatever) and I want them numbered 1-5.

How do you recommend I start going about this? With loops? An array? Again, I'm pretty new.

Thanks!
You can use a loop - either 'while' or 'for'. If you are using a MySQL database you can use the 'while' loop as such;

$query = mysql_query("SELECT * FROM table");

$count = 1;

while ($result = mysql_fetch_assoc($query)) {
echo "This is ticket number " .$count;
$count++;
}

That's the basics of it, how you format it (either using images or in tables) is completely up to you. (Does that help?)

Last edited by EdB; 02-19-2009 at 07:34 AM..
EdB is offline
Reply With Quote
View Public Profile Visit EdB's homepage!
 
Reply     « Reply to Repeating an element a given number of times
 

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.46778 seconds with 12 queries