Hey guys, below is my code, I am working on trying to PASS Variables to a popup window. I have it to where it show the embed window(which is blank) link, the title(which is blank) and instuctions(which is blank), but I cannot get it to pass the variables of what I want to the popup window. I will also append the popup window for you. Thanks everyone for your help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Exercise Video Library</title>
<link href="twoColHybLtHdr.css" rel="stylesheet" type="text/css" /><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColHybLtHdr #sidebar1 { padding-top: 30px; }
.twoColHybLtHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it may need to avoid several bugs */
</style>
<![endif]-->
<script type="text/javascript">
function showactiveLink(){
document.getElementById("arrow").innerHTML = "<img src='images/smallArrow.gif'>";
}
</script>
<script type="text/javascript">
function loadwindow(page){
window.open(page,"popup","width=560,height=800,status=1")
} 
</script>
</head>

<body onload="showactiveLink()" class="twoColHybLtHdr">

<div id="container">
  <div id="header">
    <div><h1><font color="red">Exercise Video Library</font></h1></div>
    <div id="search-form" align="right"><form id="search-block-form" action="search.php" method="get"><input type="text" name="q" /><input id="divbutton" title="Search" name="search" alt="Search" type="submit" value="" /></form></div>
    <div align="right" id="contactinfo">Contact Us: (719) 576-2256</div>
    <div align="Center" id="navigation"><a href="index.html">Home</a> | <a href="library.html">Excercise Library</a> | Tutorials | Sample Workouts | <a href="design-your-workout.html">Design Your Workout</a> | Health & Fitness Assessment </div>
  <!-- end #header --></div>
  <div>&nbsp;</div>
  <div>&nbsp;</div>
  <div id="sidebar1">
    <h3>Quick Links</h3>
    <li>Master Food list</li><br />
    <li>Workout/Nutrition Logs</li><br />
    <li>Fitness Terms &amp; Definations</li><br />
    <li>Rehbilitation Tips</li>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<li>Injury Recovery</li>

  <!-- end #sidebar1 --></div>
  <div id="mainContent">
    <div class="textwidget">
    <?php
$hostname_logon = "omited" ;
$database_logon = "omited" ;
$username_logon = "omited" ;
$password_logon = "omited" ;
//open database connection
$connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unable to connect to the database" ). mysql_error();
//select database
mysql_select_db($database_logon) or die ( "Unable to select database!" );

//specify how many results to display per page
$limit = 5;

//get the search variable from URL
$var = mysql_real_escape_string(@$_REQUEST['q']);

//get pagination
$s = mysql_real_escape_string($_REQUEST['s']);

//set keyword character limit
if(strlen($var) < 3){
    $resultmsg =  "<p>Search Error</p><p>Keywords with less then three characters are omitted...</p>" ;
}
//trim whitespace from the stored variable
$trimmed = trim($var);
$trimmed1 = trim($var);
//separate key-phrases into keywords
$trimmed_array = explode(" ",$trimmed);
$trimmed_array1 = explode(" ",$trimmed1);

// check for an empty string and display a message.
if ($trimmed == "") {
    $resultmsg =  "<p>Search Error</p><p>Please enter a search...</p>" ;
}

// check for a search parameter
if (!isset($var)){
    $resultmsg =  "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ;
}

// Build SQL Query for each keyword entered
foreach ($trimmed_array as $trimm){

  //If MATCH query doesn't return any results due to how it works do a search using LIKE
 if($row_num_links_main < 1){
    $query = "SELECT title, id, keywords, catagories, emurl FROM libvid WHERE keywords LIKE '%$trimm%' OR catagories LIKE '%$trimm%'  ORDER BY title DESC";
    $numresults=mysql_query ($query);
    $row_num_links_main1 =mysql_num_rows ($numresults);
 }
 // next determine if 's' has been passed to script, if not use 0.
 // 's' is a variable that gets set as we navigate the search result pages.
 if (empty($s)) {
     $s=0;
 }

  // now let's get results.
  $query .= " LIMIT $s,$limit" ;
  $numresults = mysql_query ($query)  or die ( "Couldn't execute query" );
  $row= mysql_fetch_array ($numresults);

  //store record id of every item that contains the keyword in the array we need to do this to avoid display of duplicate search result.
  do{
      $adid_array[] = $row[ 'title' ];
  }while( $row= mysql_fetch_array($numresults));
} //end foreach

//Display a message if no results found
if($row_num_links_main == 0 && $row_num_links_main1 == 0){
    $resultmsg = "<p>Search results for: ". $trimmed."</p><p>Sorry, your search returned zero results</p>" ;
}

//delete duplicate record id's from the array. To do this we will use array_unique function
$tmparr = array_unique($adid_array);
$i=0;
foreach ($tmparr as $v) {
   $newarr[$i] = $v;
   $i++;
}

//total result
$row_num_links_main = $row_num_links_main + $row_num_links_main1;

// now you can display the results returned. But first we will display the search form on the top of the page
echo '<form action="search.php" method="get">
        <div>
        <input name="q" type="text" value="'.$q.'">
        <input name="search" type="submit" value="Search">
        </div>
</form>';

// display an error or, what the person searched
if( isset ($resultmsg)){
    echo $resultmsg;
}else{
    echo "<p>Search results for: <strong>" . $var."</strong></p>";

    foreach($newarr as $value){

    // EDIT HERE and specify your table and field unique ID for the SQL query
    $query_value = "SELECT * FROM libvid WHERE title = '".$value."'";
    $num_value=mysql_query ($query_value);
    $row_linkcat= mysql_fetch_array ($num_value);
    $row_num_links= mysql_num_rows ($num_value);

    //create summary of the long text. For example if the field2 is your full text grab only first 130 characters of it for the result
    $introcontent = strip_tags($row_linkcat[ 'title']);
    $introcontent = substr($introcontent, 0, 130)."...";

    //now let's make the keywods bold. To do that we will use preg_replace function.

    //Replace field
      $title = preg_replace ( "'($var)'si" , "<strong>\\1</strong>" , $row_linkcat[ 'title' ] );
      $desc = preg_replace ( "'($var)'si" , "<strong>\\1</strong>" , $introcontent);
      $link = preg_replace ( "'($var)'si" , "<strong>\\1</strong>" ,  $row_linkcat[ 'emurl' ]  );
      $cata = preg_replace ( "'($var)'si" , "<strong>\\1</strong>" ,  $row_linkcat[ 'catagories' ]  );
      $instr = preg_replace ( "'($var)'si" , "<strong>\\1</strong>" ,  $row_linkcat[ 'instructions' ]  );

        foreach($trimmed_array as $trimm){
            if($trimm != 'b' ){
                $title = preg_replace( "'($trimm)'si" ,  "<strong>\\1</strong>" , $title);
                $desc = preg_replace( "'($trimm)'si" , "<strong>\\1</strong>" , $desc);
                $link = preg_replace( "'($trimm)'si" ,  "<strong>\\1</strong>" , $link);
                $cata = preg_replace( "'($trimm)'si" ,  "<strong>\\1</strong>" , $cata);
                $instr = preg_replace( "'($trimm)'si" ,  "<strong>\\1</strong>" , $instr);
             }//end highlight
        }//end foreach $trimmed_array

        //format and display search results
            echo '<div class="search-result">';
                echo '<div class="search-title">Video Title: '.$title.'</div>';
                echo '<div class="search-link">';
                echo '<a href="#" onClick="javascript:loadwindow(\'popup.php?view&var1=$title&var2=$link&var3=$instr \')"><img src=http://i3.ytimg.com/vi/'.$link.'/0.jpg width="236" height="147" /></a>';
                echo '</div>';
                echo '<div class="search-cata">';
                echo '<p><font size="-2" >Catagories: '.$cata. '</font></p>';
                echo '</div>';
                echo '<br />';
                echo '<br />';
            echo '</div>';

    }  //end foreach $newarr

    if($row_num_links_main > $limit){
    // next we need to do the links to other search result pages
        if ($s >=1) { // do not display previous link if 's' is '0'
            $prevs=($s-$limit);
            echo '<div class="search_previous"><a href="'.$PHP_SELF.'?s='.$prevs.'&q='.$var.'">Previous</a>
            </div>';
        }
    // check to see if last page
        $slimit =$s+$limit;
        if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1) {
            // not last page so display next link
            $n=$s+$limit;
            echo '<div  class="search_next"><a href="'.$PHP_SELF.'?s='.$n.'&q='.$var.'">Next</a>
            </div>';
        }
    }//end if $row_num_links_main > $limit
}//end if search result
?>
</div>
    <h2> </h2>
    <p></p>
    <!-- end #mainContent --></div>
    <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
    <br class="clearfloat" />
    <div id="footer">
    <div id="footernav"><font color="#FFFFFF" size="-2">Contact Us | Help/FAQs | <a href="terms.html">Terms of Service</a> | <a href="privacy.html">Privacy Policy</a> | Partners/Affiliate Program</font><div id="copyrightinfo" align="right"><font color="#FFFFFF" size="-2">Copyright &copy; 2013: Exercise Video Library</font></div></div>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>

Here is the code for the popup window.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>
<?php
$_GET['var1'];
$_GET['var2'];
$_GET['var3'];
echo '<div class="search-result">';
                echo '<div class="search-title">Video Title: '.$var1.'</div>';
                echo '<div class="search-link">';
                echo '<iframe width="560" height="315" src="http://www.youtube.com/embed/'.$var2.'&loop=1" frameborder="0" allowfullscreen></iframe>';
                echo '</div>';
                echo '<div class="search-cata">';
                echo '<p>Instructions: '.$var3.'</p>';
                echo '</div>';
                echo '<br />';
                echo '<br />';
            echo '</div>';

?>
</body>
</html>
Member Avatar for LastMitch

I have it to where it show the embed window(which is blank) link, the title(which is blank) and instuctions(which is blank), but I cannot get it to pass the variables of what I want to the popup window. I will also append the popup window for you. Thanks everyone for your help.

You know you're title is very misleading Passing PHP variables in Popup

Then when I look closer you are echoing out the youtube links from your database?

If it was something different than maybe I can tweak it but it's youtube links.

Im just trying to echo the variables from the main page to the popup, can you please help me?

Member Avatar for LastMitch

Im just trying to echo the variables from the main page to the popup, can you please help me?

Why didn't you put the query in your popup window?

How are you going to get the variables?

When you used javascript to make the window pop up.

That's it ... that's all you need from the javascript.

You treat the window popup page as a seperate page so you do need a query to $_GET['var1'];

Does that make sense?

Kinda, I am trying to get the variables to pass through so we can view the video on a seperate page. I have tried many different things to get the variables of the table to pass, but it wont. On the popup window, it just needs to be simple, the title, url for embed, and instructions. The reason we are doing this is just for instructional videos that repeat on a loop, most are no more then 15 seconds long, but we need them to echo to the popup for ease...

Member Avatar for LastMitch

On the popup window, it just needs to be simple, the title, url for embed, and instructions.

You mean this:

popup.php?view&var1=$title&var2=$link&var3=$instr

can you echo out the title at least?

$_GET['var1'];

If you can't echo the title then there's something wrong with your query from the file not from the popup window.

If you can't echo the title then there's something wrong with your query from the file not from the popup window.

No I cannot get anything to pass through.

Member Avatar for LastMitch

Can you put title together meaning no white space (I notice you have a lot of whitespace on your other variables):

From this:

$introcontent = strip_tags($row_linkcat[ 'title']

to this

$introcontent = strip_tags($row_linkcat['title']

Instead of $_GET try put $_POST:

$_POST['var1'];
$_POST['var2'];
$_POST['var3'];
Member Avatar for LastMitch

Instead of this:

echo '<a href="#" onClick="javascript:loadwindow(\'popup.php?view&var1=$title&var2=$link&var3=$instr \')">';

Try this:

Put the popup.php?view&var1=$title&var2=$link&var3=$instr in a variable $page

Like this:

$page = 'popup.php?view&var1=$title&var2=$link&var3=$instr';

Then do this (I took away the image part because the purpose is to echo strings):

echo '<a href="#" onclick="popup('<?php echo $page ?>')"></a>

This should echo the title and link.

Keep you pop window the same.

If it doesn't work change the $_GET to $_POST in the popup window to try it again

Ok, this is how i have the section of code:

echo '<div class="search-result">';
                echo '<div class="search-title">Video Title: '.$title.'</div>';
                echo '<div class="search-link">';
                echo '<a href="#" onclick="popup('<?php echo $page ?>')"><img src=http://i3.ytimg.com/vi/'.$link.'/0.jpg width="236" height="147" /></a>';
                    $page = 'popup.php?view&var1=$title&var2=$link&var3=$instr';
                echo '</div>';
                echo '<div class="search-cata">';
                echo '<p><font size="-2" >Catagories: '.$cata. '</font></p>';
                echo '</div>';
                echo '<br />';
                echo '<br />';
            echo '</div>';

but getting this parse error:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /homepages/36/d301143136/htdocs/omitted/search.php on line 181

Member Avatar for LastMitch

you don't need to put the

$page = 'popup.php?view&var1=$title&var2=$link&var3=$instr';

within here (it should be on top):

$page = 'popup.php?view&var1=$title&var2=$link&var3=$instr';

echo '<div class="search-result">';
echo '<div class="search-title">Video Title: '.$title.'</div>';
echo '<div class="search-link">';
echo '<a href="#" onclick="popup('<?php echo $page ?>')"></a>';
echo '</div>';
echo '<div class="search-cata">';
echo '<p><font size="-2" >Catagories: '.$cata. '</font></p>';
echo '</div>';
echo '<br />';
echo '<br />';
echo '</div>';

I told you to take out the image for now. The goal is to echo the strings (variables).

forget the above response,

I got it to not error out, but i think the error that i am having is i have to put:
echo '<a href="#" onclick="popup(\'<?php echo $page ?>\')"></a>

to make the code work propery and not cause a parse error

Member Avatar for LastMitch

to make the code work propery and not cause a parse error

You are having issues with the query echoing the data to the pop up window?

I'm not really changing much of the code. It's still the same. I hope you notice.

I feel you are very impatience.

If you think that the little changes is cause a parse error then what do you want to do?

The issue you are having is not getting the variable echoing in the pop up window.

It's close to midnight. I hope you know I have other better things to do rather than help you and I also help other people too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.