there has to be a better way...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cowboysdude
Forum Newbie
Posts: 5
Joined: Sun Jan 11, 2009 6:22 pm

there has to be a better way...

Post by cowboysdude »

Currently my code is defined as follows:

Code: Select all

 
<?php
$fileone   = $params->get('fileone');
$filetwo   = $params->get('filetwo');
$filethree   = $params->get('filethree');
$filefour   = $params->get('filefour');
$filefive   = $params->get('filefive');
$filesix   = $params->get('filesix');
$fileseven   = $params->get('fileseven');
$fileeight   = $params->get('fileeight');
 
$name1 = $params->get('name1');
$name2 = $params->get('name2');
$name3 = $params->get('name3');
$name4 = $params->get('name4');
$name5 = $params->get('name5');
$name6 = $params->get('name6');
$name7 = $params->get('name7');
$name8 = $params->get('name8');
 
$time1 = $params->get('time1');
$time2 = $params->get('time2');
$time3 = $params->get('time3');
$time4 = $params->get('time4');
$time5 = $params->get('time5');
$time6 = $params->get('time6');
$time7 = $params->get('time7');
$time8 = $params->get('time8');
?>
 
BUT to read this I have as of right now the bottom of the file doing this...

Code: Select all

 
<a class="prevPage"></a>
    
    <div id="pl"> 
            
        <div class="entries">
    
            <a href="modules/mod_flowplay/clips/<?php echo "$fileone" ?>">
                <?php echo "$name1" ?> <br />
                <em><font color="red"><?php echo "$time1" ?> min</font></em>
            </a>
            
            <a href="modules/mod_flowplay/clips/<?php echo "$filetwo" ?>">
                <?php echo "$name2" ?> <br />
                <em><font color="red"><?php echo "$time2" ?> min</font></em>    
            </a>
 
            
            <a href="modules/mod_flowplay/clips/<?php echo "$filethree" ?>">
                <?php echo "$name3" ?> <br />
                <em><font color="red"><?php echo "$time3" ?> min</font></em>    
            </a>
            
            <a href="modules/mod_flowplay/clips/<?php echo "$filefour" ?>">
                <?php echo "$name4" ?> <br />
                <em><font color="red"><?php echo "$time4" ?> min</font></em>    
            </a>
            
            <a href="modules/mod_flowplay/clips/<?php echo "$filefive" ?>">
                <?php echo "$name5" ?> <br />
                <em><font color="red"><?php echo "$time5" ?> min</font></em>    
            </a>
 
            
            <a href="modules/mod_flowplay/clips/<?php echo "$filesix" ?>">
                <?php echo "$name6" ?> <br />
                <em><font color="red"><?php echo "$time6" ?> min</font></em>    
            </a>
            
                                
        </div>
 
Is there a better way to shorten up the code or make it smaller so I don't have to retype with filename1, filename2..etc... and not to have so many entries..

because what happens in the frontend is that if there's NO information added into the admin backend then I have just empty fields that are still clickable but of course no file will load because it's not configured... I hope I'm explaining this correctly...

Basically a code that would enable to pick up the multiple params and if nothing is entered it shows nothing... see what I mean?

Many thanks in advance!~!!

John

:banghead:
Last edited by cowboysdude on Sat Mar 07, 2009 6:46 pm, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: there has to be a better way...

Post by requinix »

Learn to use arrays.
cowboysdude
Forum Newbie
Posts: 5
Joined: Sun Jan 11, 2009 6:22 pm

Re: there has to be a better way...

Post by cowboysdude »

That was VERY good advice but NOW I have 3 arrays...lol

Next question how do I match them up?

Code: Select all

 
<?php
$filename = array($fileone, $filetwo, $filethree, $filefour, $filefive, $filesix, $fileseven, $fileeight); 
 $title = array($name1, $name2, $name3, $name4, $name5, $name6, $name7, $name8); 
 $time = array($time1, $time2, $time3, $time4, $time5, $time6, $time7, $time8); 
 
$fileone belongs to $name1 and $time1  ... Currently this is what I have:
 
foreach ($filename as $filename)
        IF ($filename != $filename) {
  print "No clip to load<br />" ;
}
ELSE {
  print "<a href='modules/mod_flowplay/clips/$filename'>, $title, $time";
  
} 
    ?>  
 
when I load it, it will load the correct movie per config but in the $title and $time is just shows "array array"...

2 questions I guess lol

How do I get it to show the actual title and time with the actual file?

ie as I said above;

$fileone belongs to $name1 and $time1
$filetwo belongs to $name2 and $time2
etc...

Many Thanks again! :drunk:
Last edited by cowboysdude on Sat Mar 07, 2009 6:45 pm, edited 2 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: there has to be a better way...

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
Post Reply