Assign Hyperlinks to the Search result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agarwalsrushti
    New Member
    • Feb 2008
    • 63

    Assign Hyperlinks to the Search result

    Hi,
    Ive made a search page. It displays the name of the users which is the result of search. Now i want that if we click on the name it should open another page in which the profile of the user will be displayed. The code that i ve done till now, only works for the last user in the list of users displayed and it also doesnt opens in another window. I think the name of the users should be passed as an array to the account page where profile is displayed. But i was not able to do it. Plz help. Ive given the relevant code below plz let me know what is the problem.

    search.php
    [code=php]
    if($resultnum>0 ) { // Echos out matches if anything was found
    while($info=mys ql_fetch_array( $data)){
    //Print it out to page
    ?><a href="searchacc ount.php">
    <?php
    $_SESSION['username'] = $info['UserName'];
    echo "".$info['UserName'] . " <BR><BR>" ?></a>
    <?php
    }// end of while
    }//end of if
    else{
    echo "There are no results to be displayed for your search";
    }
    [/code]

    searchaccount.p hp
    [code=php]
    $uname = $_SESSION['username'];
    $result1= " SELECT UserName, EmailAddress, FullName FROM usermaster WHERE UserName= '$uname'";
    $data1 = mysql_query($re sult1) or die(mysql_error ());
    [/code]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You should assign the username as a parameter to the url and loop through all user names.
    [php]
    $_select = "SELECT * FROM `tbl_name`";

    while($_row = mysql_fetch_arr ay($_select))
    {
    echo $_row['username'] . " <a href=\"profile. php?id=$_row['username']\">profile</a><br />";
    }
    [/php]
    Hope this helps.

    Comment

    • agarwalsrushti
      New Member
      • Feb 2008
      • 63

      #3
      Thanks.
      I tried uaing the above code but its giving error.

      [code=php]
      while($info=mys ql_fetch_array( $data)){
      //Print it out to page
      echo "".$info['UserName'] ."<a href=\"searchac count.php?id=$i nfo['UserName']\">profile</a><br/>";
      }
      [/code]
      When i used this code it gave me the following error:
      Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs \skill_search\s earch.php on line 181

      Then i removed the inverted commas at the start of echo.
      [code=php]
      while($info=mys ql_fetch_array( $data)){
      //Print it out to page
      echo $info['UserName'] ."<a href=\"searchac count.php?id=$i nfo['UserName']\">profile</a><br/>";
      }
      [/code]
      When i used this code it gave me the following error:
      Parse error: syntax error, unexpected '.' in C:\xampp\htdocs \skill_search\s earch.php on line 181

      Plz let me know how to fix this problem.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Try
        [code=php]
        while($info=mys ql_fetch_array( $data)){
        //Print it out to page
        echo "$info['UserName'] <a href=\"searchac count.php?id=$i nfo['UserName']\">profile</a><br/>";
        }
        [/code]
        When you use an echo with double quotes, variables will be parsed inside it automatically.

        i.e.
        [php]
        echo "this will echo a $_variable";
        echo 'this wont echo a $_variable';
        [/php]

        Comment

        • agarwalsrushti
          New Member
          • Feb 2008
          • 63

          #5
          I tried this now but its still giving me the error.
          Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs \skill_search\s earch.php on line 181

          What could be the reason for this error.
          Plz help

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by agarwalsrushti
            I tried this now but its still giving me the error.
            Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs \skill_search\s earch.php on line 181

            What could be the reason for this error.
            Plz help
            what line is 181?

            regards

            Comment

            • agarwalsrushti
              New Member
              • Feb 2008
              • 63

              #7
              Originally posted by markusn00b
              what line is 181?

              regards
              Thanks the problem got solved. The curly braces were missing which was giving error.
              Thanks a lot.

              [code=php]
              echo "{$info['UserName']} <a href=\"searchac count.php?id={$ info['UserName']}\">profile</a><br/>";
              [/code]

              Can you just let me know how to make each profile open up in a different browser.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                [code=php]
                echo "{$info['UserName']} <a href=\"searchac count.php?id={$ info['UserName']}\" target=\"_blank \">profile</a><br/>";
                [/code]


                Try that

                Comment

                • agarwalsrushti
                  New Member
                  • Feb 2008
                  • 63

                  #9
                  Thanks. It worked out.
                  Thanks a lot.

                  Comment

                  Working...