rick88 Posted January 13, 2011 Share Posted January 13, 2011 Hey there. Firstly may I apologise if this is the wrong forum for this question. I wasn't overly sure. I'm currently developing an aplication within php which allows a user to upload a file which is saved to a directory and information on the file which is saved to a databse (including the file name). This information is then displayed in a table along with the directory location concatinated with the file name to provide a file location. My only issue is that being new to PHP I am unsure how to change this address to a workable link using a href. Any help in adapting the below script would be much apreciated. Thanks, Rick. echo "<table border='1'><tr>"; for($fieldIterator = 1; $fieldIterator < $numFields; $fieldIterator++) { echo "<th>".mysql_field_name($result, $fieldIterator)."</th>"; } echo "</tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row[1] . "</td>"; echo "<td>" . $row[2] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Genre'] . "</td>"; echo "<td>" . $row['Category'] . "</td>"; echo "<td>$ref= C:\wamp\www/.$row[imageAddress] </td>"; echo "</tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/224319-imbedding-a-href-within-php/ Share on other sites More sharing options...
denno020 Posted January 13, 2011 Share Posted January 13, 2011 To be able to display a link to the file in question, all you need to do is this: echo '<a href:"' . $row[imageAddress] . '"> Link to File</a>'; Depending on what is stored in $row[imageAddress] will depend what directory information you need to place before it, so like this: echo '<a href:"C:\wamp\www\files\' . $row[imageAddress] . '"> Link to File</a>'; Hopefully that can get you on the right track Denno Quote Link to comment https://forums.phpfreaks.com/topic/224319-imbedding-a-href-within-php/#findComment-1158932 Share on other sites More sharing options...
beegro Posted January 13, 2011 Share Posted January 13, 2011 This area in your code is assigning and echoing back a file system location. echo "<td>$ref= C:\wamp\www/.$row[imageAddress] </td>"; This needs to be transformed into a web URL for a browser to understand where to locate something via and HTTP request. eg. $image_address = $row['ImageAddress']; $image_name = $row['ImageName']; // assuming you have this echo "<td><a href=\"$image_address\">$image_name</a></td>"; Let me know if I'm missing something Quote Link to comment https://forums.phpfreaks.com/topic/224319-imbedding-a-href-within-php/#findComment-1158934 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 Quote your array indices. $row['ImageAddress'] Quote Link to comment https://forums.phpfreaks.com/topic/224319-imbedding-a-href-within-php/#findComment-1158935 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.