User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,075 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,118 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1966 | Replies: 9
Reply
Join Date: Mar 2006
Posts: 49
Reputation: lsu420luv is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
lsu420luv lsu420luv is offline Offline
Light Poster

Help need to make a link

  #1  
Oct 17th, 2006
I am new to php and am building a search function for my website. The problem is I cannot seem to make the Aa> tags work to make the link I keep on getting parse error. could someone tell me how to make $title a link. I can pretty much do everything else from there. Thanks in advance.:!:



while ($row = mysql_fetch_array($result))
	{
		echo "<center><table>";
		$count = 1 + $s;
			$title = $row["location"];
			echo "<tr>
						<td>";
							echo $title;
							echo "</td><td>";
							echo "</td></tr>";
			$count++;
		
		echo "</table></center>";
	}
Last edited by lsu420luv : Oct 17th, 2006 at 7:03 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Posts: 214
Reputation: SnowDog is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
SnowDog's Avatar
SnowDog SnowDog is offline Offline
Posting Whiz in Training

Re: need to make a link

  #2  
Oct 17th, 2006
Something like:

echo("<a href=\"mylink.htm\">$title</a>");

(I haven't tested that so I can't guarantee it being typo-free. PHP is unforgiving )
Last edited by SnowDog : Oct 17th, 2006 at 10:37 pm. Reason: Tidying text
Reply With Quote  
Join Date: Mar 2006
Posts: 49
Reputation: lsu420luv is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
lsu420luv lsu420luv is offline Offline
Light Poster

Re: need to make a link

  #3  
Oct 18th, 2006
Originally Posted by SnowDog View Post
Something like:

echo("<a href=\"mylink.htm\">$title</a>");

(I haven't tested that so I can't guarantee it being typo-free. PHP is unforgiving )



Thanks man. The link by the way is created dunamically do I have to use anytthing different to have a variable plug in the value rather than actually using the address.
Reply With Quote  
Join Date: Oct 2006
Posts: 214
Reputation: SnowDog is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
SnowDog's Avatar
SnowDog SnowDog is offline Offline
Posting Whiz in Training

Re: need to make a link

  #4  
Oct 18th, 2006
Well, I assume that each incarnation of 'title' will have a different target url, so what do you think you will have to do for that...?

If we assume that 'title' is also the actual url as well as the link text, then:

echo("<a href=\"$title\">$title</a>");

If the url and the link text are different then you'll need to provide another variable or string of text for each iteration.
Reply With Quote  
Join Date: Mar 2006
Posts: 49
Reputation: lsu420luv is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
lsu420luv lsu420luv is offline Offline
Light Poster

Re: need to make a link

  #5  
Oct 19th, 2006
when the user does the search he/she selects a system to search under. then that is put through a switch statement and the $var variable determines the address i.e. www.foo.bar/nes/roms/ the $title is then put in after from the location field of the table and the hyperlink works. I have it tell me the right location I just have not been able to make it a link. Thanks for all your help. The problem was not the link but making the dynamic table with the link included. I got confused with alll the echos and other punctation marks. Thanks for all your help.
Reply With Quote  
Join Date: Oct 2006
Posts: 214
Reputation: SnowDog is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
SnowDog's Avatar
SnowDog SnowDog is offline Offline
Posting Whiz in Training

Re: need to make a link

  #6  
Oct 19th, 2006
So is it sorted now? You can see what you need to do?
Reply With Quote  
Join Date: Mar 2006
Posts: 49
Reputation: lsu420luv is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
lsu420luv lsu420luv is offline Offline
Light Poster

Re: need to make a link

  #7  
Oct 19th, 2006
It is giving me an error. This is what I entered:

$title = $row["location"];
		echo "<tr>
			<td>";
			echo "<a href="$link$title">$title</a>";
			echo "</td><td>";
			echo "</td></tr>";
			$count++;

IT gives me this error:

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /var/www/web2/web/romSite/process.php on line 123

What am I doing wrong>
Reply With Quote  
Join Date: Oct 2006
Posts: 214
Reputation: SnowDog is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
SnowDog's Avatar
SnowDog SnowDog is offline Offline
Posting Whiz in Training

Re: need to make a link

  #8  
Oct 19th, 2006
You can't use " inside the echo - you have to escape any occurence of " with \", so that line in the middle should be:

echo ("<a href=\"$link$title\">$title</a>");

Otherwise PHP thinks the echo has ended and gets messed up. And you should put ( and ) each end of the echo containing the "s which are part of the syntax.

Same on your other lines - put the ( and ) in. So:

$title = $row["location"];
        echo "<tr><td>";
            echo ("<a href=\"$link$title\">$title</a>)";
            echo ("</td><td>");
            echo ("</td></tr>");
            $count++;

But I'm also a bit confused about $link$title in the anchor tag. What would each variable typically contain in an iteration?
Last edited by SnowDog : Oct 19th, 2006 at 10:04 pm.
Reply With Quote  
Join Date: Mar 2006
Posts: 49
Reputation: lsu420luv is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
lsu420luv lsu420luv is offline Offline
Light Poster

Re: need to make a link

  #9  
Oct 21st, 2006
thanks a lot man. I was wondering what all the wierd characters. I am used to c++. It is a little more plain than this. Shockingly similar though like the switch statement is almost the same as one I built for c++ class. Well thanks. I am really glad you explained why so now I can apply that to other things. Thanks again
Reply With Quote  
Join Date: Aug 2006
Location: India
Posts: 76
Reputation: dss is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dss's Avatar
dss dss is offline Offline
Junior Poster in Training

Solution Re: need to make a link

  #10  
Oct 21st, 2006
Originally Posted by lsu420luv View Post
It is giving me an error. This is what I entered:

 
$title = $row["location"];
        echo "<tr>
            <td>";
            echo "<a href="$link$title">$title</a>";
            echo "</td><td>";
            echo "</td></tr>";
            $count++;
 

IT gives me this error:

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /var/www/web2/web/romSite/process.php on line 123
 

What am I doing wrong>



Hi,
YOu can also use it like

echo "<a href="{$link$title}">{$title}</a>";

Accouding to me when we require a output from a variable between double quotes use "<a href="{$link$title}">{$title}</a>";


Thankyou
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:12 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC