SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot p2ranger's Avatar
    Join Date
    Jan 2001
    Location
    Colorado, USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still having problems with my webring program I'm working on.
    When I choose next from the site at the end of the ring, I want it to go back to the 1st site. Right now, it just goes into a loop and keeps reloading the php page that the information is submitted to.

    Also, the way I have it go to the pages is by insterting meta http-equiv="refresh" content="0;URL=http://blahblahblah" where the URL is the one for the page to go to. Doing this it has to show a blank page for a second. Is there a way around this where it won't have to show a blank page? It just runs the php program and shows the next page.

    Any help would be greatly appreciated. Thanks
    Jason
    ><>

    Code:
     
    <?php
    
    // connect to the database server
    $dbcnx = @mysql_connect("localhost", "login", "pass");
    if (!$dbcnx)
    {
        echo( "<p>Unable to connect to the database server at this time.</p>");
        exit();
    }
    
    // select the philring database
    if (! @mysql_select_db("philring") )
    {
        echo( "<p>Unable to conect to the database at this time</p>");
        exit();
    
    }
    
    //get the number of rows in the table (gets the numer of
    //sites in the ring)
    
    $sql = mysql_query("SELECT COUNT(*) AS rowCount FROM philring");
    $number_of_sites = mysql_result($sql, 0);
    
    // get the highest active site number
    $sql = mysql_query("select MAX(id) from philring where status = 1");
    $max_site = mysql_result($sql, 0);
    
    //check for where ring needs to go
    
    if(@$direction == "skip_next" and $id == $max_site)
        {
            // if skip next is selected at the end of the ring
            // then go back to site 1 and choose the next site
            $sql = "SELECT url
                    FROM philring
                    WHERE id > 1
                    AND status = 1
                    ORDER BY id
                    LIMIT 1";
        }
    
    if(@$direction == "skip_next" and $id <> $max_site)
    {
        //if skip next is selected from anywhere but the end of the ring
        // increase the id by one and go to the next directions
        $id++;
        $direction = "next";
    }
    
    if(@$direction == "skip_previous" and $id == 1)
        {
            // if skip previous is selected from site 1 then go to the end of the
            // ring and go to the previous directions
            $id=$max_site;
            $direction = "previous";
        }
    
    if(@$direction == "skip_previous" and $id <> 1)
    {
        // if skip previous is selected from anywhere but the beginning of the ring
        // then decrease id by 1 and go to the previous directions
        $id--;
        $direction= "previous";
    }
    
    if(@$direction == "next" and $id == "max_site")
    {
        // if next is selected from the end of the end of the ring, return to
        // the beginning site 1
        $sql = "SELECT url
                FROM philring
                WHERE id = 1";
    }
    
    if (@$direction == "next" and $id <> "max_site")
    {
    
         //if next is selected from anywhere but the end of the ring, go to the
         //next active site
    
        $sql = "SELECT url
                FROM philring
                WHERE id > $id
                AND status = 1
                ORDER BY id
                LIMIT 1";
    }
    
    if(@$direction == "previous" and $id == 1)
    {
        //if previous is selected from the first site of the ring, then go to the
        // last active site in the ring
        
        $sql = "SELECT url
               FROM philring
               WHERE id = $max_site";
    }
    
    if (@$direction == "previous" and $id <> 1)
    {
        //if previous is selected from anywhere but the beginning of the ring then
        //go to the previous active site
    
       $sql = "SELECT url
               FROM philring
               WHERE id < $id
               AND status = 1
               ORDER BY id DESC
               LIMIT 1";
    }
    
    if(@$direction == "random")
    {
        // choose a random site from the database
        $sql = "SELECT url
                FROM philring
                where id <> $id
                and status = 1
                ORDER BY RAND()
                LIMIT 1";
    }
    
    
    //slect url and status from database
    
    $result = mysql_query($sql);
    
    $row = mysql_fetch_array($result);
    
    echo("<meta http-equiv=\"refresh\" content=\"0;URL=$row[0]\">");
    
    ?>

  2. #2
    SitePoint Enthusiast poil11's Avatar
    Join Date
    Aug 2000
    Location
    it look me along time to do that...
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    header("Location:$row[0]");
    instead of
    echo("<meta http-equiv=\"refresh\" content="0;URL=$row[0]">");
    should work?
    I will Tell you what is wrong with your website and maybe what you can do to make it better.
    Professional Web Site Reviews ... Usability ...
    Contact Me god@stillsucks.com for more information ...
    look at my other reviews, to see what i have done.

  3. #3
    SitePoint Zealot p2ranger's Avatar
    Join Date
    Jan 2001
    Location
    Colorado, USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, didn't work. Thanks anyway though. It gave me this error when I tried it. Line 155 is where I put it in.

    Warning: Cannot add header information - headers already sent by (output started at d:\apache group\apache\htdocs\jason\philmont\philring\philring.php:5) in d:\apache group\apache\htdocs\jason\philmont\philring\philring.php on line 155

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want to use the "header" function, it has to be the very first thing on the page. It will not work if anything else comes before it. Thats why you got the error about headers already sent.

    Again, I think your problem is merely syntax. the echo function will not work the way that you have it shown here. the following is correct:

    echo "some string of text";

    or:

    echo $someVariableName;

    not:
    echo("some text")

    do not use parens...

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I spoke too soon about the proper use of "echo". You can use parens, but you don't have to. "echo", is a language construct, not a function, and therefore doesn't require them. So the following examples will all work according to php.net:

    echo ("some text");
    echo "some text";
    echo ($variableName);
    echo $variableName;

    as for your meta refresh try:

    echo "<meta http-equiv=\"refresh\" content=\"0;URL=".$row[0]."\">";


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
  •