Guys can anybody help me, I'm trying to fetch records from my database and use those records as links, my codes work but the first two records are not converted into a hyperlink, why it happened? what is wrong in my codes?

<?php 
		$username = $_SESSION['username'];
		$query = "SELECT * FROM tbldoctor_info";
		$result = mysql_query($query) or die(mysql_error());
		$record = mysql_num_rows($result);
		// check if their are records found
?>
<table cellspacing="2px" cellpadding="2px" align="center">
<tr><td><h3>Name</h3></td><td><h3>Specialty</h3></td></tr>
<?php

		if ($record!=0)
		{
			while ($row = mysql_fetch_row($result))
			{
				//print_r($result);
				$dname= $row[2].$space.$row[3].$space.$row[1];
				$dspecialty= $row[7];
?>
<tr>
<td width="250px"><?php echo '<a href="ProfileDoctor.php" style="color:#33FF00;">$dname</a>'; ?></td>
<td width="250px"><?php echo $dspecialty; ?></td>
</tr>
<?php
			}
		}
		else
		{
			die("No records to display");
		}
mysql_close();
?>
</table>
<?php 

echo "<a href='ProfileDoctor.php' style='color:#33FF00;'>$dname</a>"; ?>

as above,
+ a parameter passed to profiledoctor.php to indicate which row of the indentical table links was clicked ?
given the unknown table structure, there is some unique identifier, I hope echo "<a href='ProfileDoctor.php?ID=unique_identifier'>$dname</a>"; //_there_could_be_100_Dr_John_smith get the styles out of html into css where they belong, makes maintainence simpler later

Please allow me to add something. Since that the php closing tag is already in placed .. shown below.

?>
<tr>
<td width="250px"><?php echo '<a href="ProfileDoctor.php" style="color:#33FF00;">$dname</a>'; ?></td>

it can be rewritten as this

?>
<tr>
<td width="250px"><a href="ProfileDoctor.php" style="color:#33FF00;"><?php echo $dname; ?></a></td>

Still the same as above, remove the inline css and move it to external css file..

Veedoo:
yeah, its real messy code,

<?php $username = $_SESSION['username'];
$query = "SELECT * FROM tbldoctor_info";
$result = mysql_query($query) or die(mysql_error());
$record = mysql_num_rows($result);
if($record!=0) { echo '<table cellspacing="2px" cellpadding="2px" align="center"><tr><td width="250px"><h3>Name</h3></td><td width="250px"><h3>Specialty</h3></td></tr>';
while ($row = mysql_fetch_row($result)) { $dname= $row[2].' '.$row[3].' '.$row[1];
echo "<tr><td><a href='ProfileDoctor.php?ID=$row[0]'> $dname </a></td><td> $row[7] </td></tr>"; }
echo '</table>'; } 
else { die("No records to display"); }
mysql_close(); ?>

again assuming there is a unique id row[0]

Member Avatar
diafol

I think you need to brace out array item variable:

echo "<tr><td><a href='ProfileDoctor.php?ID={$row[0]}'> $dname </a></td><td> {$row[7]} </td></tr>"; }