Page 1 of 1

refresh main window using PHP/Javascript

Posted: Mon Nov 04, 2002 4:35 pm
by lloydie-t
I have a script which shows customer info. This window is empty. What I want to do is select a customer ID in a new window and then refresh the main window with the customer ID.
I have taken a stab at embeding some javascript in my PHP script, but it does not work. Can anyone point me in the right direction. Please bear in mind I have little javascript experience. Find the code for the child window:

Code: Select all

<?php
$query = "select * from customer where cust_name like '%$company%' ";
$queryResult = mysql_query($query);
$i=0;

while($row =mysql_Fetch_array($queryResult)) 
{ 
    
    if (is_int($i/2))
    {
        
        $bgcolor = "#cccccc";
        
    }
    
    else
    {
        
        $bgcolor = "#ffcc99";
        
    }
    
    print "<tr>";
    print "<td>";
    print "<td bgcolor="$bgcolor">$rowїcust_id]</td>";
print "<td bgcolor="$bgcolor"><a href="javascript:;"window.opener.location.reload"('customeradmin.php?cust_id=$rowїcust_id]'">$rowїcust_name]</a></td>"; 
    print "<td bgcolor="$bgcolor">$rowїpostcode]</td>";
    print "<td bgcolor="$bgcolor">$rowїcust_phone]</td>";
    print "</tr>";
    $i++;
   
}
?>

meta tags?

Posted: Mon Nov 04, 2002 8:29 pm
by mindmeddler2002
Why not use a basic meta tag, and have the main page auto update every minute or something?

(like cheap chat rooms)


<?php
echo "<META HTTP-EQUIV=Refresh CONTENT=0;URL=index.php>";
?>

where 0 is replace it with amount of secounds...

Posted: Mon Nov 04, 2002 8:40 pm
by lloydie-t
Problem is I still need to send the cust_id varible to the main window

theroy this will work

Posted: Mon Nov 04, 2002 9:20 pm
by mindmeddler2002
use a include...

in the pop up window
make a temp cookie or something that holds the info
then have a include with the meta tag,
i think when u include it, with a meta tag, it will update just that part

in theory...
anyways, have it search for the cookie each time, after its found, have it print it or what ever...

if not found, use a or else statment, so that it does not print a error...

this is just in theory.

tell me if it works, i am interested...

Posted: Mon Nov 04, 2002 9:38 pm
by lloydie-t
I managed to sort it out myself with a bit of jiggery pokery and some informed reading.
So in the main window you have some javascript in the header

Code: Select all

window.name = "customeradmin";
you need to use javascript to open new window.

The code in the new window goes like:

Code: Select all

$query = "select * from customer where cust_name like '%$company%' "; 

$queryResult = mysql_query($query); 

$i=0;
while($row=mysql_Fetch_array($queryResult)) 
{
   // if $i%2 is 0, the number is even, otherwise it will be odd.  
   $bgcolor=($i%2==0)?"#cccccc":"#ffcc99";
    print "&lt;tr&gt;"; 
    print "&lt;td&gt;"; 
    print "&lt;td bgcolor="$bgcolor"&gt;{$row&#1111;'cust_id']}&lt;/td&gt;"; 
print "&lt;td bgcolor="$bgcolor"&gt;&lt;a href="customeradmin.php?cust_id={$row&#1111;'cust_id']};" TARGET="customeradmin"&gt;{$row&#1111;'cust_name']}&lt;/a&gt;&lt;/td&gt;";  
    print "&lt;td bgcolor="$bgcolor"&gt;{$row&#1111;'postcode']}&lt;/td&gt;"; 
    print "&lt;td bgcolor="$bgcolor"&gt;{$row&#1111;'cust_phone']}&lt;/td&gt;"; 
    print "&lt;/tr&gt;"; 
    $i++;
}

?&gt;
Thanx for your help

javascript, so long ago

Posted: Mon Nov 04, 2002 9:47 pm
by mindmeddler2002
LOL,
Its been about 4 years since i did anything in javascript...

that would have helped so long ago...

kool, now i know

thank you.