• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Modern AAC] Pages/Injection

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Reaction score
72
Location
Poland
So i want add a injection - Gallery. It would be in Guilds_view

\injections\guild_view\Gallery\

So in the Gallery folder is a injection.php file.

The injection.php file INCLUDES a file in \injections\guild_view\Gallery\files

PHP:
<?php

	// initialization
	$result_array = array();
	$counter = 0;

	@$cid = (int)($_GET['cid']);
	@$pid = (int)($_GET['pid']);

	// Category Listing

	if( empty($cid) && empty($pid) )
	{
		$number_of_categories_in_row = 4;

		$result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
						FROM gallery_category as c
						LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
						GROUP BY c.category_id" );
		while( $row = mysql_fetch_array( $result ) )
		{
			$result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
		}
		mysql_free_result( $result );	

		$result_final = "<tr>\n";

		foreach($result_array as $category_link)
		{
			if($counter == $number_of_categories_in_row)
			{	
				$counter = 1;
				$result_final .= "\n</tr>\n<tr>\n";
			}
			else
			$counter++;

			$result_final .= "\t<td>".$category_link."</td>\n";
		}

		if($counter)
		{
			if($number_of_categories_in_row-$counter)
			$result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\n";

			$result_final .= "</tr>";
		}
	}


	// Thumbnail Listing

	else if( $cid && empty( $pid ) )
	{
		$number_of_thumbs_in_row = 5;

		$result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" );
		$nr = mysql_num_rows( $result );

		if( empty( $nr ) )
		{
			$result_final = "\t<tr><td>No Category found</td></tr>\n";
		}
		else
		{
			while( $row = mysql_fetch_array( $result ) )
			{
				$result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /></a>";
			}
			mysql_free_result( $result );	

			$result_final = "<tr>\n";
	
			foreach($result_array as $thumbnail_link)
			{
				if($counter == $number_of_thumbs_in_row)
				{	
					$counter = 1;
					$result_final .= "\n</tr>\n<tr>\n";
				}
				else
				$counter++;

				$result_final .= "\t<td>".$thumbnail_link."</td>\n";
			}
	
			if($counter)
			{
				if($number_of_photos_in_row-$counter)
			$result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</td>\n";

				$result_final .= "</tr>";
			}
		}
	}

	// Full Size View of Photo
	else if( $pid )
	{
		$result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
		list($photo_caption, $photo_filename) = mysql_fetch_array( $result );
		$nr = mysql_num_rows( $result );
		mysql_free_result( $result );	

		if( empty( $nr ) )
		{
			$result_final = "\t<tr><td>No Photo found</td></tr>\n";
		}
		else
		{
			$result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
			list($category_name) = mysql_fetch_array( $result );
			mysql_free_result( $result );	

			$result_final .= "<tr>\n\t<td>
						<a href='viewgallery.php'>Categories</a> &gt; 
						<a href='viewgallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n";

			$result_final .= "<tr>\n\t<td align='center'>
					<br />
					<img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' />
					<br />
					$photo_caption
					</td>
					</tr>";
		}
	}

// Final Output
echo <<<__HTML_END

<html>
<head>
	<title>Gallery View</title>
</head>
<body>
<table width='100%' border='0' align='center' style='width: 100%;'>
$result_final		
</table>
</body>
</html>

__HTML_END;
?>

As you see

PHP:
$result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";

Im unable to open such a link.. How can i add a page that will display the content?


404 Page Not Found
The page you requested was not found.



Code:
http://127.0.0.1/index.php/guilds/view/viewgallery.php?cid=1
 

Attachments

Last edited:
Guild Controller

PHP:
		/* GALLERY */
		/* Content from Controllers */
	function gallery($view, $id = null, $action = 0)
	{
		echo 'Welcome to the Guild Gallery Page';
		$ots = POT::getInstance();
		$ots->connect(POT::DB_MYSQL, connection());
		$connection = POT::getInstance()->getDBHandle();
		$guild = $ots->createObject('Guild');
		$guild->load($id);
		if(!$guild->isLoaded()) error("Could not find guild.");
		$data['guild'] = $guild;
		/* Content from View file */
		$this->load->view("view_gallery", $data);
		$this->load->model('guilds_model');
		$this->guilds_model->gallery(); 
	}

		/* GALLERY */


Guild Model (fail):eek:

PHP:
	public function gallery() {
	$this->load->database();
	$sql = $this->db->query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                        GROUP BY c.category_id" );
		$ret['amount'] = $sql->num_rows;
		$ret['news'] = $sql->result_array();


        return $ret;  

	}

Can u make me the model of the

PHP:
$sql = $this->db->query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                        GROUP BY c.category_id" );

while( $row = mysql_fetch_array( $result ) )
        {
            $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
        }
        return $result;


Really Thanks!
 
This

$this->load->model('guilds_model');
$this->guilds_model->gallery();

should be before loading view, and you should set it to some variable as it returns values

$data['values'] = $this->guilds_model->gallery();

and when loading view, second argument should be data now within view you will see it as $values.
 
How to make this

PHP:
while( $row = mysql_fetch_array( $result ) )
        {
            $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
        }
        return $result;

as a model :S
 
I made it..

So Model

PHP:
public function gallery() {
	$this->load->database();
	$sql = $this->db->query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                        GROUP BY c.category_id" );
		foreach($sql as $row) {
			$list[] = "$rsow";
		}
		return $list;
	}

Controller

PHP:
$data['list'] = $this->guilds_model->gallery();

But the Model.. Should return me the Count of the rows..

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: rsow

Filename: models/guilds_model.php

Line Number: 22

The error is 7 times.. And its good since there are 7 rows in it.. So how to display the row count?
 
I made it..

So Model

PHP:
public function gallery() {
	$this->load->database();
	$sql = $this->db->query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                        GROUP BY c.category_id" );
		foreach($sql as $row) {
			$list[] = "$rsow";
		}
		return $list;
	}

Controller

PHP:
$data['list'] = $this->guilds_model->gallery();

But the Model.. Should return me the Count of the rows..



The error is 7 times.. And its good since there are 7 rows in it.. So how to display the row count?

After query ->num_rows; to get the count. Where did u declare $rsow ? It's no where.
 
PHP:
public function gallery() {
	$this->load->database();
	$sql = $this->db->query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                        GROUP BY c.category_id" );
						$row = $sql->num_rows;
 foreach($sql as $row) {
            $list[] = "$row";
        }
        return $list;
	}

As you see dont work.. The row "(".$row[2].")" should display (7)..

PHP:
while( $row = mysql_fetch_array( $result ) )
        {
            $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
 
PHP:
public function gallery() {
	$this->load->database();
	$sql = $this->db->query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                        GROUP BY c.category_id" );
						$row = $sql->num_rows;
 foreach($sql as $row) {
            $list[] = "$row";
        }
        return $list;
	}

As you see dont work.. The row "(".$row[2].")" should display (7)..

PHP:
while( $row = mysql_fetch_array( $result ) )
        {
            $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";

I completly don't get it, why are you doing foreach for? You should do result_array() if you want it as array otherwise it's just an object.
 
gallery_model.php:
Code:
	public function gallery($id) {
		$this->load->database();
		$result = array();
                $extra = "";
                if($id) $extra = "WHERE c.category_id = $id";
		$sql = $this->db->query("SELECT c.category_id,c.category_name,COUNT(photo_id) as pcount
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id {$extra}
                        GROUP BY c.category_id")->result();
		foreach($sql as $row) {
			 $result[] = "<a href='viewgallery.php?cid=".$row["category_id"]."'>".$row["category_name"]."</a> "."(".$row['pcount'].")";  
		}
		return $result;
	}
gallery.php
Code:
	public function index($id=1) {
		$this->load->helper("form");
		$this->load->model("gallery_model");

		$data = array();
		$data['gallery'] = @$this->gallery_model->galery($id);
		$this->load->view("gallery_view", $data);
	}

Written on the fly, 10min after I woke up, no testing.
 
gallery_model.php:
Code:
	public function gallery($id) {
		$this->load->database();
		$result = array();
                $extra = "";
                if($id) $extra = "WHERE c.category_id = $id";
		$sql = $this->db->query("SELECT c.category_id,c.category_name,COUNT(photo_id) as pcount
                        FROM gallery_category as c
                        LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id {$extra}
                        GROUP BY c.category_id")->result();
		foreach($sql as $row) {
			 $result[] = "<a href='viewgallery.php?cid=".$row["category_id"]."'>".$row["category_name"]."</a> "."(".$row['pcount'].")";  
		}
		return $result;
	}
gallery.php
Code:
	public function index($id=1) {
		$this->load->helper("form");
		$this->load->model("gallery_model");

		$data = array();
		$data['gallery'] = @$this->gallery_model->galery($id);
		$this->load->view("gallery_view", $data);
	}

Written on the fly, 10min after I woke up, no testing.

As long as I remember result() returns object, return_array() returns array.
 
Dont work :| It should be in all guilds. Like /index.php/guilds/gallery/view/1.. Could you check it again? And rewrite it?

That all guilds have their gallery page
 
Back
Top