Jump to content
MakeWebGames

Help with tables


peterisgb

Recommended Posts

Hi i am working on this video script for my local network and i am stuck with the tables, i cant figure out which way round it all goes.

i spent all last night untill 5am trying to figuring it out, please help, thanks

 

 <?php
include "head.php";

$texts = glob($directory ."tv/walkingdead/*/*.flv");
$image = glob($directory ."tv/walkingdead/*/*.jpg");
echo '<form action="watch.php" method="post">
<table border="0" width="600" cellpadding="0">
<tr><td>
';

foreach($texts as $text)
{
   $video="$text";
   $file = basename($video, ".flv");
   echo '<table border="0" width="300" cellpadding="0">
<tr width="300" height="200">
<td><INPUT type="radio" name="episode" value="'.$video.'"></td>
<td><--></td>
<td>'.$video.'</td></tr></table>
';
} 
echo '</td><td>';
foreach($image as $imge)
{
   $images="$imge";
   $file = basename($images, ".jpg");
   echo '<table border="0">
<tr width="300" height="200">
<td><img src="'.$images.'" width="300" height="200"></td>
</tr></table>';
}

echo '</td>
</tr></table>
<input type="submit" value="Watch"/></form>';
echo '<br /><br /><br /><br /><a href="index.php">Home </button>';
include "foot.php";
?>
Link to comment
Share on other sites

To achieve that you need one table that has rows with 3 columns (radio, label, image). And not multiple tables!

 

the final output should look like this:

 


<table>
 <tr>
    <td  style="vertical-align:middle"><input type="radio"></td>   <td>My episode title</td> <td> <img src="myImageSrc" /> </td>
 </tr>
 <tr>
    <td  style="vertical-align:middle"><input type="radio"></td>   <td>My episode title</td> <td> <img src="myImageSrc" /> </td>
 </tr>
 <tr>
    <td  style="vertical-align:middle"><input type="radio"></td>   <td>My episode title</td> <td> <img src="myImageSrc" /> </td>
 </tr>
</table>

 

if the index of $text is linked to the index of $image you can do one loop and get the above result;

 


echo '<table>';

for($i = 0; $i < sizeof($texts); $i++){
echo '<tr>
    <td  style="vertical-align:middle"><input type="radio" name="episode" value="'.$texts[$i].'"></td>   <td>'.$texts[$i].'</td> <td> <img src="'.$image[$i].'" /> </td>
 </tr>'
}
echo '</table>';
Link to comment
Share on other sites

To achieve that you need one table that has rows with 3 columns (radio, label, image). And not multiple tables!

 

the final output should look like this:

 


<table>
 <tr>
    <td  style="vertical-align:middle"><input type="radio"></td>   <td>My episode title</td> <td> <img src="myImageSrc" /> </td>
 </tr>
 <tr>
    <td  style="vertical-align:middle"><input type="radio"></td>   <td>My episode title</td> <td> <img src="myImageSrc" /> </td>
 </tr>
 <tr>
    <td  style="vertical-align:middle"><input type="radio"></td>   <td>My episode title</td> <td> <img src="myImageSrc" /> </td>
 </tr>
</table>

 

if the index of $text is linked to the index of $image you can do one loop and get the above result;

 


echo '<table>';

for($i = 0; $i < sizeof($texts); $i++){
echo '<tr>
    <td  style="vertical-align:middle"><input type="radio" name="episode" value="'.$texts[$i].'"></td>   <td>'.$texts[$i].'</td> <td> <img src="'.$image[$i].'" /> </td>
 </tr>'
}
echo '</table>';

well i have 2 foreach on there which makes this harder i think

Link to comment
Share on other sites

you can do it with one loop.

Or do one loop and inside that loop search for the image you need.

There's allot of ways to do this. But if you insist on keeping two loops just don't output the table in the loop and build it as a template.

here is a an example. Witch is a crappy way to do it.

 



$table = '<table>';

$i = 0;
foreach($texts as $text){

$table .= ''<tr>
      <td  style="vertical-align:middle">
           <input type="radio" name="episode" value="'.$texts[$i].'">
      </td>   
      <td>'. $text .'</td> 
      <td> {'.$i.'} </td>
   </tr>';

$i++;
}


$i = 0;
foreach($image as $img){

$imgTpl = '<img src="'.$img.'" />';

$table = str_replace('{'.$i.'}',$imgTpl);

$i++;
}


$table .= '</table'>

echo $table;
Link to comment
Share on other sites

you can do it with one loop.

Or do one loop and inside that loop search for the image you need.

There's allot of ways to do this. But if you insist on keeping two loops just don't output the table in the loop and build it as a template.

here is a an example. Witch is a crappy way to do it.

 



$table = '<table>';

$i = 0;
foreach($texts as $text){

$table .= ''<tr>
      <td  style="vertical-align:middle">
           <input type="radio" name="episode" value="'.$texts[$i].'">
      </td>   
      <td>'. $text .'</td> 
      <td> {'.$i.'} </td>
   </tr>';

$i++;
}


$i = 0;
foreach($image as $img){

$imgTpl = '<img src="'.$img.'" />';

$table = str_replace('{'.$i.'}',$imgTpl);

$i++;
}


$table .= '</table'>

echo $table;

Well i tried to put the loops in with eachother then tried to put them together, but i wasnt very good or successfull at doing it.

I'm an ok coder but i know what i know and not much other than that, which is why its bad lol. getting there tho.

would you be able to put up a demo or somthing with 2 loops in one, i tried to google it but couldnt find what i needed it.

Link to comment
Share on other sites

You have 2 arrays:

- Texts

- Images

How do you relate them ? In your code it looks like the first text match the first image and so one.

Am I right ?

 

If yes,

then the length of those arrays is the same and you can do one loop.

If not,

How do you know that text a has image b ?

Edited by HazardBoy
Link to comment
Share on other sites

This is really a simple thing... You do NOT need two foreach statements, you do not even need a foreach at all.. use a while statement (if you're using a database) and count the rows..you have your table structure wrong that is why you are having a complicated time with it...

If you are pulling info from a database this is what you can use or you may can convert it to the foreach I suppose.

$n is how many eps to show per line, I take it you want one, than the next one below it and so forth...

 

echo '<form action="watch.php" method="post">
     <table border="0" width="600" cellpadding="0">
  <tr>
   <td style="vertical-align: middle;">';
 $a=$db->query("SELECT * FROM videos") or die(mysql_error());

  $c = 0; 
  $n = 1;
  while($show= $db->fetch_row($a))
  {   
  if($c % $n == 0 && $c != 0) 
  {
  echo '
   </td>
  </tr>
  <tr>
   <td style="vertical-align: middle;">';
  }
  $c++;
  echo 'Radio Input</td><td style="vertical-align: middle;"><--></td><td style="vertical-align: middle;">Episode Name</td><td style="vertical-align: middle;">Image';
  }
echo '</table>';
Edited by lucky3809
Link to comment
Share on other sites

This is really a simple thing... You do NOT need two foreach statements, you do not even need a foreach at all.. use a while statement (if you're using a database) and count the rows..you have your table structure wrong that is why you are having a complicated time with it...

If you are pulling info from a database this is what you can use or you may can convert it to the foreach I suppose.

$n is how many eps to show per line, I take it you want one, than the next one below it and so forth...

 

No database, The first line

$texts = glob($directory ."tv/walkingdead/*/*.flv");
$image = glob($directory ."tv/walkingdead/*/*.jpg");

Selects all Videos and Pictures on the dir of the file manager

Link to comment
Share on other sites

No database, The first line
$texts = glob($directory ."tv/walkingdead/*/*.flv");
$image = glob($directory ."tv/walkingdead/*/*.jpg");

Selects all Videos and Pictures on the dir of the file manager

Then adopt a database and simplify your code.

Link to comment
Share on other sites

Then adopt a database and simplify your code.

Yes it does sound like a good idea but it'll take ages to put all the files into the database.

But there are a few hundred avi files which seems like alot of hard work when this code grabs all the files needed in the dir

I've attached a screeny of my work so far.

neither am i any good at creating my own login system to suit my needs.

s1.thumb.jpg.07c211ad23e8b9a220e73a7961ded7f2.jpg

s2.thumb.jpg.aedfde5e5e7042de80ad9154a0dff17b.jpg

s3.thumb.jpg.52eb59985851882c613decacbc95c1fe.jpg

Edited by peterisgb
Link to comment
Share on other sites

Yes it does sound like a good idea but it'll take ages to put all the files into the database.

But there are a few hundred avi files which seems like alot of hard work when this code grabs all the files needed in the dir

I've attached a screeny of my work so far.

neither am i any good at creating my own login system to suit my needs.

With proper naming conventions of your file names you can make a small script that can grab file names from your directories and insert them into your db.

You can do like tv/walkingdead/season1/ep1.flv or whatever then to grab it there are some functions you can use, explode the "/" and grab what you need from there to match up

Link to comment
Share on other sites

  • 3 months later...

I know this is a late reply, but working on it slowly.

Ive got this


$file = ($_POST['episode']);   
$direc = ($_POST['dir']);
$path_parts = pathinfo(''.$_POST['episode'].'');
$dir = ($path_parts['dirname']);
$base = ($path_parts['basename']);
$ext = ($path_parts['extension']);
$name = ($path_parts['filename']);

$sql = "INSERT  INTO `tvdir` (`id`, `directory`, `series`, `episode`, `name`, `desc`) 
	VALUES (NULL, '{$_POST['episode']}', '{$dir}', '{$name}', '', '')";
	if ($mysqli->query($sql)) {
		//echo "New Record has id ".$mysqli->insert_id;
		echo "<p>Entered Into Database!</p>";
	} else {
		echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>";
		exit();
	}

 

which does place it into the database, but my knowledge isnt good enough to firgure out how to do them all at once.

Link to comment
Share on other sites

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.   Paste as plain text instead

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