Add a hyperlink to each entry of a table from mysqli

116 views Asked by At

I'm trying to add a direct link to the genomic region of each gene on a table generated with mysqli data, but can't figure out the way. The idea is that every gene name has a hyperlink to it's region on a genome browser.

The problem comes when I have to generate the link dynamically for each gene depending on the gene selected by the user.

I've tried this:

echo '<td><a href="http://genome.ucsc.edu/cgi-bin/hgTracks?"'.urlencode($genome.$row['name2'])'>'$row['name2']'</a></td>';

$genome is the par of the url specific for each species and assembly, and $row['name2'] is the name of each gene.

2

There are 2 answers

0
chop62 On BEST ANSWER

You had your quote double quote in wrong location if there are additional problems will need more info

    // Yours
echo '<td><a href="http://genome.ucsc.edu/cgi-bin/hgTracks?"'.urlencode($genome.$row['name2'])'>'$row['name2']'</a></td>'
// Fixed Quote
echo '<td><a href="http://genome.ucsc.edu/cgi-bin/hgTracks?'.urlencode($genome.$row['name2'])'">'$row['name2']'</a></td>';
0
Georges O. On

I complete my previous comment with some advice - maybe this is the answer to your question.

1. How to use echo

You should separate each part of the echo function by a separator. The common separator is the coma ,. Of course, you can also concatenate with a dot .

echo 'a', 'b', 'c', $var, 'con'ca' . 'tenated';

Tips: use the coma only for echo instruction. It's faster :)

2. Issues on your code

If I take your generated output, you should have something like this - with **cho* corrections:

<td><a href="http://genome.ucsc.edu/cgi-bin/hgTracks?"%20gen%20The+name>The name</a><td>

As you can see, the link is http://genome.ucsc.edu/cgi-bin/hgTracks?. The content after the " is ignored.

Solution: Move to the dynamic part of the link, at the correct place :)