Current location: Hot Scripts Forums » Programming Languages » PHP » loop function and increase numbers


loop function and increase numbers

Reply
  #1 (permalink)  
Old 10-03-04, 04:16 AM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
loop function and increase numbers

i have the following function in my index.php:

PHP Code:

<!-- #1 -->

<? include("../_includes/trackcode0.php");?>
1.<?/* track number */?>
<? 
include("../_includes/trackcode1.php");?>
<? 
include('tracks.php'); print $track1;?><?/* track name - UPPERCASE */?>
<? 
include("../_includes/trackcode2.php");?>
<? 
include('tracks.php'); print $track1;?><?/* track name - LOWERCASE */?>
<? 
include("../_includes/trackcode3.php");?>
<? 
include('tracks.php'); print $track1;?><?/* track name - LOWERCASE */?>
<? 
include("../_includes/trackcode4.php");?>
this retrieves data from the file tracks.php.

how can i loop this function for as many times as there are $integers in the tracks.php file? i also need the numbers in the function to increase with 1 for each loop.
Reply With Quote
  #2 (permalink)  
Old 10-03-04, 05:44 AM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
What's the structure/contents of your track.php?
__________________
suf.id.au
Reply With Quote
  #3 (permalink)  
Old 10-03-04, 08:11 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
for each time you open and close php it takes a bit of cpu away, try this:

PHP Code:

<?php

include("../_includes/trackcode0.php");

// track number
echo '1.';

//track name - UPPERCASE
include("../_includes/trackcode1.php");
include(
'tracks.php');
echo 
$track1;

//track name - LOWERCASE
include("../_includes/trackcode2.php");
include(
'tracks.php'); 
echo 
$track1;

// track name - LOWERCASE
include("../_includes/trackcode3.php");
include(
'tracks.php'); 
echo 
$track1;
include(
"../_includes/trackcode4.php"); 
?>
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #4 (permalink)  
Old 10-03-04, 11:36 AM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by sufyan
What's the structure/contents of your track.php?
PHP Code:

<? $track1="real talk";?>

<? $track2
="club beats";?>
<? $track3
="across the street";?>

<? $message="Please contact me for CD's or links to more tracks online.";?>
Reply With Quote
  #5 (permalink)  
Old 10-03-04, 11:40 AM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Acecool
for each time you open and close php it takes a bit of cpu away, try this:

snip
i had no idea about that, thanks! you guys are great, very helpful!
Reply With Quote
  #6 (permalink)  
Old 10-03-04, 12:02 PM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
just to give u an idea of what i want to do. i want to be able to post playlists to my server. i want the time and effort needed to construct the playlists to be minimal. basically i want to just make a file (tracks.php) containing the song names and have my index.php look at the file and echo whatever songs are there. i want the code in the tracks.php to be minimal - none if possible. the best thing would be if i could format the file like this:

real talk
club beats
across the street

and have the function understand that each new line is a new item. i don't know if that's possible. if not, the current format (<? $track1="real talk";?> ) is ok too.
Reply With Quote
  #7 (permalink)  
Old 10-03-04, 12:30 PM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Acecool
for each time you open and close php it takes a bit of cpu away, try this:
...
Yes, you are right. Anyway it's not a part of PHP crash policy. Only stack overflow is concerned as serious threat through PHP coding.
__________________
just an ignorant noob with moronic solution...
Reply With Quote
  #8 (permalink)  
Old 10-03-04, 12:51 PM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by nassau
just to give u an idea of what i want to do. i want to be able to post playlists to my server. i want the time and effort needed to construct the playlists to be minimal. basically i want to just make a file (tracks.php) containing the song names and have my index.php look at the file and echo whatever songs are there. i want the code in the tracks.php to be minimal - none if possible. the best thing would be if i could format the file like this:

real talk
club beats
across the street

and have the function understand that each new line is a new item. i don't know if that's possible. if not, the current format (<? $track1="real talk";?> ) is ok too.
we can make it simple. please have a look at PHP Manual PCRE functions first. We'll start from there.
__________________
just an ignorant noob with moronic solution...
Reply With Quote
  #9 (permalink)  
Old 10-03-04, 02:43 PM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by moronovich
we can make it simple. please have a look at PHP Manual PCRE functions first. We'll start from there.
i'm sorry, i feel like a dumbbot... but i don't understand what to make of the info about PCRE. i went to http://us4.php.net/manual/en/ref.pcre.php to read up but.. no cigar.

i don't want to keep asking you about simple stuff but if you want to explain, please do.

thanks
Reply With Quote
  #10 (permalink)  
Old 10-03-04, 09:08 PM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
Ok Nassau, let's move a bit. I won't use regex check method here.
Assume song titles is placed in your tracks.php
Code:
//File tracks.php -> don't include this one in the file
Real Talk
Club Beats
Across the Street
Orient Blue
Vinizzi
Valentine
//EOF -> don't include this one in the file
and now your index.php
PHP Code:

//File index.php

$mp3Folder '/data/mp3/';
$crLf "\n";
print 
'Welcome to my MP3 Server<br />';
print 
'Here you can click and play our mp3 collection<br />';
$fp fopen('tracks.php','rb');
flock($fp,LOCK_SH);
$content fread($fp,filesize('tracks.php'));
flock($fp,LOCK_UN);
fclose($fp);
$row explode($crLf,$content);
//Simpler method for above code
//$row = file('tracks.php');
for($i=0$i<count($row); $i++) {
     print 
'<a href="'.$mp3Folder.$row[$i].'.mp3">'.$row[$i].'</a><br />';

my suggestion:
this code algorithm is not optimum. it's better that php engine searches for song title in a localized folder and then display all mp3 files in the folder automatically.
__________________
just an ignorant noob with moronic solution...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date function ??? marquito Windows .NET Programming 1 10-01-04 05:22 PM
Date function ??? marquito ASP 1 09-27-04 07:23 PM
Date function ??? marquito ASP.NET 0 09-27-04 02:13 PM
rainbow text (n00b) StickMan JavaScript 4 08-27-04 06:25 PM


All times are GMT -5. The time now is 04:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.