-2

I have a select box and when it selects it refreshes the page causing the iframe to update its link. Now everything works fine except every time I change value of listbox it refreshes the entire page, and I am looking for partial only.

The select and iframe, now I'll show you my PHP and then maybe it will clear out the situation!

<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$dbh = mysql_connect("host", "user", "pass");
mysql_select_db("database_name");
############END OF CONNECT SCRPIT#############################
$id = $_GET['id'];
######id as in index.php?id=1 from the list page#####
$anime = "SELECT * FROM anime WHERE id=$id";
$anime_query = mysql_query($anime) or die(mysql_error());
$thisanime = mysql_fetch_assoc($anime_query);
$amountepi = $thisanime['episodes'];
if(isset($_POST['epinum'])){
$epinum = $_POST['epinum'];  // Storing Selected Value In Variable
##############episodes number how many 1-2-3!!
$episodes = "SELECT * FROM episodes WHERE animeid = $id AND number = $epinum";
$episodes_query = mysql_query($episodes) or die(mysql_error());
$allepisodes = mysql_fetch_assoc($episodes_query);
}
?>
<html>
<!-- Header -->
<?PHP require('work/header.php'); ?>
<!-- Sidebar -->
<?PHP require('work/left.php'); ?>
</div><div></div><div></div></div><div></div></div></div>
<!-- bagian main -->
<div id='main-wrapper'>
<div><div><div><div><div></div><div><div></div></div></div><div></div></DIV><div></div><div>
<div class="post-container">
    <h3 class="post-title"><?PHP echo $thisanime['animename']; ?> <font style='float:right;'>Status:<font color='green'><?PHP echo $thisanime['status']; ?></h3>
    <div class="post-thumb"><img src="<?PHP echo $thisanime['imagecover']; ?>" /></div>
    <div class="post-content">
         <p></p>
        <font color="yellow">Year Of Release:<?PHP echo $thisanime['year']; ?></font>
        <p><font color="lightblue"><?PHP echo $thisanime['description']; ?> </p></font></div>
</div>


*******thisisthepartIwantonlytorefresh********


<tbody><tr><td>
<?PHP echo " <font size='4' color = 'blue'>Episode   " . $allepisodes["number"]. "        -->" . $allepisodes["name"]. "</font>"; ?>


<form class="anilist" action="" method="post">
<select class="listofepisodes" onchange='this.form.submit()' name="epinum" multiple='multiple'>
<?PHP if ($amountepi==3){ ?>
<option value='1' <?php if($allepisodes['number']==1) echo "selected='selected'"; ?>>Episode 1</option>
<option value='2' <?php if($allepisodes['number']==2) echo "selected='selected'"; ?>>Episode 2</option>
<option value='3' <?php if($allepisodes['number']==3) echo "selected='selected'"; ?>>Episode 3</option>
<?PHP }elseif ($amountepi==2){ ?>
<option value='1' <?php if($allepisodes['number']==1) echo "selected='selected'"; ?>>Episode 1</option>
<option value='2' <?php if($allepisodes['number']==2) echo "selected='selected'"; ?>>Episode 2</option>
<?PHP }elseif ($amountepi==1){ ?>
<option value='1' <?php if($allepisodes['number']==1) echo "selected='selected'"; ?>>Episode 1</option>
<?PHP } ?>
</select>
<noscript>&lt;input type="submit" value="Submit"&gt;</noscript>
</form>

 <iframe src="<?PHP echo $allepisodes['code']; ?>" width="408" height="324" frameborder="1" allowfullscreen></iframe>



*************till here************************



</div></div></div></div></div>
<!-- sidebar right -->
<?PHP require('work/right.php'); ?>
<!-- Footer -->
<?PHP require('work/footer.php'); ?>
George Stocker
  • 57,289
  • 29
  • 176
  • 237
Animex PHP
  • 62
  • 1
  • 9
  • The link to your code returns 404. I'll remove it, if you would edit your code into the question, that is a much better way to supply it anyway. – halfer Nov 29 '14 at 00:07
  • You have SQL injection vulnerabilities in this code. – halfer Nov 29 '14 at 00:10
  • I did i was just looking for a way to show the php file visible , so help me if you can , tnx ^_^ – Animex PHP Nov 29 '14 at 00:11
  • Are there any JavaScript errors in your browser console, when you change the list box? – halfer Nov 29 '14 at 00:12
  • Nope there Are no errors , just trying to figure out how do i get to refresh that content without affecting the top content of the script – Animex PHP Nov 29 '14 at 00:14

1 Answers1

1

If you want to post your form and display the result in the iframe, you can use this.

<form target="refreshing_iframe">
 ...
</form>
<iframe name="refreshing_iframe" ... >

Source How do you post to an iframe?

Edit

The best way to do what you want to do is to load all episodes for the anime id so that you end up with all the urls to each episode. Then you dont need to contact the server again when someone chooses a different episode. You could default the iframe to episode 1 code (url). Then just add links for each episode which updates the iframe src when clicked.

Community
  • 1
  • 1
Phil
  • 1,996
  • 1
  • 19
  • 26
  • Its not going to work because it POSTS the select result which causes it to refresh the entire page and Without post how is it going to change variable value? – Animex PHP Nov 29 '14 at 00:23
  • This will POST the form to your iframe which means your page will not do a full refresh. Obviously that causes other issues since your sql wont run every time you change your select box, but one step at a time eh. Work on getting just the iframe refreshing, then move your sql to another php file which your form action points to. – Phil Nov 29 '14 at 00:37
  • Yes I was able to refresh Easly the iframe itself but even the iframe has a src="link" that is being pulled of the sql which makes it practicaly impossible if that form isnt posted the var episode number dosent got a value so .. Thats one BIG thing I couldnt figure! – Animex PHP Nov 29 '14 at 00:52
  • OK, then this answer is wrong. I see more what you are trying to do. The way I would do it would be to load all episodes for the anime id so that you end up with all the urls to each episode. You could then default the iframe src to episode 1 code. Then above the iframe, create an anchor link for each episode which only updates the iframe src when clicked. – Phil Nov 29 '14 at 01:12
  • thanks I sill try my best , its just that its hard database pulls specific specified values but actually you gave me an idea there from your writing above shall pull all episodes link beforehand so when page is loaded they are all variables and then all Ill have to do is use them with iframes that way i woun't be involving sql because link will be already pulled as variable , thanks a lot , i will try my best on working on it , if you know the way i could change all that it will make it easier for me . – Animex PHP Nov 29 '14 at 08:55
  • if not still thanks because now i know that this way should work and ill try my best to script it :) that last comment is the answer to my question if that works out ! Ill comment back as soon as I get something working ! – Animex PHP Nov 29 '14 at 08:57
  • Could I just say im soooooo happy everything got figured out , as soon as i transformed every episode link into a variable there was no need to contact db everytime it only pulls it once and everything got sorted ThankYou Very Much Phil_1984_ – Animex PHP Nov 30 '14 at 12:59
  • ok, i will update this answer so it is correct. Thanks – Phil Nov 30 '14 at 14:16