Can anyone see where im going wrong with this code I keep hitting a brick wall with it.
Its doing my head in. I think its more the sql code, It keeps showing all data instead of just showing the data based on the user_id which should be limited to one set of data. Any help would be much appreciated :)

function get_agency_profile($id = '') {
		
		if($id != ""):
			$id = mysql_real_escape_string($id);
			$sql = "
		SELECT p.cname, p.email, p.work_landline, p.mobile, p.door_no, p.street, p.town, p.county, p.country, 
		p.postcode, p.website, p.aimage, p.intro, p.id 
		FROM profile p INNER JOIN users u ON u.id=p.user_id 
		WHERE user_id = '$id'";	
		
			else:
			$sql = "
		SELECT p.cname, p.email, p.work_landline, p.mobile, p.door_no, p.street, p.town, p.county, p.country, 
		p.postcode, p.website, p.aimage, p.intro, p.id 
		FROM profile p INNER JOIN users u ON u.id=p.user_id ORDER BY user_id DESC"; 
		endif;
		
		$res = mysql_query($sql) or die(mysql_error());
		
		if(mysql_num_rows($res) != 0):
			while($row = mysql_fetch_assoc($res)) {
				
				echo ' <br /> ';
				echo ' ' . $row['id'] . ' ';
				echo ' <br /> ';
				echo ' ' . $row['cname'] . ' ';
				echo ' <br /> ';
				echo ' ' . $row['email'] . ' ';
			}
		else:
			echo '<p>Uh Oh!, this doesn\'t exist!</p>';
		endif;
		
		
	}

You have assingned a null value for $id in function get_agency_profile($id = '')
After the if condition fails, then executing the else statement. Please check, this may be the problem.. May be i am also wrong. Check it and let me know if any probs.

No still no go, At the moment it just runns and loops every item in the data base wich is echo-ing 6 times rather than just once I feel this maybe an SQL prob but I can't see any problem with it and I have tried everything I can think of, its really anoying. grrr

Now use mysql_fetch_array() in case of using
while($row = mysql_fetch_assoc($res))
Check it and let me know if any probs...

Member Avatar
diafol

THis suggests that you're not passing an id value to the function in the first place. Just for testing, add this line as a first line in your function:

$id = 1;

Set the var to any id value you know is present in the DB. See if it now works.

If I set a value inside it works but if dont then it won't so I guess not value is being passed on which is wierd as it works with everything else I have done so far.

function get_agency_profile($id='2') {
		
		if($id != ""):
		$id = mysql_real_escape_string($id);
		$sql = "SELECT * FROM profile WHERE id = '$id'"; 
		else:
		$sql = '
		SELECT p.cname, p.email, p.id, p.user_id 
		FROM profile p INNER JOIN users u ON p.user_id=u.id 
		WHERE p.user_id=user_id ORDER BY id ASC';  
		endif;
		$res = mysql_query($sql) or die(mysql_error()); 
		if(mysql_num_rows($res) != 0):
			while($row = mysql_fetch_assoc($res)) {
				
				$id = 1;
				echo ' <br /> ';
				echo ' ' . $row['user_id'] . ' ';
				echo ' <br /> ';
				echo ' ' . $row['cname'] . ' ';
				echo ' <br /> ';
				echo ' ' . $row['email'] . ' ';
			}
		else:
			echo '<p>Uh Oh!, this doesn\'t exist!</p>';
		endif;	
	}

The code that should pass the value is:

<?php 
require_once 'class/paginator.class.php'; 
include 'class/class.php';
include 'db_inc/obj.php';



$result = mysql_query("SELECT COUNT(*) FROM profile WHERE id"); 
while($num_rows = mysql_fetch_array($result))
  {	
	$pages = new Paginator;  
    $pages->items_total = $num_rows[0];  
    $pages->mid_range = 9;  
    $pages->paginate();  

echo '<span style="margin-left:25px"> ' . $pages->display_jump_menu() . $pages->display_items_per_page() . '</span>';  

	if(isset($_GET['id'])):
		$obj->get_pagination($_GET['id']);
	else:
		$obj->get_pagination();
	endif;
	
	
    echo $pages->display_pages();  
  }
?>

The get function call

if(isset($_GET['id'])):
		$obj->get_agency_profile($_GET['id']);
	else:
		$obj->get_agency_profile();
	endif;

Does any thing look odd with the code

Soz I missed one out

function get_pagination($id = '') {
		
		if($id != ""):
			$id = mysql_real_escape_string($id);
			$sql = "SELECT COUNT(*) FROM profile WHERE id = '$id'";	
			else:
			$sql = "SELECT p.cname, p.intro, p.aimage, p.id, p.user_id  
				   FROM profile p INNER JOIN users u ON u.id=p.user_id != '' ORDER BY p.id ASC $pages->limit";
		endif;
		
		$res = mysql_query($sql) or die(mysql_error());
		
		if(mysql_num_rows($res) != 0):
			while($row = mysql_fetch_assoc($res)) {
	
	echo "<br />";
	$user_id = $row['user_id'];
	$cname = $row['cname'];
	
	
	$intro = $row['intro'];
	$aimage = '<a href="page.php?='. $row['id'] .'"><img src="members/images/'. $row['aimage'] .' " style="width:100px; height:165px; border:1px solid #000;" /></a>';
	
	echo $user_id;
	echo "<br />";
	echo $cname;
	echo "<br />";
	echo $intro;
	echo "<br />";
	echo $aimage;
	echo "<br />";
	echo "<br /><br /><hr /><br />";	
			}
		else:
			echo '<p>Uh Oh!, this doesn\'t exist!</p>';
		endif;
	}

Finally fixed the problem at last 8 hours later lol what headache