I'm fairly new to coding, but have managed to create a function that gets all my elements in the database and echos them out in a list. However, I want each element to have an individual anchorpoint so that i can use the "#" in my link to refer to a specific element.
My whole function currently looks like this (Please excuse some strange names as they're in norwegian):
function visAktiveForslagFlestStemmer()
{
echo "<section id='innhold'><h2>Aktive forslag</h2>";
$db = returnerDB();
if(!$db)
{
die("Kunne ikke knytte til databasen");
}
$sql = "SELECT Tittel, Tekst, COUNT(stemme.ForslagID) AS Antall FROM forslag, stemme WHERE stemme.ForslagID = forslag.ForslagID AND forslag.Aktiv = 1 AND forslag.Besvart IS NULL GROUP BY stemme.ForslagID ORDER BY Antall DESC";
$resultat = $db->query($sql);
$i=1;
$index=1;
while ($rad = mysqli_fetch_array($resultat, MYSQLI_ASSOC))
{
echo "<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js'></script>
<script>
$(document).ready(function(){
$('#beskrivelse".$index."').hide();
$('#visSkjulButton".$index."').click(function(){
$('#beskrivelse".$index."').toggle(500, 'swing');
});
});
</script>";
if ($i%2==0)
{
$tall="repeteres";
$ftall="forslag";
$sstall="stemmeOgSosialt";
$stall="stemme";
$sotall="sosialt";
}
else
{
$tall="repeteres2";
$ftall="forslag2";
$sstall="stemmeOgSosialt2";
$stall="stemme2";
$sotall="sosialt2";
}
echo "<a id='anchor".$i."'><div class='".$tall."'><div class='".$ftall."'><p><h3>".$rad["Tittel"]."</h3></p><div id='beskrivelse".$index."'>
<p id='forslagbeskrivelse'>".$rad["Tekst"]."</p></div><button class='btn btn-info' id='visSkjulButton".$index."'>Vis/ Skjul</button></div><div class='".$sstall."'><div class='".$stall."'>
<p><div class='btn btn-primary btn-lg center-block disabled'>".antallStemmer($rad["ForslagID"])."</div></p>
<br><br><div class='btn btn-primary btn-lg center-block'>Avgi Stemme</div></div>
<div class='".$sotall."'><a href='http://facebook.com' class='image1'></a><a href='http://twitter.com' class='image2'></a><a href='http://plus.google.com' class='image3'></a>
<div class='btn btn-warning btn-md' id='rapporterButton'>Rapportér</div></div></div></a>";
$i++;
$index++;
}
mysqli_close($db);
This function is called in a separate page, which is included in my index.php-page. My index.php-page also includes a navigation bar, assigning [mywebpage.com/index.php]?page=1 to the end of the url where the function is being called.
The issue I'm having is that adding for example "#anchor1" to this link does not make my browser window jump to the first (or any) element that this function gets from the database.
Can anyone please pont to where my error lies?