title: Use PHP variable in AJAX
body: <p>I am trying to accomplish the following on the page "videos.php" (note, this is all inside of a PHP echo):</p>
  
  <ol>
  <li>User clicks <strong>.star_' . $pvid_ID . '</strong> which submits a video rating to a form (this is working properly)</li>
  <li>Now, I need to refresh the div that displays the current video rating to show the updated video rating, which is stored in the variable <strong>$avg_rating</strong> (grabbed from the DB in an earlier query on videos.php).</li>
  <li>To update the variable <strong>$avg_rating</strong>, I want to POST the id of the video to <strong>find_ratings2.php</strong> (that video ID is currently stored on "videos.php" as <strong>$pvid_ID</strong>)</li>
  </ol>
  
  <p>Here is what I have as my jquery/ajax on "videos.php":</p>
  
  <pre><code>echo'
  &lt;script type="text/javascript" language="javascript"&gt;
  $(document).ready(function() {
     $(".star_' . $pvid_ID . '").click(function() {
         $.ajax({
             type: "POST",
             url: \'/dev/scripts/find_ratings2.php\',
             data: { videoid: ' . $pvid_ID . ' },
             success: function(data) {
                 $(".parent_video_' . $pvid_ID . '").load(\'testratings.php .vid_frame_id_' . $pvid_ID . '\').hide().fadeIn(2000);
              }
          });
      });
  });                        
  &lt;/script&gt;
  ';
  </code></pre>
  
  <p>then, on find_ratings2.php I've got:</p>
  
  <pre><code>&lt;?php
  require('config.php');
  require('checklogin.php');
  
  $video_id = $_POST['videoid'];
  $mysqlicon3 = mysqli_connect($db_host, $db_username, $db_password, $db_name);
  $find_rating = mysqli_query($mysqlicon3, "SELECT AVG(rating) AS avgRating FROM videoRatings WHERE videoID = '$video_id'");
  
  while ($rating_row = mysqli_fetch_array($find_rating)) {
      $avg_rating = $rating_row['avgRating'];
  }
  ?&gt;
  </code></pre>
  
  <p>When <strong>.star_' . $pvid_ID . '</strong> is clicked, the div is being refreshed properly (the .hide() and .fadeIn() are also working), but <strong>$avg_rating</strong> is not being updated.</p>
  
  <p>For reference, <strong>$avg_rating</strong> is on "videos.php" like this:</p>
  
  <pre><code>echo'
  &lt;div class="parent_video_' . $pvid_ID . '"&gt;
      &lt;div class="comment_iconimg-stars vid_frame_id_' . $pvid_ID . '"&gt;
          &lt;div class="video-stars"&gt;&lt;input class="imgstar star_' . $pvid_ID . '" type="image" src="';
          if ($avg_rating &gt; 0){echo '/dev/images/rate_video_icon_yellow.png';} else{echo '/dev/images/rate_video_icon.png';}
          echo '" border="0" /&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;';
  </code></pre>