Jump to content

[SOLVED] Problems creating a URL with info from a database


mike12255

Recommended Posts

Im grabbing this line from my database:

 

pfd/Order Number.pdf

 

I need to create a url like this:

 

<a href = admin/pfd/Order Number.pdf>Link</a>

 

to do this im using the following PHP code:

 

<?php
		  $sql = "SELECT * FROM catagories";
		  $res = mysql_query($sql) or die (mysql_error());
		  while ($row = mysql_fetch_assoc($res)){
		  //echo "<a href= Admin/".$row['Name'].">".$row['wantedname']."</a><br>";
		  echo "<a href=\"" . urlEncode($row['Name']) . "\">" . $row['wantedname'] . "</a><br >\n";
		  }
		  

		  ?>

 

unfortinatlly this outputs this:

 

<a href="Admin/pfd/Order" number.pdf="">sdfas sdf asdf</a>

 

anyone know how to fix the <a href part?

change it to

echo '<a href="' . urlEncode($row['Name']) . '">' . $row['wantedname'] . '</a><br >\n';

 

you should use ' instead of " when there is no php variables inside the quotes, otherwise PHP is still searching through it in case there is one.

change it to

echo '<a href="' . urlEncode($row['Name']) . '">' . $row['wantedname'] . '</a><br >\n';

 

you should use ' instead of " when there is no php variables inside the quotes, otherwise PHP is still searching through it in case there is one.

However, like that the \n won't parse. The \n must be wrapped in double quotes to parse.

 

Also, urlEncode is just going to change your space to +, which I don't think you want. That's used more for variables and such. So try this:

 

$name = 'pfd/Order Number.pdf';
echo '<a href="admin/' . $name . '">' . $row['wantedname'] . '</a><br >' . "\n";

 

Output: <a href="admin/pfd/Order Number.pdf"></a><br >

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.