I have a table that is something like this:

(table name: sites)

ID----FileName-----FileAddress----About
1----website1-------google.com----Seach engine

How can I make a code in such a way that it can be like:

Display all of the FileName in an alphabetical order on file.php that links to their further information page. i.e FileName=website1 links to /file.php?sites=website1


Now when someone clicks on that /file.php?tablename=FileName

It will show for instance
/file.php?sites=website1

And then in side it, it will show About section.

Hi!

I believe you want something like this:

<?php

// Not Tested!!!

if(isset($_GET['sites'])) {

	$id = (int)$_GET['sites'];
	
	if($id > 0) {

		$sql_about = sprintf("SELECT `FileName`, `About` FROM `sites` WHERE `ID` = %d LIMIT 1;", $id);
    	$qry_about = mysql_query($sql) or die (mysql_error());
    	
    	if(mysql_num_rows($qry_about) == 1) {

			$obj_about = mysql_fetch_object($qry_about);
			
			?>
			
			<fieldset>
				<legend>About <?php echo $obj_about->FileName; ?></legend>
				<p><?php echo $obj_about->About; ?></p>
			</fieldset>
			
			<?
		  mysql_free_result($obj_about);
    	}


	}
	
}


$sql = "SELECT `ID`, `FileName` FROM `sites` ORDER BY `FileName`;";
$qry = mysql_query($sql);

if(mysql_num_rows($qry) > 0) {

	while($obj = mysql_fetch_object($qry)) {

?>

		 <p> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?sites=<?php echo $obj->ID; ?>"><?php echo $obj->FileName; ?></a> </p>

<?php

	}

  mysql_free_result($qry);
}

?>

Or perhaps this:

<?php

// Not Tested!!!

$sql = "SELECT `ID`, `FileName`, `About` FROM `sites` ORDER BY `FileName`;";
$qry = mysql_query($sql);

if(mysql_num_rows($qry) > 0) {

$id = 0;

 if(isset($_GET['sites'])) {

 	$id = (int)$_GET['sites'];

 }

	while($obj = mysql_fetch_object($qry)) {

		if($id > 0) { ?>

			<p> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?sites=<?php echo $obj->ID; ?>"><?php echo $obj->FileName; ?></a> </p>

		<?php } else { ?>

			<p>
 			  <?php echo $obj->FileName; ?></a> <br />
 			  <strong>About:</strong> <?php echo $obj->About; ?>
			</p>

		<?php }

	}

  mysql_free_result($qry);
}

?>

I made it in two different ways, since I was not sure about how you want to do it.

I believe that it would had better presentation if you use JavaScript and make use of display style property to show the details and hidden them, anyway, hope PHP snippets would help you.

This article has been dead for over six months. Start a new discussion instead.