PHP POPUPS? hehe

JavaScript and client side scripting.

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

PHP POPUPS? hehe

Post by John Cartwright »

I know this is the stupidest thing to ask but how can I create popups with php... don't ask why.... it just will make my life a whole lot easier. I know you propably can't :S but I thought I'd ask.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Yeah, you can't ;)
PHP is server side, so you'de need to use JavaScript, course, PHP can create the JavaScript same as it can 'create' HTML :o
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

K let's take a different course of action then.

Code: Select all

<script language="JavaScript" type="text/javascript">

flyer = "";
function pop_news(psjs_url)&#123;
    if(flyer)&#123;
        if(flyer.closed)&#123;
            flyer = window.open("news.php", "flyer", "top=" + ((screen.availHeight/2) - (500 / 2)) + ",left=" + ((screen.availWidth/2) - (700 / 2)) + ",width=500,height=500,resizable=0,toolbar=0,scrollbars=1,location=0,status=0,menubar=0")
        	
		&#125; else &#123; 
            flyer.focus();
        &#125;
    &#125; else &#123;
        flyer = window.open("news.php", "flyer", "top=" + ((screen.availHeight/2) - (500 / 2)) + ",left=" + ((screen.availWidth/2) - (700 / 2)) + ",width=500,height=500,resizable=0,toolbar=0,scrollbars=01,location=0,status=0,menubar=0")
    &#125;
&#125;

</script>
and then my link was

Code: Select all

&#1111;<a href="javascript:pop_news();">read 
              more</a>]
K so thats the javascript way.... but I have a loop which is for different news headlines there is a read more function which brings up all the news articles in the news database (news.php) and it brought to the specific article..... I'm mentally stuck on this :S
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

Just as u creat HTML code with php as response u can also create java script using php for pop ups u can use java script window.open(.....) function
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Just out of curiosity... Do i have to declare the function before using it ..

cuz you set it then it reads the rest of the code and makes sense of it and runs to function... or u gotto declare it first :S
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

nvm I just remembered all about windows.open function... all I needed to know TY
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

grr I'm trying it out but its not working very well.. getting a lot of errors

How do I format this properly

Code: Select all

<?php
			 ."<td width="73" class="readmore">[<a href="javascript:window.open(news.php, width=500, length=500, location=0);">read more</a>]</td>\n"
?>
I know #$id will give an invalid char error... but I'm getting other errors such as 'news' undefined.

I'm not sure what to do, I tried putting all the variables in window.open in quotes... and then just their numbers... but still nothng
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Might be better to just do

<td width="73" class="readmore">[<a href="javascript:window.open(news.php?id=<?php echo $id ?>, width=500, length=500, location=0);">read more</a>]</td>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

cant do that.... this is inside a loop :S
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Can still break out of PHP mode for it if you wanted..

foreach($foo as $bar){
?>
<td>..etc..etc..</td>
<?php
}
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

This is still not working

Heres a bigger snipplet.

Code: Select all

<?php
    	$result = @mysql_query("SELECT * FROM news ORDER BY `id` DESC LIMIT 10");
     		if (!$result) { 
    			echo("<p>Error performing query: " . mysql_error() . "</p>"); 
   				exit(); 
    			} 
	  
	    while ( $row = mysql_fetch_array($result) ) { 
		$title =   $row["title"]; 
 		$newsid =  $row["id"];		
		
		echo "<tr>\n"
		     ."<td height="19">$title</td>\n"; ?>
		
			 <td width="73" class="readmore">[<a href="javascript:window.open(news.php?id=<?php echo $id ?>, width=500, length=500, location=0);">read more</a>]</td>
		<?
		echo "</tr>\n";
		}
		?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

help me :(
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Whats wrong with it? Seems fine to me...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

There is a syntax error...

Line 1 Char 25 Code=0


That's all it sais... The error is that javascript line...
Last edited by John Cartwright on Fri Jan 30, 2004 2:12 pm, edited 1 time in total.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Phenom, if you want help you have to tell us the problem. Just mentioning it vaugly doesn't help! Show us the exact error you got! Show us the line it is pointing to! We can't help unless you tell us what's wrong. :wink:
Post Reply