...

View Full Version : Blank Page



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.

Candan
06-22-2010, 03:20 PM
Put your code between [ PHP] [ /PHP] tags, please.



<?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++;

}





?>


Have you tried putting your variables outside of quotes?
echo "<a href='".$link."'>".$name."</a> \t";

Fou-Lu
06-22-2010, 04:31 PM
Enable your error reporting. Chances are, it will complain about your mysql_result.
Move your mysql_close to the end.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum