Need help with a very simple script

Discussion in 'PHP' started by Realdeals228, Jul 24, 2007.

  1. #1
    Hello,

    Yesterday I wrote a script for a simple stumble exchange site. It allows the user to add their site to a list and then shows them a list of sites to stumble. The random sites are found using:

    while ($numofsite <= $num )
    {
    $fcontents = join ('', file ('stumblesites.txt'));
    $s_con = split("~",$fcontents);
    $site_no = rand(0,(count($s_con)-1));
    print "<a href=$s_con[$site_no]>$s_con[$site_no]</a>";
    print "<br />";
    $numofsite++;
    }

    I want to make it so users don't see their own sites. Both ones entered now and those entered previously. I tried to do this using:

    while ($numofsite <= $num )
    {
    $fcontents = join ('', file ('stumblesites.txt'));
    $ucontents = join ('', file ('users.txt'));
    $s_con = split("~",$fcontents);
    $site_no = rand(0,(count($s_con)-1));
    if("$user" != "$u_con[$site_no]")
    {
    print "<a href=$s_con[$site_no]>$s_con[$site_no]</a>";
    print "<br />";
    $numofsite++;
    }
    }

    Since the site and user who owns it are in the same line in the respective files this seemed like a good idea. However the code never sees $user and $u_con[$site_no] as being equal. $user is a text input from the form.

    Any help would be great. Thanks.
     
    Realdeals228, Jul 24, 2007 IP
  2. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if("$user" != "$u_con[$site_no]")

    Remove the quotes.

    if($user != $u_con[$site_no])

    Quotes are only used to delimit a text string. These are variables.
     
    ecentricNick, Jul 25, 2007 IP
  3. Realdeals228

    Realdeals228 Active Member

    Messages:
    755
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    75
    #3
    I just got it working thanks for the help. I figured it was something small like that.
     
    Realdeals228, Jul 25, 2007 IP