July 19th, 2001, 05:59 AM
-
database connection in a javascript
I have the following link that belongs to a javascript:-
<A target="_new" href="http://www.othersite.com" onClick="return frameBranding('http://www.othersite.com', 'page.htm', 'rows');">
however I want to insert a link from a mysql database instead of http://www.othersite.com, with the following:-
<?php
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("ISS",$db);
$result = mysql_query("SELECT link FROM table WHERE id = '$id'",$db);
do {
if ($myrow[0] != "") {
echo "$myrow[0]";
}
} while ($myrow = mysql_fetch_array($result));
?>
what's the best way to go about this.
July 19th, 2001, 06:13 AM
-
cant get u.
hey friend,
can u explain again what u want to accomplish ?
i dont understand .
do u want to change the parameter passed to framebranding function ?? [ i can guess only that but i m not sure ]
so plz explain.
jd
_____________________________
d.k.jariwala (JD)
~ simple thought, simple act ~
I blog @
http://jdk.phpkid.org
July 19th, 2001, 06:22 AM
-
I'm not sure what you are trying to do here..but i assume that you are trying to get the following...
PHP Code:
<?php
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("ISS",$db);
$result = mysql_query("SELECT link FROM table WHERE id = '$id'",$db);
if(mysql_num_rows($result)>0){
// record is there in db
while ($myrow = mysql_fetch_array($result)){
if (!empty($myrow["link"])) {
echo "<A target=\"_new\" href=\"".$myrow["link"] ."\" onClick=\"return frameBranding('".$myrow["link"]."', 'page.htm', 'rows');\">\n";
//print that java script here..
}
}
?>
July 19th, 2001, 06:24 AM
-
basically the javacript, is a frame branding script, where a user clicks on a link and the link takes them to the site they want to go to but the site is displayed in a frameset, like what lycos does and other portals.
so the user click on a hyperlink as normal:-
<A target="_new" href="http://www.othersite.com" onClick="return frameBranding('http://www.othersite.com', 'page.htm', 'rows');">
However the link (or the site that it's going to) is constantly changing and is dependant to the page that they're on.
so that's why I need to connect it to a database. So intead of
"href="http://www.othersite.com" I want to it to be something like:-
href="<?php ......get link from mysql database.....?> "
July 19th, 2001, 06:27 AM
-
I have a script that does exactly what you want on my site..
With a little customisation I'm sure it will do what you want..
July 19th, 2001, 06:35 AM
-
so that's why I need to connect it to a database. So intead of
"href="http://www.othersite.com" I want to it to be something like:-
href="<?php ......get link from mysql database.....?> "
i think you may try what i have written earlier...
July 19th, 2001, 08:30 AM
-
are you sure that's right Shiju
I'm getting parse errors
July 19th, 2001, 08:40 AM
-
Make the last bit of the script
}
}
?>
look like
}
}
}
?>