Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2013
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    hyper link using php

    I am trying to create a hyper link that will link to the id number of the sql item for every link.

    example:
    im trying to make the "id" in a sql query link with the same number as the id
    so like id = 1
    create a hyper link that would make it localhost/?page=1
    id = 2
    localhost/?page=2
    and so on
    but more complicated like a product number 4567-2443
    so it would be localhost/?page=4567-2443

    The goal is I will have 28,000 items in a table split by categories. when i click the product id i want to link to its page which will always be www.yourdomain.com/?product=<product id>

    any suggestions help. This is the code I have so far to display the table and pagination.

    PHP Code:
     <?php
        
        $link 
    mysql_connect(
      
    ':/Applications/MAMP/tmp/mysql/mysql.sock',
      
    'root',
      
    'root'
    );
        
    mysql_select_db('products');
        
        if (!
    $link){
        echo 
    "Could not connect to database" mysql_error();
        exit();
        }

        
    $db_name "products";
        if (!
    mysql_select_db($db_name$link)){
        die (
    "Could not select database" mysql_error());
        }

        
        
    $per_page 2;
        
        
    $pages_query mysql_query("SELECT COUNT(`id`) FROM `beans`");
        
    $pages ceil (mysql_result($pages_query0) / $per_page);
        
        
    $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
        
    $start = ($page 1) * $per_page;
        
        
    $id $query_row['id'];
        
        
    $query mysql_query("SELECT * FROM `beans` LIMIT $start, $per_page");
        while (
    $query_row mysql_fetch_assoc($query)) {
            echo 
    '<p>'$query_row['id'] ,$query_row['name'] ,'</p>';
            
        }
        
        if (
    $pages >= 1) {
            for (
    $x 1$x <= $pages$x++) {
                echo 
    '<a href="?page=' $x '">' $x '</a> ';
            }
            
        }
        
    ?>

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    just replace

    echo '<p>', $query_row['id'] ,$query_row['name'] ,'</p>';

    with your link
    eg...

    PHP Code:
    echo '<a href="www.yourdomain.com/?product=' $query_row['id'] . '">' $query_row['name'] . '</a> '
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    wlf
    wlf is offline
    New Coder
    Join Date
    Aug 2012
    Posts
    61
    Thanks
    0
    Thanked 2 Times in 2 Posts
    @ahaberman25
    mysql extension is deprecated and will be removed in the future.
    You should start using mysqli http://php.net/manual/en/book.mysqli.php

    Most functions' names are the same ... you just need to replace mysql_ with mysqli_


  •  

    Posting Permissions

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