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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 >

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.