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>";
	}

Recommended Answers

All 9 Replies

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 ;))

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.

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.

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.

So is it sorted now? You can see what you need to do?

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>

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?

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.