Welcome Guest, Not a member yet? Register   Sign In
image not show up in second page pagination,..
#1

[eluser]newbee[/eluser]
hi guys,.. i need some help here! i want to make simple page that show all produk detail include the image(only url that saved in database) all work in first page but if i click the second page in pagination all image not show up, i dunno why??
here the controller
Code:
class Produk extends Controller
    {
        function Produk()
        {
            parent::controller();
            $this->load->model('Produk_model','',TRUE);
        }
        var $title='produk';
        
        function index()
        {
            $data['title']=$this->title;
            $data['h2_title']='Produk > Catalog';
            $data['main_view']='produk/catalok';
            $data['form_action']=site_url('produk/cart');
            $data['link']=array('all'=>anchor('produk','all',array('class'=>'nonaktif')),'accessories'=>anchor('produk/get_acc','accessories',array('class'=>'aktif')),'disk_drive'=>anchor('produk/get_disk','disk drive',array('class'=>'aktif')),);
            
            $limit=3;
            $uri_segment=3;
            $offset=$this->uri->segment($uri_segment);
            $query=$this->Produk_model->get_all_ten($limit,$offset);
            $produk=$query->result();
            $jumlah=$this->Produk_model->count_all_row();
            
            //$produk=$this->Produk_model->get_all();
            if($jumlah>0)
            {
                $page['base_url']=site_url('produk/index');
                $page['total_rows']=$jumlah;
                $page['per_page']=$limit;
                $page['uri_segment']=$uri_segment;
                $this->pagination->initialize($page);
                $data['pagination']=$this->pagination->create_links();
                
                foreach($produk as $row)
                {    
                    $temp=array('id_produk'=>$row->id_produk,'nama'=>$row->nama,'seri'=>$row->seri,'keterangan'=>$row->keterangan,'image'=>$row->image,'jumlah'=>$row->jumlah,'harga'=>$row->harga,'tipe'=>$row->tipe);
                    $data['produk'][$row->id_produk]=$temp;
                }
            }else
            {
                $data['message']="Tidak ada data produk.";
            }
            $this->load->view('template',$data);
        }
}

here the model
Code:
class Produk_model extends model
    {
        function Produk_model()
        {
            parent::Model();
        }
        
        var $table='produk';

                function get_all_ten($limit,$offset)
        {
            $this->db->limit($limit,$offset);
            return $this->db->get($this->table);
        }

                function count_all_row()
        {
            return $this->db->count_all($this->table);
        }

        }

and here the view
Code:
echo ! empty ($h2_title) ? '<h2>'.$h2_title.'</h2>':'';
    
    echo ! empty ($message) ? '<p class="message">'.$message.'</p>':'';
    
    $flashmessage=$this->session->flashdata('message');
    
    if(!empty($link))
    {
        echo '<p id="top_link">';
        foreach($link as $l)
        {
            echo $l.' '.' '.' ';
        }
        echo '</p>';
    }
    
    echo ! empty ($flashmessage) ? '<p class="message">'.$flashmessage.'</p>':'';
    
    if(!empty($produk))
    {
    foreach($produk as $p)
    {
        ?&gt;
<fieldset class="produk">
<legend>&lt;?echo $p['tipe']?&gt;</legend>
            &lt;form action="&lt;?$form_action?&gt;" method="post"&gt;
        <table border="0" width="600">
            <tr>
                <td><h1 class="nama">&lt;? echo $p['nama']?&gt;</h1></td>
                <td></td>
                <td rowspan="5"><img src="&lt;?php echo $p['image']?&gt;" width="242" height="180" alt="Gambar Produk" /></td>
            </tr>        
            <tr>
                <td><h1 class="seri">&lt;? echo $p['seri']?&gt;</h1></td>
                <td></td>
            </tr>
            <tr>
                <td colspan="2" rowspan="3"><p class="keterangan">&lt;?echo $p['keterangan']?&gt;</p></td>
            </tr>
            <tr>
            </tr>
            <tr>    
            </tr>
            <tr>
                <td><h1 class="etc">Rp &lt;?echo $p['harga']?&gt;,00</h1></td>
                <td>
                <td>
                    &lt;input type="hidden" name="id_produk" value=&lt;?echo $p['id_produk']?&gt; /&gt;
                    &lt;input type='image' src="../images/11.png" alt="add to cart" class="submit"&gt;
                </td>
            </tr>
        </table>
        &lt;/form&gt;
</fieldset>
        &lt;?php
    }
    }
    
echo ! empty ($pagination) ? '<div class="pagination">'.$pagination.'</div>' : '';

i use autoload for url,form and pagination!!

i really need anyone help,.. thank you for reply!!
#2

[eluser]cideveloper[/eluser]
Three questions

1) In your view you have this code

Code:
&lt;input type='image' src="../images/11.png" alt="add to cart" class="submit"&gt;

Does this image show up on the second page of pagination?

2) Can you give an example of the url of the image stored in the database
3) I assume all the other information shows up ok in the view e.g.

$p['seri']
$p['nama']

I ask this to make sure pagination is working properly

Your issue for sure has something to do with paths, if the answer to (3) is yes.

P.S. Do you have firefox installed and if yes do you have firebug?
#3

[eluser]newbee[/eluser]
thank you for listening!!

answer,..
1. if i open from
Quote:http://localhost/OnlineShop/index.php/produk
as first page it show up normally, but start from second page
Quote:http://localhost/OnlineShop/index.php/produk/index/3
to the end page all image type not show.

Code:
<img src="&lt;?php echo $p['image']?&gt;" width="242" height="180" alt="Gambar Produk" />
and
Code:
&lt;input type='image' src="../images/11.png" alt="add to cart" class="submit"&gt;
not show up like i will,.. but it show up the alt value...

2. here example url
Code:
../catalok_produk/ks-h16.gif

3. yes,.. all thing except in answer 1 work well,..

i use mozilla firefox and already instaled firebug but don't know how to use it..
#4

[eluser]InsiteFX[/eluser]
See the bottom of code!

Code:
class Produk extends Controller
{
function Produk()
{
parent::controller();
$this->load->model('Produk_model','',TRUE);
}
var $title='produk';

function index()
{
$data['title']=$this->title;
$data['h2_title']='Produk > Catalog';
$data['main_view']='produk/catalok';
$data['form_action']=site_url('produk/cart');
$data['link']=array('all'=>anchor('produk','all',array('class'=>'nonaktif')),'accessories'=>anchor('produk/get_acc','accessories',array('class'=>'aktif')),'disk_drive'=>anchor('produk/get_disk','disk drive',array('class'=>'aktif')),);

$limit=3;
$uri_segment=3;
$offset=$this->uri->segment($uri_segment);
$query=$this->Produk_model->get_all_ten($limit,$offset);
$produk=$query->result();
$jumlah=$this->Produk_model->count_all_row();

//$produk=$this->Produk_model->get_all();
if($jumlah>0)
{
$page['base_url']=site_url('produk/index');
$page['total_rows']=$jumlah;
$page['per_page']=$limit;
$page['uri_segment']=$uri_segment;
$this->pagination->initialize($page);
$data['pagination']=$this->pagination->create_links();

foreach($produk as $row)
{
$temp=array('id_produk'=>$row->id_produk,'nama'=>$row->nama,'seri'=>$row->seri,'keterangan'=>$row->keterangan,'image'=>$row->image,'jumlah'=>$row->jumlah,'harga'=>$row->harga,'tipe'=>$row->tipe);
$data['produk'][$row->id_produk]=$temp;
}
}else
{
$data['message']="Tidak ada data produk.";
}
// the line below will allow all $data anywhere!
$this->load->vars($data);
$this->load->view('template');
}
}

InsiteFX
#5

[eluser]newbee[/eluser]
thank you for the answer InsiteFx but the image still not show,..
#6

[eluser]cideveloper[/eluser]
Im pretty sure this has nothing to do with your controller. It's best not to use relative paths for assets for your site/application. "../images/imagename.jpg" is bad. "http://localhost/images/imagename.jpg" is good

I always use this type url

Code:
&lt;?=base_url()?&gt;images/imagename.jpg

From looking at you code you have two folders that hold images. One called "images" and the other one called "catalok_produk". How is the directory structure for the folders in CI and in relation to the main index.php.

I would set it up like this

-index.php
-application
-system
-assets
--images
---catalok_produk

so then your code will look like this for the product images and all other images

Code:
<img src="&lt;?=base_url()?&gt;assets/images/&lt;?=$p['image']?&gt;" width="242" height="180" alt="Gambar Produk" />  

&lt;input type='image' src="&lt;?=base_url()?&gt;assets/images/11.png" alt="add to cart" class="submit"&gt;

you will have to makes sure you remove the ../ from all the entries in the database though.
#7

[eluser]newbee[/eluser]
problem solved,..

thank you very much cideveloper, for solution and the tips.. i'll remember that!!
#8

[eluser]cideveloper[/eluser]
Hey, No problem. Thats what the forums are for. One thing in terms of forum ettiquite that most people do not follow but is real good practice.

If the your problem is solved, append "[solved]" to the title of your post so it would look like this

Code:
image not show up in second page pagination,..[solved]

Good luck with your project

P.S. I did notice that your alt tags for the dynamic images is a static field. alt="Gambar Produk". Probably want to change that to a dynamic alt text from the db relating to the actual image.




Theme © iAndrew 2016 - Forum software by © MyBB