CodeIgniter Forums
Get uploaded picture from mysql database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Get uploaded picture from mysql database (/showthread.php?tid=55148)

Pages: 1 2


Get uploaded picture from mysql database - El Forum - 10-12-2012

[eluser]rochellecanale[/eluser]
hello guys i need a help regarding of getting the picture from my database literally the file path. My problem is after u run the query. It will continue to load and view nothing just keep on loading. Here's my code below hope you can help me.

Code:
$username = $this->session->userdata('username');
                $sql = "SELECT file_path FROM upload WHERE username = '$username'";
                $query = mysql_query($sql) or die (mysql_error());
                
                while(($row = mysql_fetch_row($resultSelect))!== FALSE){
                    $path = $row['file_path'];
                }
                
                echo "<br />";
                echo "<img src='$path' height='250' width='250'>";

Here's the sample output from my database:
Code:
+-----------------------------------------+
| file_path                               |
+-----------------------------------------+
| http://localhost/eMLM/upload/Winter.jpg |
+-----------------------------------------+

When i attempt to run in sql like this:
Code:
mysql> SELECT file_path FROM upload WHERE username = 'ssssssssssss';

It display a path but when i load it in my php code it shows nothing.




Get uploaded picture from mysql database - El Forum - 10-12-2012

[eluser]LuckyFella73[/eluser]
DB queries goes into models and echo image tags into views but
basically you can do your query like that:

Code:
$this->load->library->('database');
$this->db->select('file_path');
$query = $this->db->get('upload');

if ($query->num_rows() > 0)
{
$row = $query->row();
$path = $row->file_path;
}
echo "<img src='$path' height='250' width='250'>";



Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
Its not showing any images. I tried also displaying of the full_path from my database but it loads only. I dont know my exact problem.


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]LuckyFella73[/eluser]
Quote:+-----------------------------------------+
| file_path |
+-----------------------------------------+
| http://localhost/eMLM/upload/Winter.jpg |
+-----------------------------------------+

Does your browser display the image when you
paste the url directly into url field?


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
I tried to create a simple image tag like this.
Code:
<img src='http://localhost/eMLM/upload/Sunset.jpg' height='100' width='100'>

And it displays the image from my folder. But when i attempt to pull down the data from my mysql database it does not show. It keeps on loading.


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
By the way if i attempt to run it in my url id displays
Code:
Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
10/15/12 17:27:17
Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1



Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]LuckyFella73[/eluser]
What do you get if you debug like:
Code:
$this->load->library->('database');
$this->db->select('file_path');
$query = $this->db->get('upload');

if ($query->num_rows() > 0)
{
$row = $query->row();
$path = $row->file_path;
}
echo "Path from DB: ".$path;
exit();




Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
Hmm i didn't try that wait.


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
Ok nothing displays it load again. It does not shows the path.


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]LuckyFella73[/eluser]
Seems you have to set up your htaccess the right way first?
The error you posted is not related to your database call.
Looks like your controller isn't called correctly.