Welcome Guest, Not a member yet? Register   Sign In
Images not showing
#1

[eluser]Brovar[/eluser]
Heya.

I'm making a webcomic site, and i've run into a problem. I'm displaying comics, and you can browse between then as in every site that type. The problem is, that displaying latest comic works fine, but switching won't work. Here's the code:

Model:
Code:
<?php
class Comic_model extends CI_Model {

public function __construct()
{
  $this->load->database();
}
        public function get_comic($id = FALSE)
{
if ($id == FALSE)
{
  $this->db->select_max('ComicId');
                $query = $this->db->get('comic');
  $max = $query->row_array();
  $maxx = $max['ComicId'];
  $this->db->where('ComicId', $maxx);
  $query = $this->db->get('comic');
  return $query->row_array();
}
else
{
$query = $this->db->get_where('comic', array('ComicId' => $id));
return $query->row_array();
}
}

Controller:
Code:
<?php
class Comic extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('comic_model');
}

public function index($id = FALSE)
{
                $this->load->helper('url');
                $this->load->helper('html');
  $data['comic'] = $this->comic_model->get_comic($id);
  $this->load->view('templates/header');
  $this->load->view('templates/main');
                $this->load->view('comic', $data);
                $this->load->view('templates/sidebar');
  $this->load->view('templates/footer');
  
}
        
}

View:

Code:
<div id="splash"><img src = "&lt;?php echo $comic['ComicUrl'] ?&gt;" height = "400" width = "600"></div>
<div id="comicmenu">
<ul>
  <li>&lt;?php echo anchor('comic',img('images/arrow_left2.jpg'));?&gt;</li>
  <li>&lt;?php echo anchor('comic/index/8',img('images/arrow_left.jpg'));?&gt;</li>
  <li>&lt;?php echo anchor('comic/index/9',img('images/arrow_right.jpg'));?&gt;</li>
  <li>&lt;?php echo anchor('comic',img('images/arrow_right2.jpg'));?&gt;</li>
  &lt;?php echo $comic['ComicUrl'];?&gt;
</ul>
        
</div>

As you see, if there is no id present, it just takes latest entry into database via get_max and displays it. Otherwise it returns an entry with corresponding id. The links are hardcoded for testing purposes.

The problem is, that when i go through webcomic/comic it works fine, but if i use webcomic/comic/index or webcomic/comic/index/$id it won't display the image. Curious thing is that proper database entry is actually passed to view. I double checked it via echo and the end of the view, and also if i go to source code, it actually shows identical img src as when going without id ( but of course with different entry ).

Any ideas?
#3

[eluser]aquary[/eluser]
webcomic/comic or webcomic/comic/index would be the same since it's one without id.

If I understand the problem correctly:
- without ID, you got the latest one, no problem.
- with ID, The images are missing, but the generated image src was the same as the above one.

My question is: How could the image on the 2nd case, with the same image src as the first case, gone missing? It's impossible. If the sourcecode are the same, the same image should be shown.

Could you show what are the generated code from the one with and without id ? I think some chain are missing here...

FYI: you could use order_by to select a latest entry, instead of using MAX...
Code:
//Model
public function get_comic($id = FALSE)
{
    if ($id == FALSE)
    {
       return $this->db->order_by('ComicId', 'desc')->limit(1)->get('comic')->row_array();
    }
    else
    {
       $query = $this->db->get_where('comic', array('ComicId' => $id));
       return $query->row_array();
    }
}
#4

[eluser]Brovar[/eluser]
Thanks for the replies.

I read on routing and i failed to find anything that would help me solve this particular problem.

About source code: When i check it, it's exactly the same. So if i click on a link to webcomic/comic it gets latest id, so source code shows images/5.jpg and it works fine. But if i use a link to webcomic/comic/index/3 for example it shows images/3.jpg and there is image missing element on the site.

What's even more strange, when i go to webcomic/comic/index it also shows images/5.jpg but image is missing! Even though it should provide same result as webcomic/comic.
I tried to comment out any and all routing options, no difference. And as i said source code is identical.

Btw. for some reason i get an error when trying to paste code.
#5

[eluser]pickupman[/eluser]
The maybe a absolute/relative path issue. Mind posting the output from the source code from both? I bet you have luck using:
Code:
<div id="splash"><img src = "/&lt;?php echo $comic['ComicUrl'];?&gt;" height = "400" width = "600"></div>
#6

[eluser]Brovar[/eluser]
Adding "/" , or using whole path "webcomic/comic/index/id" did not work. What's more, it even made the webcomic/comic stop working.

Code:
<div id="splash"><img src = "images/3.jpg" height = "400" width = "600" ></div>


So the above part is source code that does not work ( webcomic/comic/index/id )

Below, the one that works (webcomic/comic):

Code:
<div id="splash"><img src = "images/5.jpg" height = "400" width = "600" ></div>
#7

[eluser]pickupman[/eluser]
This means you do have a file path issue because the links without a leading slash are relative to the url in the browser's address bar.

Example:
URL: webcomic/comic/index/id
Image Path: webcomic/comic/index/images/5.jpg

URL: webcomic/comic
Image Path: webcomic/comic/images/5.jpg

Seeing that means you need to use an absolute URL for images to work. This should do the trick providing your images are in the folder webcomic/comic/images:
Code:
<div id="splash"><img src = "/webcomic/comic/&lt;?php echo $comic['ComicUrl'];?&gt;" height = "400" width = "600"></div>
#8

[eluser]Brovar[/eluser]
W00t, fixed.

My images were placed in the root folder of my application. So my app is webcomic/application, and my images are in webcomic/images. I got to work by using

Code:
<img src = "&lt;?=base_url(); echo $comic['ComicUrl']; ?&gt;" height = "400" width = "600" >

Thanks for helpWink
#9

[eluser]CroNiX[/eluser]
Yes, using a absolute path is the best thing to do.




Theme © iAndrew 2016 - Forum software by © MyBB