www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Hyper link for my results

  1. #1
    Join Date
    Feb 2012
    Posts
    19

    Hyper link for my results

    I have the following code for a results page from a search form. How do I properly hyperlink the results bearing in mind that different results will have different hyperlinks.

    <?
    // Grab POST data sent from form
    $field = @$_GET['field'] ;
    $find = @$_GET['find'] ;
    $searching = @$_GET['searching'] ;

    //This is only displayed if they have submitted the form
    if ($searching =="yes")
    {
    echo "<h2>Results</h2><p>";

    //If they did not enter a search term we give them an error
    if ($find == "")
    {
    echo "<p>You forgot to enter a search term";
    exit;
    }

    // Otherwise we connect to our Database
    mysql_connect("localhost", "name", "pass") or die(mysql_error());
    mysql_select_db("db_name") or die(mysql_error());

    // We preform a bit of filtering
    $find = strtoupper($find);
    $find = strip_tags($find);
    $find = trim ($find);

    //Now we search for our search term, in the field the user specified
    $data = mysql_query("SELECT documentid,title,category FROM material WHERE upper($field) LIKE'%$find%' Limit 0,1");

    //And we display the results
    while($result = mysql_fetch_array( $data ) )





    {






    echo $result['documentid'];
    echo $result['title'];
    echo $result['category'];
    echo $result['subcategory'];

    echo "<br>";
    echo "<br>";













    }
    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    $anymatches=mysql_num_rows($data);
    if ($anymatches == 0)
    {
    echo "Sorry, but we can not find an entry to match your query<br><br>";
    }

    //And we remind them what they searched for
    echo "<b>Searched For:</b> " .$find;
    }
    // Close the database connection
    mysql_close();
    ?>

  2. #2
    Join Date
    Aug 2012
    Posts
    155
    Firstly, why are you using GET with POST data?
    Secondly, where are you trying to link to or where is the link you want to use coming from as there is nothing in your code?

  3. #3
    Join Date
    Oct 2009
    Posts
    658
    First this is more of a PHP question than a database question.

    From
    PHP Code:
    while($result mysql_fetch_array$data ) ) 

    echo 
    $result['documentid']; 
    echo 
    $result['title']; 
    echo 
    $result['category']; 
    echo 
    $result['subcategory'];

    echo 
    "<br>"
    echo 
    "<br>"


    Do something like

    PHP Code:
    while($result mysql_fetch_array$data ) ) 

    echo 
    "<a href='/mylink/'" $result['documentid'] . ">Text</a>"
    echo 
    $result['title']; 
    echo 
    $result['category']; 
    echo 
    $result['subcategory'];

    echo 
    "<br>"
    echo 
    "<br>"


    Good Luck

    Santos Systems

  4. #4
    Join Date
    Feb 2012
    Posts
    19
    Am truly a novice at this...I hope to one day look back and laugh at my mistakes...until then.. How would I display as a one link the documentid, title, category...etc.? And each document would require it's own unique hyperlink.

  5. #5
    Join Date
    Oct 2009
    Posts
    658
    Quote Originally Posted by tdp View Post
    Am truly a novice at this...I hope to one day look back and laugh at my mistakes...until then.. How would I display as a one link the documentid, title, category...etc.? And each document would require it's own unique hyperlink.
    Give us the format of the link you want.
    Good Luck

    Santos Systems

  6. #6
    Join Date
    Feb 2012
    Posts
    19
    the format??

  7. #7
    Join Date
    Oct 2009
    Posts
    658
    Like

    http://yourdomain/yourscript?did=<documentid>

    We can only tell you how to implement it but you have to tell us what you need. Without that we cannot help you. It is also the same reply simplypixie gave to you.
    Good Luck

    Santos Systems

  8. #8
    Join Date
    Feb 2012
    Posts
    19
    Results

    1Customer Guide to TrashDisposal

    Searched For: CUSTOMER

    Above is my current results page...basically I need "Customer Guide to Trash" to be hyperlinked so that the user can download the document associated with the title.

  9. #9
    Join Date
    Oct 2009
    Posts
    658
    Quote Originally Posted by tdp View Post
    Results

    1Customer Guide to TrashDisposal

    Searched For: CUSTOMER

    Above is my current results page...basically I need "Customer Guide to Trash" to be hyperlinked so that the user can download the document associated with the title.
    We understand that but that doesn't give us the format. Try this

    PHP Code:
    while($result mysql_fetch_array$data ) ) 

          echo 
    "<a href='/mylink/" $result['documentid'] . "'>" $result['title'] . "</a><br /><br />";


    Good Luck

    Santos Systems

  10. #10
    Join Date
    Feb 2012
    Posts
    19
    Yes!!! it works!! My last question..the '/mylink/" do I store the actual link in a variable like
    $mylink="http://www.google.com"; ??

  11. #11
    Join Date
    Oct 2009
    Posts
    658
    It depends on you. It's just a placeholder. You can place it in a variable if you want or directly on the line.
    Good Luck

    Santos Systems

  12. #12
    Join Date
    Feb 2012
    Posts
    19
    Last question...I have over a thousand documents....so in essence I have have to make a link for each and everyone of them as illustrated above?

  13. #13
    Join Date
    Oct 2009
    Posts
    658
    No, you are already looping on your query. Remove the limit 0, 1 and you should be good to go
    Good Luck

    Santos Systems

  14. #14
    Join Date
    Feb 2012
    Posts
    19
    Even though every document has a different link? I assume I just have to declare the various links?

  15. #15
    Join Date
    Oct 2009
    Posts
    658
    Yes. basically you are looping through an array of objects. I suggest reading on Control Loops and Arrays
    Good Luck

    Santos Systems

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles