Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > HTML, XML, Javascript, AJAX
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 10-11-2004, 08:25 AM   #1 (permalink)
trogette
Registered User
 
Join Date: Oct 2004
Location: UK
Posts: 11
trogette is on a distinguished road
Send a message via AIM to trogette
help out a numptie... javascript and php and pop-ups and stuff

Hullo, this is my first post, i'm a refugee from a forum which isn't keen on newbies asking silly questions, given this place's name I'm hoping things are a bit more tolerant here!! (I'm a fan of the expression 'the only silly question is the one that isn't asked' *grin*) I'm quite happy to be pointed towards threads or tutorials elsewhere, of course...

I'm trying to figure out if it's possible to add pop-up windows/images to a piece of text stored in a database. The database currently stores the text and an image separately, I'd like to change that so that the thumbnail is included in the text. There's a function defined in the head of the page where the text appears, am I correct in thinking that I would leave that there (changing whatever parameters are necessary) and add that function to the text/html/javascript stored in the database?

TIA
__________________
trogette is offline   Reply With Quote
Old 10-11-2004, 08:45 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
hey welcome to the site, and yes, we have a no flaming policy here so everyone feels comfortable asking any questions. even though it's 'code newbie' , we have some very very experienced people around too.

as for your question, tell us more about the structure of your data.

1. is this image actually stored in the database? or is it just a text url that is stored?

2. is there an id field in this table? if there is, then you can send an id in the url and call the information dynamically.

here is some pseudo code to generate a popup script:

PHP Code:
<script language="JavaScript">
function 
openWindow(id){
  var 
win window.open('somepage.php?p='+id,'somepage','width=400,height=500,scrollbars=no');
  
win.focus();
}
</script>
<a href="javascript:openSpecWindow('1442')">click here</a> 
now this is what somepage.php might look like:
PHP Code:
<?
// connect to database here
$result mysql_query("select text,image from table where id=".$_GET['id']);
if(
$row mysql_fetch_array($result)){
  echo 
"text = ".$row['text']."<br>
  <img src="
.$row['image'].">\n";
}
mysql_close();
?>
this implementation would be if you were storing the image path in the database, .. not the image itself.
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 10-11-2004, 09:05 AM   #3 (permalink)
trogette
Registered User
 
Join Date: Oct 2004
Location: UK
Posts: 11
trogette is on a distinguished road
Send a message via AIM to trogette
Cheers for the welcome!

Atm I *think* it's the image path that's stored, but either way it's moot cos I won't be using either the image or the image-path on this page, just the code with the text and image-paths for the thumbnail and the pop-up. Does that make sense? (there is an option written in to not *have* to store an image, but I will do cos it's called on somewhere else.)

I think what I'm asking is if javascript is called by the php ECHO command will it work with a function that's written into the head of the page? Or does the function definition need to be in the script that's called?
__________________
trogette is offline   Reply With Quote
Old 10-11-2004, 09:10 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
well it's important to understand that php executes server-side and javascript executes on the client.

javascript is NOT called by a php echo tag. php can write a javascript function, .. but javascript is called by the text in your html page .. which can include other javascript functions.
__________________
testing 1 2 3
sde is online now   Reply With Quote
Old 10-11-2004, 09:27 AM   #5 (permalink)
trogette
Registered User
 
Join Date: Oct 2004
Location: UK
Posts: 11
trogette is on a distinguished road
Send a message via AIM to trogette
Ah sorry that was my lazy way of saying if there's javascript included in HTML/text sent to the client by the echo tag. But then logically the source of the javascript doesn't matter that much? So my original thinking was right? I just need to figure out the syntax
__________________
trogette is offline   Reply With Quote
Old 10-11-2004, 10:11 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
yes, i think my above examples will do almost exactly what you want.
__________________
testing 1 2 3
sde is online now   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 12:11 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle