Jump to content

Help With MultiDimensional Arrays


spikeon

Recommended Posts

<?php
$episodearray[104] = 104;
$episodearray[104][1] = "Bleach-104.avi";
$episodearray[104][2] = "58mb";
$episodearray[104][3] = "www.akirablaid.com/media/downloads/";
?>

apparently there is an error on line three, but i don't see it.

am i doing something wrong with the multidimentional arrays?
Link to comment
Share on other sites

I copied your code and there were no syntax errors, but the code won't work as it stand since you're trying to use the value of index 104 as both a scalar and an array.

Try this code instead:
[code]<?php
$episodearray[104] = array();
$episodearray[104][] = 104;
$episodearray[104][] = "Bleach-104.avi";
$episodearray[104][] = "58mb";
$episodearray[104][] = "www.akirablaid.com/media/downloads/";
echo '<pre>' . print_r($episodearray,true) . '</pre>';
?>[/code]

The echo statement is there to see what's in the array.

Ken
Link to comment
Share on other sites

well, theres a problem with that

thats just a segment of a code thats included into a larger script.  i can't call on the array until much later, and with the script i built, it will add onto that code with copies like
<?php
$episodearray[104] = 104;
$episodearray[104][1] = "Bleach-104.avi";
$episodearray[104][2] = "58mb";
$episodearray[104][3] = "www.akirablaid.com/media/downloads/";
?>
<?php
$episodearray[103] = 103;
$episodearray[103][1] = "Bleach-103.avi";
$episodearray[103][2] = "58mb";
$episodearray[103][3] = "www.akirablaid.com/media/downloads/";
?>
Link to comment
Share on other sites

actually, heres a copy of the entire segment of that site, devided by ---filename.php---

if you see anything that i did that was a really, really, bad idea, tell me


[code]---adddownload.php---
<?php
session_start();
if($_POST['continue'] == "out") {
echo "You are now logged out<br /> feel free to browse the rest of the site by the left navigation par<br />";
session_destroy();
}
else{
if($_POST['passed'] == yes || $_SESSION['auth'] == 1 || $_SESSION['auth'] == 2){
if($_POST['choice']=="anime"){
echo "<form method=\"post\" action=\"dl.php\" name=\"adddownload\">";
include('media1/anime/list.php');
foreach($anime as $ani) {
echo "$ani <input type=\"radio\" name=\"anime\" value=\"$ani\" /><input type=\"hidden\" value=\"anime\" name=\"choice\" />";
}
echo "<br /><input type=\"text\" name=\"times\" />";
echo "<br /><input type=\"submit\" /></form>";
}
elseif($_POST['choice']=="manga"){
echo "<form method=\"post\" action=\"dl.php\" name=\"adddownload\">";
include('media1/manga/list.php');
foreach($manga as $man){
echo "$man? <input type=\"radio\" name=\"manga\" value=\"$man\" /><input type=\"hidden\" value=\"manga\" name=\"choice\" />";
}
echo "<br /><input type=\"text\" name=\"times\" />";
echo "<br /><input type=\"submit\" /></form>";
}
else{
echo "<form action=\"adddownload.php\" method=\"post\" name=\"choices\"> manga? <input type=\"radio\" name=\"choice\" value=\"manga\" /> anime? <input type=\"radio\" name=\"choice\" value=\"anime\" /><input type=\"submit\" />";
}
echo "<form name=\"logout\" method=\"post\" id=\"logout\" action=\"adddownload.php\">";
echo "<input type=\"checkbox\" value=\"out\" name=\"continue\" /> Would you like to logout instead? <br />";
echo "<input type=\"submit\" value=\"logout\" name=\"logout\" />";
echo "</form>";
echo "<br />";
}
else {
echo "<table><tr><td colspan=\"2\">";
echo "Please Login:<br /></td></tr>";
echo "<form name=\"login\" method=\"post\" id=\"login\" action=\"password.php\">";
echo "<tr><td>Username:</td> <td><input type=\"text\" name=\"user\" /></td></tr>";
echo "<tr><td>Password:</td> <td><input type=\"password\" name=\"password\" /></td></tr> <br />";
echo "<tr><td><input type=\"submit\" value=\"Login\" name=\"sumbit\" /></td></tr>";
echo "</form></table>";
}
}
?>
---password.php---
<?php
session_start();

$inuser = $_POST['user'];
$inpassword = $_POST['password'];

//actual user and pass go here
include('passlist.php');
$lastkey = end(array_keys($userarray));
for($namecount=1;$namecount<=$lastkey;$namecount++){
if(strtolower($userarray[$namecount]) == strtolower($inuser)){
$user = $userarray[$namecount];
$password = $passarray[$namecount];
}
}
$site = "addanime/addanime.php";

// End user and pass

if ($inuser == $user && $user != "") {

  if ($inpassword == $password) {

  $_SESSION['auth'] = 1;
  echo "<form action=\"$site\" method=\"post\">";
  echo "<input type=\"hidden\" name=\"passed\" value=\"yes\" />";
  echo "Login Succeeded<br />";
  echo "<input type=\"submit\" value=\"Click Here To Complete Login\" name=\"login\"/>";
  echo "</form>";
 

  }

  else {

  echo "<form action=\"$site\" method=\"post\">";

  echo "<input type=\"hidden\" name=\"passed\" value=\"no\" />";

  echo "Login Failed (Wrong Password)<br />";

  echo "<input type=\"submit\" value=\"Click Here To Try Again\" name=\"login\" />";

  echo "</form>";

  }

}

  else {

  echo "<form action=\"$site\" method=\"post\">";

  echo "<input type=\"hidden\" name=\"passed\" value=\"no\" />";

  echo "Login Failed (Wrong Username)<br /> You entered: $inuser<br /><br />";
  if($user==""){
  echo "also, \$user is blank";
  }

  echo "<input type=\"submit\" value=\"Click Here To Try Again\" name=\"login\" />";

  echo "</form>";

  }

?>
---dl.php---
<?php
$repeatnumber = $_POST['times'];
$choice = $_POST['choice'];

if($choice=="anime"){
$anime = $_POST['anime'];

echo "<form action=\"dl2.php\" method=\"post\" name=\"addtodll\">";
echo "insert full directory path <input type=\"text\" name=\"dir\" /><br />\n";

for($rn=1;$rn<=$repeatnumber;$rn++){
echo "Episode Input $rn<br />";
echo "insert Episode Number <input type=\"text\" name=\"adden".$rn."\" /><br />\n";
echo "insert filename <input type=\"text\" name=\"addfn".$rn."\" /><br />\n";
echo "insert filesize <input type=\"text\" name=\"addfs".$rn."\" /><br />\n";
}
echo "<input type=\"hidden\" value=\"".$repeatnumber."\" name=\"number\" /><br />\n";
echo "<input type=\"hidden\" value=\"$anime\" name=\"anime\" /><br />\n";
echo "<input type=\"hidden\" value=\"anime\" name=\"choice\" /><br />\n";
echo "<input type=\"submit\" /><br />\n";
}

elseif($choice=="manga"){
$manga = $_POST['manga'];

echo "<form action=\"dl2.php\" method=\"post\" name=\"addtodll\">";
echo "insert full directory path <input type=\"text\" name=\"dir\" /><br />\n";

for($rn=1;$rn<=$repeatnumber;$rn++){
echo "Episode Input $rn <br />";
echo "insert Episode Number <input type=\"text\" name=\"adden".$rn."\" /><br />\n";
echo "insert filename <input type=\"text\" name=\"addfn".$rn."\" /><br />\n";
echo "insert filesize <input type=\"text\" name=\"addfs".$rn."\" /><br />\n";

}
echo "<input type=\"hidden\" value=\"".$repeatnumber."\" name=\"number\" /><br />\n";
echo "<input type=\"hidden\" value=\"$manga\" name=\"manga\" /><br />\n";
echo "<input type=\"hidden\" value=\"manga\" name=\"choice\" /><br />\n";
echo "<input type=\"submit\" /><br />\n";
}


?>
---dl2.php---
<?php
$number = $_POST['number'];
$dir = $_POST['dir'];
$choice = $_POST['choice'];

if($choice=="anime"){
$anime = $_POST['anime'];
$fhand = fopen("media1/anime/".$anime."dllist.php", 'a');
$filecont = "<?php \n";
for($num=1;$num<=$number;$num++){
$EpNum = $_POST["adden".$num];
$FiNam = $_POST["addfn".$num];
$FiSiz = $_POST["addfs".$num];
$filecont .= "\$episodearray[$EpNum] = $EpNum;";
$filecont .= "\$episodearray[$EpNum][1] = \"$FiNam\";";
$filecont .= "\$episodearray[$EpNum][2] = \"$FiSiz\";";
$filecont .= "\$episodearray[$EpNum][3] = \"$dir\";";

}
$filecont .= "?>";
fwrite($fhand,$filecont);
fclose($fhand);
}

if($choice=="manga"){
$manga = $_POST['manga'];
$filecont = "<?php \n";
for($num=1;$num<=$number;$num++){
$EpNum = $_POST["adden".$num];
$FiNam = $_POST["addfn".$num];
$FiSiz = $_POST["addfs".$num];
$filecont .= "\$episodearray[$EpNum] = $EpNum;";
$filecont .= "\$episodearray[$EpNum][1] = \"$FiNam\";";
$filecont .= "\$episodearray[$EpNum][2] = \"$FiSiz\";";
$filecont .= "\$episodearray[$EpNum][3] = \"$dir;\"";
}
$filecont .= "?>";
fwrite($fhand,$filecont);
fclose($fhand);
}

?>

---downloadlist.php---
<table>
<tr><td>Episode number</td><td>Download link</td><td>Size</td></tr>
<?php
echo "<tr><td colspan=3><center>Anime</center></td></tr>";
include('media1/anime/list.php');
$counter=0;
foreach($anime as $ani){
$counter++;
echo "<tr><td colspan=3><center>$ani</center></td></tr>";
include('media1/anime/'.$ani.'dllist.php');
for($cs=$animenum[$counter];$cs>=1;$cs--){
if($episodearray[$cs]!=""){
echo "<tr><td>$ani - $episodearray[$cs]</td>";
echo "<td><a href=\"".$episodearray[$cs][3]."/".$episodearray[$cs][1]."\"> $episodearray[$cs][1] </a></td>";
if($episodearray[$cs][2] != 0){
echo "<td>$episodearray[$cs][2]</td></tr> \n";
}
else{
echo "<td>N/A</td></tr> \n";
}
}
echo "<tr><td>$ani - $cs</td>";
echo "<td>Not Available</a></td>";
echo "<td>N/A</td></tr> \n";
}
}
echo "<tr><td colspan=3><center>Manga</center></td></tr>";
include('media1/manga/list.php');
$counter=0;
foreach($manga as $ani){
$counter++;
echo "<tr><td colspan=3><center>$ani</center></td></tr>";
include('media1/manga/'.$ani.'dllist.php');
for($cs=$animenum[$counter];$cs>=1;$cs--){
if($episodearray[$cs]!=""){
echo "<tr><td>$ani - $episodearray[$cs]</td>";
echo "<td><a href=\"".$episodearray[$cs][3]."/".$episodearray[$cs][1]."\"> $episodearray[$cs][1] </a></td>";
if($episodearray[$cs][2] != 0){
echo "<td>$episodearray[$cs][2]</td></tr> \n";
}
else{
echo "<td>N/A</td></tr> \n";
}
}
echo "<tr><td>$ani - $cs</td>";
echo "<td>Not Available</a></td>";
echo "<td>N/A</td></tr> \n";
}
}
?>
</table>
--- bleachdllist.php ---
<?php
$episodearray[104] = 104;
$episodearray[104][1] = "Bleach-104.avi";
$episodearray[104][2] = "58mb";
$episodearray[104][3] = "www.akirablaid.com/media/downloads/";
?>[/code]
Link to comment
Share on other sites

There's a fundamental flaw in the design of your data structure.  You will have to redesign it to get it to do what you want.

What you're doing now is:

1. Set $episodearray[104] to an integer 104
2. Treat $episodearray[104] as an array

You simply can't do that.  You will need to store that number 104 somewhere else, or you will need to store the additional data in a seperate array.  For example, you could do:

[code=php:0]$episodearray[104][0] = 104;
$episodearray[104][1] = "Bleach-104.avi";
$episodearray[104][2] = "58mb";
$episodearray[104][3] = "www.akirablaid.com/media/downloads/";[/code]


Or, you could do

[code=php:0]$episodearray[104] = 104;
$episodearrayextra[104][1] = "Bleach-104.avi";
$episodearrayextra[104][2] = "58mb";
$episodearrayextra[104][3] = "www.akirablaid.com/media/downloads/";[/code]


Either will work.  But you can't set something to an integer, and then treat it as an array.  Whichever script is adding code like that needs to be fixed.
Link to comment
Share on other sites

ok, that fixed the errors, but now its not doing what i want it to do.

right now its supposed to say "Bleach - 104 Bleach-104 58mb"
but instead it says "Bleach - 1                 Array"
heres a link www.akirablaid.com/newTest.php?page=downloadlist

and heres the code segment thats displaying the screw up

[code]
include('media1/anime/list.php');
$counter=0;
foreach($anime as $ani){
$counter++;
echo "<tr><td colspan=3><center>$ani</center></td></tr>";
include('media1/anime/'.$ani.'dllist.php');
for($cs=$animenum[$counter];$cs>=1;$cs--){
  if($episodearray[$cs][0]!=""){
   echo "<tr><td>$ani - $episodearray[$cs][0]</td>";
   echo "<td><a href=\"".$episodearray[$cs][3]."/".$episodearray[$cs][1]."\"> $episodearray[$cs][1] </a></td>";
   if($episodearray[$cs][2] != 0){
    echo "<td>$episodearray[$cs][2]</td></tr> \n";
   }
   else{
    echo "<td>N/A</td></tr> \n";
   }
  }
  else {
   echo "<tr><td>$ani - $cs</td>";
   echo "<td>Not Available</a></td>";
   echo "<td>N/A</td></tr> \n";
  }
}
}
[/code]
[code]
<?php
$episodearray[104][0] = 104;
$episodearray[104][1] = "Bleach-104.avi";
$episodearray[104][2] = "58mb";
$episodearray[104][3] = "www.akirablaid.com/media/downloads/";
?>
[/code]
[code]
<?php
$anime[1] = "Bleach";
$animenum[1] = "104";
?>
<?php
$anime[2] = "Naruto";
$animenum[2] = "210";
?>
[/code]
also, while i am at it, why is it displaying up to 210, when thats from a different anime.
Link to comment
Share on other sites

GRRRRR... i worked on it a little more, but now i have a bigger problem

now its only displaying $anime[2] functions, but at least  the write list is going to it

[code]<table>
<tr><td>Episode number</td><td>Download link</td><td>Size</td></tr>
<?php
echo "<tr><td colspan=3><center>Anime</center></td></tr>";
include('media1/anime/list.php');
$key = end(array_keys($anime));
for($an=1; $an<=$key; $an++){
echo "<tr><td colspan=3><center>$anime[$an]</center></td></tr>";
include('media1/anime/'.$anime[$an].'dllist.php');
for($cs=$animemenum[$an];$cs>=1;$cs--){
  if($episodearray[$cs][1]!=""){
  echo "<tr><td>$anime[$an] - $cs</td>";
  echo "<td><a href=\"".$episodearray[$cs][3]."/".$episodearray[$cs][1]."\"> $episodearray[$cs][1] </a></td>";
  if($episodearray[$cs][2] != 0){
    echo "<td>$episodearray[$cs][2]</td></tr> \n";
  }
  else{
    echo "<td>N/A</td></tr> \n";
  }
  }
  else {
  echo "<tr><td>$anime[$an] - $cs</td>";
  echo "<td>Not Available</a></td>";
  echo "<td>N/A</td></tr> \n";
  }
}
}


echo "<tr><td colspan=3><center>Manga</center></td></tr>";
include('media1/manga/list.php');
$key = end(array_keys($anime));
for($an=1; $an<=$key; $an++){
echo "<tr><td colspan=3><center>$anime[$an]</center></td></tr>";
include('media1/manga/'.$anime[$an].'dllist.php');
for($cs=$manganum[$an];$cs>=1;$cs--){
  if($episodearray[$cs][1]!=""){
  echo "<tr><td>$anime[$an] - $cs</td>";
  echo "<td><a href=\"".$episodearray[$cs][3]."/".$episodearray[$cs][1]."\"> $episodearray[$cs][1] </a></td>";
  if($episodearray[$cs][2] != ""){
    echo "<td>$episodearray[$cs][2]</td></tr> \n";
  }
  else{
    echo "<td>N/A</td></tr> \n";
  }
  }
  else {
  echo "<tr><td>$anime[$an] - $cs</td>";
  echo "<td>Not Available</a></td>";
  echo "<td>N/A</td></tr> \n";
  }
}
}

?>
</table>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.