Hi, I am trying to create a group of html links that are dependant on two arrays. The data of the arrays is populated from a mysql database, here is my code:
<?php
include_once 'title.php';
include_once 'checkuser.php';
if (isset($_GET['view'])) $view = sanitizeString($_GET['view']);
else $view = $user;
$sql = "SELECT id FROM user WHERE user='$view'";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
$id = mysql_result($result, 0);
$sql = "SELECT name from album WHERE user='$id'";
$query = mysql_query($sql) or die("Invalid query: " . mysql_error());
//$name = mysql_result($query, 0);
$sql = "SELECT id from album WHERE user='$id'";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
while($id=mysql_fetch_assoc($result))
{
while($name=mysql_fetch_assoc($query))
{
print "<br />";
print "<br />";
print '<a href="displayalbum.php?id=' . $id['id'] . '">';
print $name['name'];
print '</a>';
print "<br />";
}
}
?>
The current result is all names are printed as a link, but they all have the same id, I have tried other arrangements of the while statements but only get similar results such as:
while($id=mysql_fetch_assoc($result) && $name=mysql_fetch_assoc($query))
{
print "<br />";
print "<br />";
print '<a href="displayalbum.php?id=' . $id['id'] . '">';
print $name['name'];
print '</a>';
print "<br />";
}
This method totally ignored the first part of the while statement and only uses $name
I have also tried:
while($id=mysql_fetch_assoc($result))
{
print "<br />";
print "<br />";
print '<a href="displayalbum.php?id=' . $id['id'] . '">';
while($name=mysql_fetch_assoc($query))
{
print $name['name'];
}
print '</a>';
print "<br />";
}
?>
This provides the opposite result to my original code, it prints all links with different id's but all have the same name.
Hope someone can help me,
Thanks.