url variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robojob
Forum Newbie
Posts: 6
Joined: Sun Dec 11, 2005 3:48 pm

url variable

Post by robojob »

Hi,

I have this page where i am getting a url variable to select all records from the database that have a certain catagory assigned to them.

The code that i am using is below but when i view the page it is only showing me the first row in the database with that particular catagory. Any ideas on why this is doing this or any other ways i could go about this task...

Code: Select all

<html> 
<head> 
<title> The Kidlington Directory & Village Life - Online Directory </title> 

<script language="javascript"> 
var win = null; 
function NewWindow(mypage,myname,w,h,scroll){ 
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0; 
TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
settings = 
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable' 
win = window.open(mypage,myname,settings) 
} 

</script> 

</head> 

<?php include ("config.php") ?> 

<? 

   $catagory = $_GET['catagory']; 
   $query = "SELECT * FROM `directory` WHERE `catagory`='$catagory'"; 
   $result = mysql_query( $query ); 
   if( $result && $details = mysql_fetch_object( $result ) ) 
   { 
      $business = $details -> business; 
      $id = $details -> id;     ?> 
        
<link rel="stylesheet" href="stylesheet.css" type="text/css"> 

<body bgcolor="#000099" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> 

<table width="200" border="0" cellspacing="0" cellpadding="0" class="sitestyle" height="21"> 
  <tr>   
    <td height="25">   
      <li> <a href="details.php?id=<? echo "$id";?>" onclick="NewWindow(this.href,'name','400','400','yes');return false"><? echo "$business";?></a> </li> 
    </td><? }?> 
  </tr> 
</table> 
</body> 
</html>
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

change

Code: Select all

$result = mysql_query( $query );
   if( $result && $details = mysql_fetch_object( $result ) )
   {
      $business = $details -> business;
      $id = $details -> id;     ?>
to

Code: Select all

$result = mysql_query( $query ) or die(mysql_error());
   while($details = mysql_fetch_object( $result ) )
   {
      $business = $details -> business;
      $id = $details -> id;     ?>
Post Reply