SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast jrwap's Avatar
    Join Date
    Oct 2000
    Location
    NJ
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I am using a script which allows user to submit a url for their site. The url is saved in a MySQL database with other things like site name and description.

    The url is saved in a variable: $url. Now I have the urls and sites listed in a page and I want them to open up in a new window when they are clicked.

    Here is some of the code:

    function list_sites($mode='top', $category_id='') {
    global $directory_tablename, $root_category_id, $PHP_SELF, $num_top_sites, $num_new_sites;
    if(!$link_id) $link_id = db_connect($default_dbname);
    if($mode=='top') {
    $order_by_str = 'ORDER BY hit DESC';
    $limit_str = "LIMIT $num_top_sites";
    }
    else {
    $order_by_str = 'ORDER BY registerdate DESC';
    $limit_str = "LIMIT $num_new_sites";
    }
    if($category_id == $root_category_id) $category_str = '1';
    else $category_str = "category_id LIKE '$category_id%'";
    $query = "SELECT url_id, title, url FROM $directory_tablename WHERE $category_str AND approved = 1 $order_by_str $limit_str";
    $result = mysql_query($query);
    if(!$result) echo sql_error();
    if(mysql_num_rows($result) > 0) {
    if($mode=='top') echo "Top $num_top_sites Sites<BR>";
    else if($mode=='new') echo "New $num_new_sites Sites<BR>";
    }
    $i = 1;
    while($query_data = mysql_fetch_array($result)) {
    $url_id = $query_data["url_id"];
    $url = "http://" . $query_data["url"];
    $title = $query_data["title"];
    echo " <A HREF=\"$PHP_SELF?action=go_url&url=$url&url_id=$url_id\">$i. $title</A><BR>\n";
    $i++;
    }
    }

    This displays the sites. Now when they are clicked on $action = go_url which executes the go_url function:

    function go_url() {
    global $default_dbname, $directory_tablename;
    global $url_id, $url;
    if(isset($url_id) && isset($url)) {
    if(!$link_id) $link_id = db_connect($default_dbname);
    $result = mysql_query("UPDATE $directory_tablename SET hit = hit + 1 WHERE url_id=$url_id");
    if(!$result) error_message(sql_error());
    rock("Location: $url");
    }
    }

    Now the function rock should open it up in a new window but it doesnt.

    function rock() {
    global $new_window_width, $new_window_height;
    ?>
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    function open_window(url) {
    var NEW_WIN = null;

    NEW_WIN = window.open ("","RecordViewer","toolbar=no,width="+<?php echo $new_window_width ?>+",height="+<?php echo $new_window_height ?>+",directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
    NEW_WIN.location.href = url;
    }
    //-->
    </SCRIPT>
    <?php
    }

    What is wrong here?
    Thanks for your help,

    -JRW

  2. #2
    SitePoint Enthusiast jrwap's Avatar
    Join Date
    Oct 2000
    Location
    NJ
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The page that its being called in starts off with an include statemnet for the .inc file. It simply has a switch statment for $action which calls different functions. The only one that isnt working is the go_url function.

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Two problems I see:

    rock("Location: $url");

    Your rock() function isn't declared to take a parameter. It looks like you only half changed an old call to header().

    function open_window(url) {

    What calls this JavaScript function?
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  4. #4
    SitePoint Enthusiast jrwap's Avatar
    Join Date
    Oct 2000
    Location
    NJ
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are correct.... it was a header() function..... I just couldn't keep track of all my chandes so I renamed it.

    I'm not too sure what calls it. Maybe that is the problem. Im kinda new at this so it is probably something stupid.

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Then let me propose the following changes:

    Code:
    rock($url);
    and

    Code:
    function rock($url) { 
    global $new_window_width, $new_window_height; 
    ?> 
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> 
    <!-- 
    function open_window(url) { 
    var NEW_WIN = null; 
    
    NEW_WIN = window.open ("","RecordViewer","toolbar=no,width="+<?php echo $new_window_width ?>+",height="+<?php echo $new_window_height ?>+",directories=no,status=no,scrollbars=yes,resize=no,menubar=no"); 
    NEW_WIN.location.href = url; 
    } 
    
    open_window('<?=$url?>');
    //--> 
    </SCRIPT>
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •