Array not working
Posted: Tue Jul 15, 2008 6:34 am
Hello all first time poster, and new to PHP. I'm having some trouble with an array, I'm trying to list several websites (currently all random) that have the same usergroup number as the users from a mysql table but all I'm getting is a blank page. Heres my code:
but it only outputs the HTML:<?php
$query = mysql_connect("*********", "******", "******") or die(mysql_error());
mysql_select_db('******', $query) or die(mysql_error());
session_start();
if(isset($_SESSION['UserON'])) {
// User is logged in!
$conn ="SELECT url FROM links WHERE usergroup = " . $_SESSION['UserON'] . " LIMIT 0,50";
$result = mysql_query($conn,$query);
while($row=mysql_fetch_row($result))
{
$url[] = $row[1];
}
echo "<p>\n";
foreach( $url as $v )
{
echo $v."<br />\n";
}
echo "</p>\n";
} else {
header('location: login.php');
}
mysql_free_result($result);
?>
now if I use the following bit I get an output from the database, but since this is not an array i just get a single url.<p>
<br />
<br />
</p>
any ideas? thanks<?php
$query = mysql_connect("************", "******", "*******") or die(mysql_error());
mysql_select_db('*****', $query) or die(mysql_error());
session_start();
if(isset($_SESSION['UserON'])) {
// User is logged in!
$query = mysql_query("SELECT url FROM links WHERE usergroup = " . $_SESSION['UserON'] . " LIMIT 0,50") or die(mysql_error());
list($url) = mysql_fetch_row($query);
echo $url ;
}
else {
header('location: login2.php');
}
?>