Not sure if its the sql query or what, but I have a pagination class and a function I am trying to put together if some one would be able to point be in the wright direction it will be very appreciated. :)

The following is the function which I am trying to get results from, based on a count of id's from a table called (profile) then joined by a row (user_id) to a table called (users) I then need to display certain rows from both tables and use the $id variable to use as an anchor so it can be used in a href link.

// Function for pagination
function get_cprofile($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 
		FROM profile p INNER JOIN users u ON u.id=p.user_id 
		WHERE 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($num_rows = mysql_fetch_assoc($res)) {
			
	echo "<br />";
	$cname = $row['cname'];
	$intro = $row['intro'];
	$aimage = '<img src="members/images/'. $row['aimage'] .' " style="width:100px; height:165px; border:1px solid #000;" />';
	
	echo $cname;
	echo "<br />";
	echo $intro;
	echo "<br />";
	echo $aimage;
	echo "<br /><br /><hr /><br />";
	
    echo $pages->display_pages();  
		
			}
		else:
			echo '<br /><p>No Profile Details Available! Please Add Some <-link-> </p>';
		endif;
		
		echo '<br />';
	}

This next bit of code calls the function above and objects class from my pagination class.

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

$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_cprofile($_GET['id']);
	else:
		$obj->get_cprofile();
	endif;

All I seem to be getting is the result of nothing to display,


"No Profile Details Available! Please Add Some <-link->"


I just can't get my head around it, I stopped all the sql errors but now the code just seems to skip to their is nothing to display from my else: statement. :(

Recommended Answers

All 3 Replies

well I am a little confused.

For starters what is '$obj'?

also, I see that you are trying to use variables from your function in your other script and use variables from your other script in your function. Unfortunately PHP does not work this way.

from the looks of it 'get_cprofile' is not a function of a class so I would assume making a call like:

$obj->get_cprofile($_GET['id']);

would only need to be

get_cprofile($_GET['id']);

but the more important issue is that the variables '$pages' and '$num_rows' cannot be interchanged between the two scripts. the best way to think about it is anything inside the function is trapped there, unless you return it in the end, and anything outside the function cannot get into it, unless you pass it in as a parameter.

I hope this was helpful.

Thank you thats helped a lot I wasn't to sure if I could not use a function class inside another function. I did manage to get it working but not with a function so I will just use that instead and now I face another problem but trial and error seems the only way at the min, I now think it will be a good idea to plan this thing out on paper as im starting to loose where i am this lol, Thanks for your help very useful.

no problem, good luck. trial and error is a great way to learn.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.