refresh main window using PHP/Javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

refresh main window using PHP/Javascript

Post 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++;
   
}
?>
mindmeddler2002
Forum Newbie
Posts: 21
Joined: Mon Nov 04, 2002 3:09 pm
Location: US, PA, Harrisuburg

meta tags?

Post 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...
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

Post by lloydie-t »

Problem is I still need to send the cust_id varible to the main window
mindmeddler2002
Forum Newbie
Posts: 21
Joined: Mon Nov 04, 2002 3:09 pm
Location: US, PA, Harrisuburg

theroy this will work

Post 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...
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

Post 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
mindmeddler2002
Forum Newbie
Posts: 21
Joined: Mon Nov 04, 2002 3:09 pm
Location: US, PA, Harrisuburg

javascript, so long ago

Post 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.
Post Reply