Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fetching data from mysql

Status
Not open for further replies.

rshandy

Technical User
Dec 26, 2003
91
US
Thanks to all the great posts, I currently have an html page that changes about 20 or so fields on an html page depending on what graphic the user clicks on. The data is was initially created in an array in a js in the header of the document.

I then created an external js script to house that array and its still works fine. The problem is that the data in the array needs to change/be updated from a database - I thought mysql would be a logical choice as my softcart database is too quirky in this approach.

Can anyone tell me if its possible to retreive mysql data from a static html page, after the page is loaded.

Would it be logical to have an external js script that calls a server side program that fetches the data (i.e perl, PHP)??? And if so, what would that look like.

Any thoughts or direction would be a great start.

Thanks,

Rich
 

Can anyone tell me if its possible to retreive mysql data from a static html page, after the page is loaded.

Not AFAIK, given that one is client-side, and one would require server-side code to execute.

Why not build the JS file dynamically using PHP, etc?

Hope this helps,
Dan

 
Thanks for the reply Dan.

I need to use static html. I'm wondering whether I can call an external file PHP/Perl to generate a JS array - maybe create an external JS file that then gets called from the html page?

Don't know whether I'm going to run into an unexpected nightmare.

I like to try and test this approach.

Right now I call a few functions from within the html:

<a href='javascript:createHide1(0,0,0,2,0,0,0,"4");MM_swapImage("mwlife_familypic"," ", " name="mw_1636_sw" src="graphics/mw_1636_sw.jpg" width="90" border="0" ></a>


the create hide1 function pulls from an array and changes values in div tags within the body of the page.


How would I call a Perl script first (based on above).

I'm going to have the Perl script write the array (pulling from a mysql DB) in an external js, then call that external js from the createhide1 function.

Think this will cause problems??

Thanks,

Rich
 

I need to use static html.

If you need to use static HTML because your server doesn't support PHP, then trying to use PHP at all would be fruitless.

If your server does support PHP, then why not use it to create the JS file dynamically? As far as your browser is concerned, any content delivered to it WILL be static.

Dan

 
You will need some kind of server-side scripting solution available in order to query the mySQL database anyway. You cannot query the database directly from the page because the query has to be done on the server (and requested from the server).

Find out if you have access to a server-side scripting solution first. Let us know what one (ASP, JSP, PHP, CFM, ASPX etc) and then we can look at taking things further.

Cheers,
Jeff
 
Thanks for the posts guys. It's not that the server doesn't support PHP et al, its a search engine optimization thing.

I may have run into a wall anyway as my ISP isn't offering mysql.

Here's the problem: I use softcart for a product database (kinda stuck with it at this point). Softcart interprets tags on html pages i.e. %%product(12345).price%% would return the price for sku 12345.

The only way to get softcart to interpret that tag is to execute the program SoftCart.exe.

I can do this with no problem using a perl script in a form tag either like this:

<form action="
or

<form action="
and then having a js function on the page like this:

SCPath = "/cgi-bin/SoftCart.exe";
config = "scstore";
if (location.pathname.substring(0,SCPath.length)!= SCPath) {
window.location.replace(SCPath + location.pathname + "?E+" + config);
}


I setup a test page just to write some data to txt file by calling it from the body of the html product page and its works fine if I don't parse the url through SoftCart - But when I do include the SoftCart path, either directly in the path or as a function on the page ...

<script language="JavaScript1.2" src="
I get a js syntax error.

I hope I explained this enough to get a sense of the problem.

Let me know.

Rich
 
What do mean by "output"?. The PL script runs fine with out the SoftCart.exe path, and the output is writing to a txt file.

Sorry, not quite sure what you mean - could you explain, please

Rich
 
You said that you have this code:

Code:
<script language="JavaScript1.2" src="[URL unfurl="true"]http://www.mydomain.com/cgi-bin/SoftCart.exe/cgi-bin/write_test_softcart.pl"></script>[/URL]

Which is including a JS file on the page, delivered by "write_test_softcart.pl".... So unless "write_test_softcart.pl" is delivering valid JS, you will get JS errors.

Dan
 
Ok, thanks.

"write_test_softcart.pl" is delivering valid JS. In fact I validated this by removing the /cgi-bin/SoftCart.exe in the path. Everything then works fine.

But... when I put that additional path back in (still goes to the same page) I get an error

Rich

 

Then surely that means that with the full path in, it is NOT delivering valid JS. Post the exact output of what it is delivering with the full path in and we shall see.

Dan

 
Hey Dan:

I created a test page so you can see what's happening:


This page has a link to the Perl script that will interpret the softcart tag and write it to a txt file.

The other link will take you to an identical page except that I added the call of the Perl script in JS as well.

Let me know what you think.

Thanks,

Rich
 
Woops:

Here's the perl script code:

#!/usr/bin/perl -w
use strict;
use CGI qw:)standard);
my $upname10="selector10.txt";
my $upname11="selector11.txt";
my $upname12="selector12.txt";

open (File12, ">$upname12" || die "Error opening file $upname12");
print "Content-type: text/html\n\n";
print"<header>";
print<<DDPENWE1;
<title> crates test</title>

<SCRIPT LANGUAGE="JavaScript">
SCPath = "/cgi-bin/SoftCart.exe";
config = "scstore";
if (location.pathname.substring(0,SCPath.length)!= SCPath) {
window.location.replace(SCPath + location.pathname + "?E+" + config);
}
var B=0;
var BC=0;
var A=0;
var Ctot=0;
var colorchange=0;
var sku= "1";
var b1=b2=b3=b4=b5=b6=b7=0;
var session="+%%softcart.sessionid%%";
var quest="?L";
config1= "+scstore";
CartQ=new Array(100);
var prodtotal = 0;

</Script>
</head>
DDPENWE1
print File12 "Checking,";

print File12 "checking,";

print File12 "checking the cell structure,";

print File12 "Just a scene from Annie Hall, no definitely Sleeper!";
print File12 "%%product(99901BB).micro_description%%";
close (File12);

my $description = "%%product(99901BB).micro_description%%";


open (File10, ">$upname10" || die "Error opening file $upname10");
print File10 "check this out now dude2222333xxxxxxxxxxxxxxx3322222225555555555555555555555555555555522 Why does this print into the file and not the next line";
print File10 "So, now you think you're working!!!!";
print "Below is the description of SKU 99901BB that has been properly interpreted by SoftCart:<br><br>";
print "<b>%%product(99901BB).micro_description%%</b>";
close (File10);
open (File11, ">$upname11" || die "Error opening file $upname11");
print File11 "check this out now dude11111111111112222222222222222222255555555555511111111";
print File11 "\n\nwell, we're waiting!!!!!!!!!!!!!!!!!!";

print File11 "\n\n oh, now we're cooking with gas!!!\n\n";
print File11 $description;
print File11 "%%product(99901BB).micro_description%%";
close (File11);
 

I'm no perl expert, so cannot be sure exactly what the output is. Why don't you just show us the output from the perl file? It's what I've been hinting at all along!

That aside, "<title> crates test</title>" is NOT valid JS.

Dan

 
This:

<SCRIPT LANGUAGE="JavaScript">

and this:

</Script>
</head>

is also not valid JS within as .js file.

Adam
 
Hi Guys:



Still trying to figure it out. Its seems to be choking on the <SCRIPT LANGUAGE="JavaScript">.

Dan, When the <SCRIPT LANGUAGE="JavaScript"> is in the pl script, I don't get anything written to the selector**.txt files. Is this the "output" that you are referring to?

When I remove it, the output of the selector11.txt looks like this:

check this out now 11112222222222222222222255555555555511111111

well, we're waiting!!!!!!!!!!!!!!!!!!

oh, now we're cooking with gas!!!

%%product(99901BB).micro_description%%%%product(99901BB).micro_description%%

As you can see, the script can interpret the softcart tags.



So, when you call a file this way, its always interpreted as .js file??

How do you call pl script, so it can stand on its own...as a perl script...WITHOUT going to a new page, refreshing the page, or opening another browser

Rich
 

How do you call pl script, so it can stand on its own...as a perl script...WITHOUT going to a new page, refreshing the page, or opening another browser

The only way I can think of is to use frames or iframes.

Dan
 
Assuming your perl will return only valid JS and no HTML, you can use this:
Code:
function execPerlJS(url){
  var o=new ActiveXObject("Microsoft.XMLHTTP");
  o.open("GET",url,false); o.send(null);
  eval(o.responseText)
}

Adam
 
Lee, didn't see your post until just now.

Well, yes, kindof. There's no folder call SoftCart.exe but, the way softcart works it parses the pages through the url path. this way is keep the cart and session id intact (it appends it to the url) and can interpret the tags on the page it parses.

The call is really to pl script. once softcart is executed is will always parse the page you navigate to unless you jump outside the url or tell it not to parse the page. Its so quirky but we've been working with it (mostly around it) for a few years and are kind of stuck with it.

Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top