Title: shortcode implementation issue
Last modified: August 20, 2016

---

# shortcode implementation issue

 *  [nepzap2](https://wordpress.org/support/users/nepzap2/)
 * (@nepzap2)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/shortcode-implementation-issue/)
 * When I use “return” it only returns one row from database but when I use echo
   it returns everything. The only problem is that echo places the shortcode at 
   the top of page not where it should be. Can someone help me out. My code is below.
   Thanks.
 *     ```
       add_shortcode('martinPubs', 'martin_publications'); 
   
       function martin_publications() {  
   
       include "includes/publications_conn.php";
   
       $sql = "SELECT * FROM pubs
               WHERE pi = 'martin' AND (label = 's' || label = 'S')
       	ORDER BY year DESC";
   
       $result = mysql_query($sql);
   
       //echo "<div style='height: 200px; width: 730px; overflow-y: auto;'>";
   
       while ($row = mysql_fetch_assoc($result)) {
   
       	$id = $row['id'];
               $author_1 = $row['author_1'];
       	$author_2 = $row['author_2'];
       	$pages = $row['pages'];
       	$title = $row['title'];
       	$title_secondary = $row['title_secondary'];
       	$volume = $row['volume'];
       	$year = $row['year'];
       	$url = $row['url'];
   
       //if(!(null == $url || "" === $url)){
   
       	return "$author_1, $author_2. $year. <a href='$url' target='blank'>$title</a>. $title_secondary $volume: $pages<br / ><br / >"; 
   
       //}else {
   
       //return "$author_1, $author_2. $year. $title. $title_secondary $volume: $pages<br / ><br / >"; 
   
       //}
       }
   
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/shortcode-implementation-issue/#post-3389462)
 * You must accumulate all the output before returning it.
 * This code is untested, but should be close:
 *     ```
       $out = '';
       while ($row = mysql_fetch_assoc($result)) {
   
       	$id = $row['id'];
               $author_1 = $row['author_1'];
       	$author_2 = $row['author_2'];
       	$pages = $row['pages'];
       	$title = $row['title'];
       	$title_secondary = $row['title_secondary'];
       	$volume = $row['volume'];
       	$year = $row['year'];
       	$url = $row['url'];
   
       	$out .= "$author_1, $author_2. $year. <a href='$url' target='blank'>$title</a>. $title_secondary $volume: $pages<br / ><br / >";
       }
   
       return $out;
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘shortcode implementation issue’ is closed to new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [shortcode issues](https://wordpress.org/support/topic-tag/shortcode-issues/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/shortcode-implementation-issue/#post-3389462)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
