I want to get a link to my php web page from a mysql (bibliographic) database. This is so that all books can have valid links on both local and remote web pages.
I think the only way is to use javascript. In fact the following code works for a single static page (of course the $intellectualia php variable is already defined and is different for local and remote).
<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 with php I couldn’t get the expected result.
This code doesn’t work:
Omit the whole mysql query (and some useless lines).
$result = mysqli_query($db, $query);
echo "<table>";
while ($row = mysqli_fetch_array($result))
{ $href = "https://www.sitepoint.com/community/t/dynamic-link-from-mysql/$row[href]";
$link = "onclick="https://www.sitepoint.com/community/t/dynamic-link-from-mysql/$row[href]"";
if($href != '') {echo "<td><a href="" $link>read</a></td>";}
echo "</tr>"; }
echo "</table>";
In my mysql data I set a row with this content ( href
digit):
location.href=intellectualia+'/mypath/myfile.php';return false;
The resulting html source code (which of course doesn’t work) is:
<a href="" onclick='location.href=intellectualia+'/mypath/myfile.php';return false;'>read</a>
what should i change?
thank you!
Presumably this (pure php, no js) code could work remotely, such as it works locally.
$link = "$intellectualia/$href";
if($href != '') {echo "<td><a href="https://www.sitepoint.com/community/t/dynamic-link-from-mysql/$link">leggi</a></td>";}
And in mysql I put just the path after $intellectualia.
Sure it works.sorry to bother you
1 like