473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple words in Variable link

1
I have used a mysql query to receive a variable and placed it in a link. The problem is when the variable contains two words it only displays the first in the link.

eg. if the variable contained the words 'tim tam' after the query this is what would happen

THE CODE

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT recent_query, COUNT(*) as total from recent GROUP BY recent_query ORDER BY total DESC LIMIT 5";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<table width=200 border=1><tr><td><b>Most Searched</b></td></tr>";

$i=0;
while ($i < $num) {


$recent_query=mysql_result($result,$i,"recent_quer y");

echo "<tr><td width=200><div style=padding-left:15px;><a href=/search/$recent_query target=_self>$recent_query</a></div></td>
</tr>";


THE RESULT

www.mydomain.com/search/tim

if i can get the resulting link to say www.mydomain.com/search/tim+tam things would work.

Any clues?
Feb 27 '08 #1
2 1717
echo "<tr><td width=200><div style=padding-left:15px;><a href=/search/$recent_query target=_self>$recent_query</a></div></td>
</tr>";
I don't know too much about this, but if i were you, i would try putting curly braces around your variable...

.../search/{$recent_query} target...

that technique has helped me out while inserting into databases, but i'm not sure that it works for url's....
Feb 27 '08 #2
hsriat
1,654 Expert 1GB
I have used a mysql query to receive a variable and placed it in a link. The problem is when the variable contains two words it only displays the first in the link.

eg. if the variable contained the words 'tim tam' after the query this is what would happen

THE CODE

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT recent_query, COUNT(*) as total from recent GROUP BY recent_query ORDER BY total DESC LIMIT 5";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<table width=200 border=1><tr><td><b>Most Searched</b></td></tr>";

$i=0;
while ($i < $num) {


$recent_query=mysql_result($result,$i,"recent_quer y");

echo "<tr><td width=200><div style=padding-left:15px;><a href=/search/$recent_query target=_self>$recent_query</a></div></td>
</tr>";


THE RESULT

www.mydomain.com/search/tim

if i can get the resulting link to say www.mydomain.com/search/tim+tam things would work.

Any clues?
Space is actually an illegal character for URLs, so everything after space is being ignored in your case.

You can filter the string and make it url friendly by this...[php]$filtered_link = urlencode($recent_query);[/php]But if you particularly want to convert space into '+', then do like this...[php]$filtered_link = urlencode(str_replace(" ", "+", $recent_query));[/php]

On the other page, you can use urldecode() to decode the encoded string.
I hope you will get it working now... :)
Feb 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Will | last post by:
I know I am searching using the wrong words because I can't seem to find a simple answer on this. Here's what I want to do. helper.inc <!php var $fileName2; class helper { function...
6
by: Christopher Harrison | last post by:
Is there a way to store an indefinite number of keys in one field and self join them? Imagine, for example, you have a table of users with a "friends" column. Say user 1 is friends with users 9, 7,...
6
by: Don Leverton | last post by:
Hi All, I've got a situation where I am developing an Access 97 app for a client, and am in the "beta testing" stage. I have split the app up, using the DB splitter, into front-end /back-end...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
5
by: Jason | last post by:
Is there a mechanism in VB.NET that allows something like: If myVar In ("A","B","C") Then... The way I'm doing it now is: Select Case myVar Case "A","B","C" Or like this:
4
by: Lee Crabtree | last post by:
I need to shift all of the values in a byte array by more than 8 bits, meaning that values should flow from one byte to another. Since I don't know in advance how many bits will be shifting, I...
11
by: lars.uffmann | last post by:
Easily described problem: Using g++ version 3.3.5 under suse 9.3, bla.h: ----------- #ifndef myTEST #define myTEST ZFSInt test; #endif
14
by: dl | last post by:
I have two classes, say A and B, both having a data member 'int n'; private in A, public in B. When I derive class C from both public A and public B, B::n should be visible to C while A::n...
4
by: henry | last post by:
Folks: As a follow-up to my recent posts, I want to ask some more general questions about multiple instances of a CSS link in a page as seen by browsers due to server-side file inclusion. Let...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.