Author Topic: A little php development help  (Read 1086 times)


  • Veteran
  • ***
  • Posts: 85
    • View Profile
A little php development help
« on: January 19, 2008, 09:22:11 pm »
I'm trying to develop a php page that will allow you to batch set multiple media files with the same picture and attributes.  This could be useful for setting the media attributes for episodes for shows and tracks within CDs. I'm new to php and far from a web developer. I put together a page that kind of works but I'm having a problem with variables.

The problem is that after I submit a query to a DB I fill an array with some values. This works fine, but after I do another submit with a different button, the values in the array seem to disappear. Any help will be appreciated. I figured it might be some php gurus in the community.

Here is the code, bear in mind that this is a rough, kind of proof of concept. After I get it to work, I will try to incorporate it into plutoadmin:
Code: [Select]

/***************** Connect to database ******************/
mysql_connect("localhost""root""") or die(mysql_error());
mysql_select_db("pluto_media") or die(mysql_error());

/****************** Set Title ****************************/
Echo "<html>";
"<title>HTML with PHP</title>";

/***************** Variables ****************************/
$i 0;
$querStr $_POST['querStr'];
$mediaSubTypeEnum = array (=> "TV Shows",=> "Movies",=> "Home Videos"=> "Sports Events"=> "Music Videos"=> "Alternative"=> "Popular Music"=> "Classical Music");
$fileFormatEnum = array (=> "Low Res",=> "DVD",=> "Standard Def"=> "HD 720"=> "HD 1080"=> "Low Quality"=> "MP3"=> "CD Quality"=> "High-def audio");

/******************* Create main body of html page **********************************************/
Echo  "
<body bgcolor='Green'>
<form action="
.$_SERVER['PHP_SELF']." method='post'>
Search For:<input name='querStr' type='text' size='10'/>
<input type='submit' name='submit' value='submit'>"

/**************** perform action after button is clicked ***************************************/
if(isset($_POST['submit'])) { //If the initial button displayed is clicked
$result mysql_query("SELECT * FROM File Where Filename LIKE '%".$querStr."%'");
Echo " <input type='submit' name='submit2' value='submit2'> // output results of query in html table - this works fine
<table border='1'>
<th>Primary File</th>
<th>Update File</th>
while($row mysql_fetch_array($result)) {
echo "<tr>";
echo "<td><input type='radio' name='primary[]' value=$i/></td>";
echo "<td><input type='checkbox' name='CopyFile[]' value='$i'/></td>";
echo "<td>".$row['Filename']."</td>";
echo "<td>".$row['Path']."</td>";
echo "<td>".$mediaSubTypeEnum[$row['FK_MediaSubType']]."</td>";
echo "<td>".$fileFormatEnum[$row['FK_FileFormat']]."</td>";                               
$myArray[$i++] = $row['PK_File']; // this is the variable in question - it does get fill here, as expected
echo "<td>".$myArray[$i-1]." -".$i."</td>";
echo "</tr>";
echo "</table>";

/**************** perform action after second button is clicked ***************************************/
if(isset($_POST['submit2'])) {
foreach($_POST['primary'] as $value) { // determine which radio button is selected
$value $value 1;
echo "the primary is".$value."\n";
for ($i 0$i 10$i++) { 
/* simple test to see if anything is in myArray. the array appears to be empty. This is the problem area. Before the second button was clicked
the array had verified values in it.*/
echo $myArray[$i];  // the array seems to have lost all previous values
echo " in loop".$i;

$result mysql_query("SELECT * FROM Picture_File Where FK_File = '".$myArray[$value]."'"); // so the rest of the code won't work
$row mysql_fetch_array($result);
$FK_Picture $row['FK_Picture'];
$priVal $value;
echo "prival and fk_pic = ".$priVal" - ".$FK_Picture."\n";
foreach($_POST['CopyFile'] as $value) {
$value $value 1;
mysql_query("INSERT INTO `Picture_File` VALUES ($FK_Picture,$myArray[$value],NULL,NULL,NULL,0,NULL,NULL)");
mysql_query("UPDATE File SET mediaSubTypeEnum='.mediaSubTypeEnum[$priVal].' fileFormatEnum='.$fileFormatEnum[$priVal].' WHERE FK_File='.$myArray[$value].'");

" </form>

« Last Edit: January 19, 2008, 09:25:15 pm by lon22 »


  • Veteran
  • ***
  • Posts: 85
    • View Profile
SOLVED Re: A little php development help
« Reply #1 on: January 19, 2008, 11:40:46 pm »
I figued it out.
To save data:
 $saveStr = implode(",",$myArray);
 echo $saveStr;
 echo "<input type='hidden' id='arry' name='myArray' value='".$saveStr."'/>";

To retrieve data:
 $saveStr  = $_POST['myArray'];
 echo $saveStr;
 $myArray = explode(",",$saveStr);

I should have a working script in no time.