Jump to content

space in link text problem


samoht

Recommended Posts

Hello,

 

I am having a problem with a link text when ever there is a text that has multiple words.

(e.g. 2 Cor prints out with the white space but when I click on the text the url is printed without the text as 2Cor and so it doesn't find a match)

 

here is my code:

<?php 
if($_GET['book'] == ''){
$books = $wpdb->get_results("
	SELECT book_name 
	FROM {$wpdb->prefix}sb_books_sermons 
	LEFT JOIN {$wpdb->prefix}sb_books ON {$wpdb->prefix}sb_books_sermons.book_name = name 
	GROUP BY book_name 
	ORDER BY {$wpdb->prefix}sb_books.id 
	ASC 
	");

	foreach($books as $book){
		echo '<li><div class="droidlist"><a href="bible/?book='.htmlentities($book->book_name).'">'.$book->book_name.'</a></div></li>'."\n\t";
	}
}

 

Link to comment
Share on other sites

alright,

 

I changed the htmlentities to preg_replace - to search for any spaces and replace with %20  like so:

<?php 
	foreach($books as $book){
		echo '<li><div class="droidlist"><a href="bible/?book='.preg_replace('[\s]', '%20', $book->book_name).'">'.$book->book_name.'</a></div></li>'."\n\t";
	}
}

 

This loos like it should work but again when I click on the link the url removes the %20 and the space and I am back with 2Cor

??

 

 

Link to comment
Share on other sites

ok,

 

I am trying rawurlencode() now and it is writing in the %20

then ON the page reload when I get the variable from the url I am using rawurldecode()

 

but the space is still being removed before I run my query??

 

<?php
if($_GET['book'] == ''){
$books = $wpdb->get_results("
	SELECT book_name 
	FROM {$wpdb->prefix}sb_books_sermons 
	LEFT JOIN {$wpdb->prefix}sb_books ON {$wpdb->prefix}sb_books_sermons.book_name = name 
	GROUP BY book_name 
	ORDER BY {$wpdb->prefix}sb_books.id 
	ASC 
	");

	foreach($books as $book){
		echo '<li><div class="droidlist"><a href="bible/?book='.htmlentities(rawurlencode($book->book_name)).'">'.$book->book_name.'</a></div></li>'."\n\t";
	}
}else {
$book = $wpdb->escape(rawurldecode($_GET['book']));

Link to comment
Share on other sites

So, I got it to work sort of!

 

I removed the relative link and for some reason that worked. So then I tried just shortening the relative link to

<a href="?book='.rawurlencode($book->book_name).'">'

Which also worked. - not sure why adding the /bible/ in front of the query broke it?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.