peterisgb Posted June 7, 2014 Share Posted June 7, 2014 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"; ?> Quote Link to comment Share on other sites More sharing options...
sniko Posted June 7, 2014 Share Posted June 7, 2014 What do you mean by "i cant figure out which way round it all goes"? Quote Link to comment Share on other sites More sharing options...
HazardBoy Posted June 7, 2014 Share Posted June 7, 2014 What a mess. :) Maybe tell us what you want to achieve ? How should it look like ? first of all give up the tables or keep them if you try to align stuff vertically. Give the "expected result" and we can help you. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted June 7, 2014 Author Share Posted June 7, 2014 well Here is a Screeny. Basically i want the "Input radio, <-->, Episode Name, the Picture" all on one line. as you can see from the screeny it doesnt line up. Quote Link to comment Share on other sites More sharing options...
DidNotCompute Posted June 7, 2014 Share Posted June 7, 2014 well Here is a Screeny. Basically i want the "Input radio, <-->, Episode Name, the Picture" all on one line. as you can see from the screeny it doesnt line up. Use vertical align. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted June 7, 2014 Author Share Posted June 7, 2014 Use vertical align. Thanks, what a star. Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted June 7, 2014 Share Posted June 7, 2014 Haha........... Quote Link to comment Share on other sites More sharing options...
HazardBoy Posted June 8, 2014 Share Posted June 8, 2014 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>'; Quote Link to comment Share on other sites More sharing options...
peterisgb Posted June 8, 2014 Author Share Posted June 8, 2014 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 Quote Link to comment Share on other sites More sharing options...
HazardBoy Posted June 8, 2014 Share Posted June 8, 2014 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; Quote Link to comment Share on other sites More sharing options...
peterisgb Posted June 8, 2014 Author Share Posted June 8, 2014 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. Quote Link to comment Share on other sites More sharing options...
HazardBoy Posted June 9, 2014 Share Posted June 9, 2014 (edited) 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 June 9, 2014 by HazardBoy Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted June 9, 2014 Share Posted June 9, 2014 (edited) 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 June 9, 2014 by lucky3809 Quote Link to comment Share on other sites More sharing options...
peterisgb Posted June 9, 2014 Author Share Posted June 9, 2014 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 Quote Link to comment Share on other sites More sharing options...
sniko Posted June 9, 2014 Share Posted June 9, 2014 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. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted June 9, 2014 Author Share Posted June 9, 2014 (edited) 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. Edited June 9, 2014 by peterisgb Quote Link to comment Share on other sites More sharing options...
sniko Posted June 9, 2014 Share Posted June 9, 2014 Yes it does sound like a good idea but it'll take ages to put all the files into the database. No it wouldn't. You've already got the code there, you just need to change it a little ;) Quote Link to comment Share on other sites More sharing options...
peterisgb Posted June 9, 2014 Author Share Posted June 9, 2014 hmmm, well i have tried a few login systems out there but i havent found one simple enough and aint good enough to do it myself. Best i could do is strip down mccodes and use that which is a bad idea..... Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted June 9, 2014 Share Posted June 9, 2014 hmmm, well i have tried a few login systems out there but i havent found one simple enough and aint good enough to do it myself. Best i could do is strip down mccodes and use that which is a bad idea..... They have a login script how to on wikihow, really simple to follow. http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted June 10, 2014 Share Posted June 10, 2014 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 Quote Link to comment Share on other sites More sharing options...
peterisgb Posted September 17, 2014 Author Share Posted September 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.