whatg
06-22-2010, 11:59 AM
Thought I would make a simple site map by getting info from sql table. Seemed to work but the link keeps directing people to the same page. The name of the link changes so don't know whats going on!!
Here's the code:
<?php
//set variables to connect
$host='localhost';
$user='user';
$pass='password';
$db='database';
//connect to mysql
mysql_connect($host,$user,$pass);
@mysql_select_db($db) or die( "Unable to select database");
$query="SELECT * FROM site_map";
$result=mysql_query($query);
if (!$result){
die("Query error! text $query<br> error is".mysql_error());
}
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while($i<$num){
$name=mysql_result($result,$i,"name");
$link=mysql_result($result,$i,"link");
echo "<a href='$link'>$name</a> \t";
$i++;
}
?>
I have a feeling I'm doing something wrong with this:
echo "<a href='$link'>$name</a> \t";
am I using quotes correctly?
Thanks.
Here's the code:
<?php
//set variables to connect
$host='localhost';
$user='user';
$pass='password';
$db='database';
//connect to mysql
mysql_connect($host,$user,$pass);
@mysql_select_db($db) or die( "Unable to select database");
$query="SELECT * FROM site_map";
$result=mysql_query($query);
if (!$result){
die("Query error! text $query<br> error is".mysql_error());
}
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while($i<$num){
$name=mysql_result($result,$i,"name");
$link=mysql_result($result,$i,"link");
echo "<a href='$link'>$name</a> \t";
$i++;
}
?>
I have a feeling I'm doing something wrong with this:
echo "<a href='$link'>$name</a> \t";
am I using quotes correctly?
Thanks.