Dynamic hyperlink from mysql – JavaScript – SitePoint Boards

I want to get a hyperlink from a mysql (bibliographic) database to my php webpage. In order that I might have a sound hyperlink for each ebook each in native and in distant net pages.
I assume that the one approach ought to be to make use of javascript. And certainly the next code works (after all $intellectualia php variable is already outlined, completely different in native and in distant), in a single static web page:

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

However utilizing mysql in php I didn’t handle to get the anticipated consequence.
This code doesn’t work:
I omit the entire mysql question (and a few ineffective rows):

$consequence = mysqli_query($db, $question);
echo "<desk>";
whereas ($row = mysqli_fetch_array($consequence))
{ $href = "https://www.sitepoint.com/group/t/dynamic-link-from-mysql/$row[href]";
  $hyperlink = "onclick="https://www.sitepoint.com/group/t/dynamic-link-from-mysql/$row[href]"";
    if($href != '') {echo "<td><a href="" $hyperlink>learn</a></td>";}
    echo "</tr>"; }
echo "</desk>";    

In my mysql knowledge I’ve set a row with this content material (in href column):

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

The ensuing html supply code (not working, after all) is:

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

What ought to I modify?

Perhaps this (pure php, no js) code might works even in distant, resembling works in native:

$hyperlink = "$intellectualia/$href";
    if($href != '') {echo "<td><a href="https://www.sitepoint.com/group/t/dynamic-link-from-mysql/$hyperlink">leggi</a></td>";}

and in mysql I put solely the trail after $intellectualia.

Certainly it really works. Sorry for bothering you :blush:

1 Like

Source link

Add a Comment

Your email address will not be published. Required fields are marked *