#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    109
    Rep Power
    14

    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.
  2. #2
  3. phpkid ~~~~~~ :o)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Nov 2000
    Location
    NJ, USA
    Posts
    2,534
    Rep Power
    16

    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
  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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..
     
       

     }
    ?>
    SR -
    webshiju.com
    www.lizratechnologies.com

    "The fear of the LORD is the beginning of knowledge..."
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    109
    Rep Power
    14
    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.....?> "
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Australia
    Posts
    10
    Rep Power
    0
    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..
    -=-=-=-=-=-=-=-=-=-=-=-=-
    PHP Scripts n Stuff
    http://www.bcnstech.net/
    -=-=-=-=-=-=-=-=-=-=-=-=-
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    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...
    SR -
    webshiju.com
    www.lizratechnologies.com

    "The fear of the LORD is the beginning of knowledge..."
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    109
    Rep Power
    14
    are you sure that's right Shiju

    I'm getting parse errors
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Australia
    Posts
    10
    Rep Power
    0
    Make the last bit of the script
    }
    }
    ?>
    look like
    }
    }
    }
    ?>
    -=-=-=-=-=-=-=-=-=-=-=-=-
    PHP Scripts n Stuff
    http://www.bcnstech.net/
    -=-=-=-=-=-=-=-=-=-=-=-=-

IMN logo majestic logo threadwatch logo seochat tools logo