Jump to content

PHP arrays


Los Davelyy!

Recommended Posts

Hi,

 

I run a music website coded in HTML, but I am in the process of converting to PHP.

 

Anyway, here is my problem, I hope I give you enough information to help me.

 

Right, let me show exactly what I have here.

 

FOLDER: Testing

SUBFOLDERS: Images, Artists, Scripts

 

Files inside Artists:

music.php

info.php

header.php

tail.php

 

Inside artists is a folder called 4dayweekend, inside this folder is:

 

index.php and details.php

 

 

Index.php grabs the 4 files from the Artists folder like so. As well as grabbing the details.php from the 4dayweekend folder (same folder as index.php)

 

<?php include('details.php'); ?>
<?php 
include($_SERVER['DOCUMENT_ROOT'].'/testing/artists/header.php');
?>
<div id="maincontent">
<?php 
include($_SERVER['DOCUMENT_ROOT'].'/testing/artists/info.php');
?>
<?php
include($_SERVER['DOCUMENT_ROOT'].'/testing/artists/music.php');
?>
<div id="tail">
<?php 
include($_SERVER['DOCUMENT_ROOT'].'/testing/artists/tail.php');
?>

 

All works well, apart from this bit inside music.php

 

<?php
$result = count($song) - 1;
for ($i=0; $i<=$result; $i++)
  {
echo '<tr>
              <td width="480" height="30">' . $song['$i'] . '</td>
              <td width="70" height="30">' . filesize($file['$i']) . ' bytes</td>
              <td width="30" height="30"><a href="' .   $file['$i']   . '" target="_blank"><img src="/artists/download.png" width="21" height="21" border="0"></a></td>
              </tr>';
  }
?>

 

inside details.php is this:

 

$song=array("Full Session", "Coloured In Cassettes", "Don't Shoot The Messenger", "Golden Souls", "McDonalds", "Mr. Brightside (The Killers Cover)", "Remember The Dropout", "Tonight");

$file=array("mp3s/4dw_session.mp3","mp3s/coloured_in_cassettes.mp3", "mp3s/dont_shoot_the_messenger.mp3", "mp3s/golden_souls.mp3", "mp3s/mcdonalds.mp3", "mp3s/mr_brightside.mp3", "mp3s/remember_the_dropout.mp3", "mp3s/tonight.mp3");

 

The output is = http://www.gapradio.co.uk/testing/artists/4dayweekend/

Where as I need it to be like this = http://www.gapradio.co.uk/artists/4dayweekend

 

If anybody can help me, I will be truely grateful <3

Link to comment
https://forums.phpfreaks.com/topic/167990-php-arrays/
Share on other sites

You have to use double quotes for variables.  Single quotes will print the variable name, not the value.

 

<?php
$result = count($song) - 1;
for ($i=0; $i<=$result; $i++)
  {
echo '<tr>
              <td width="480" height="30">' . $song["$i"] . '</td>
              <td width="70" height="30">' . filesize($file["$i"]) . ' bytes</td>
              <td width="30" height="30"><a href="' .   $file["$i"]   . '" target="_blank"><img src="/artists/download.png" width="21" height="21" border="0"></a></td>
              </tr>';
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/167990-php-arrays/#findComment-886043
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.