Dynamic link from mysql

I would like to get a link from a mysql (bibliographic) database to my php webpage. So that I could have a valid link for every book both in local and in remote web pages.
I guess that the only way should be to use javascript. And indeed the following code works (of course $intellectualia php variable is already defined, different in local and in remote), in a single static page:

<script>
     var intellectualia = "<?php echo "$intellectualia"; ?>";
</script>
<p>Link to <a href="" onclick="location.href=intellectualia+'/mypath/myfilephp';return false;">go to myfile</a></p>

But using mysql in php I didn’t manage to get the expected result.
This code doesn’t work:
I omit the whole mysql query (and some useless rows):

$result = mysqli_query($db, $query);
echo "<table>";
while ($row = mysqli_fetch_array($result))
{ $href = "$row[href]";
  $link = "onclick='$row[href]'";
    if($href != '') {echo "<td><a href='' $link>read</a></td>";}
    echo "</tr>"; }
echo "</table>";    

In my mysql data I have set a row with this content (in href column):

location.href=intellectualia+'/mypath/myfile.php';return false;

The resulting html source code (not working, of course) is:

<a href='' onclick='location.href=intellectualia+'/mypath/myfile.php';return false;'>read</a>

What should I change?
Thank you!

Maybe this (pure php, no js) code could works even in remote, such as works in local:

$link = "$intellectualia/$href";
    if($href != '') {echo "<td><a href='$link'>leggi</a></td>";}

and in mysql I put only the path after $intellectualia.

Indeed it works. Sorry for bothering you :blush:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.