Title: the_permalink Function in mysql query?
Last modified: August 19, 2016

---

# the_permalink Function in mysql query?

 *  [wglassbrook](https://wordpress.org/support/users/wglassbrook/)
 * (@wglassbrook)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/the_permalink-function-in-mysql-query/)
 * I’m trying to inject the_permalink into the url of this query.
 *     ```
       $result = mysql_query("SELECT link_title, link_destination, link_unique_clicks
       FROM wp_tracking_clicks, wp_tracking_links
       WHERE wp_tracking_clicks.link_id = wp_tracking_links.link_id
       AND wp_tracking_clicks.click_refer = 'http://www.url.com'");
   
       while ($row = mysql_fetch_assoc($result)) {
           echo $row['link_title'];
           echo $row['link_destination'];
           echo $row['link_unique_clicks'];
       }
       ```
   
 * The code above works but I need to display this in a template, so I need to get
   the pages current url.
 * All attempts to put the_permalink directly, or into a variable and then pass 
   it to the query fail. I’ve tried both
 * `AND wp_tracking_clicks.click_refer = 'the_permalink'");`
    and
 *     ```
       $link=the_permalink();
       AND wp_tracking_clicks.click_refer = '$link'");
       ```
   
 * I’m sure I’m missing something simple but any help would be greatly appreciated.

The topic ‘the_permalink Function in mysql query?’ is closed to new replies.

## Tags

 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [the_permalink](https://wordpress.org/support/topic-tag/the_permalink/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * 0 replies
 * 1 participant
 * Last reply from: [wglassbrook](https://wordpress.org/support/users/wglassbrook/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/the_permalink-function-in-mysql-query/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
