Jump to content

Getting pictures out the database


GetAWeapon

Recommended Posts

Hello, like I promised, I'm back with another problem. This one will be harder xD so squeeze your brain

 

Now I've got a webpage, with a database shown into a table, under that I've got page numbers. So I got my 20 rows for each page.

 

https://www.dropbox.com/s/txsinttizihiwo5/stillnotok.jpg

 

Great/awesome so far :D

 

Now I've got a new problem and it's hard for me to explain this too.

 

In my database I got allot of tables, in my webpage I'm using 2 of them, called 'artikel' and 'images".

 

Everything from my artikel table is ok. So we don't need to look at that.

 

But my problem is with the table 'images'.

 

In that table I got 2 items.

 

Like you will see in my code, I need the I_ARTCODE and I_FILE

 

in I_ARTCODE stands: 14 and for the other image 15

 

in I_FILE stands: 5.jpg and for the other image 6.jpg

 

With the code I've got now, I display the word 5.jpg and 6.jpg.

 

But I need to display the picture behind that, the person who gave me this task sayed, I normally can do this with the pad but it's not a real url, I'll give you guys a picture how my database looks like:

 

https://www.dropbox.com/s/lfac7gzr1uqplxd/path.jpg

 

Over here the pad is this: 000000-001000

 

It doesn't seems normal to me and I can't find a sollution for this on the internet.

 

Can someone plz help me?

 

Ooh ya, almost forgot, this is my code:

<?php
include('connect-mysql.php');
if (!empty($_GET["page"])) {
    $page  = $_GET["page"];
} else {
    $page=1;
}; 
$start_from = ($page-1) * 20; 
$sqlget = "SELECT *
FROM artikel, images
LIMIT $start_from, 20
";

$sqldata = mysqli_query($dbcon, $sqlget) or die('error getting');

echo "<table>";
echo "<tr><th>A_ARTCODE</th><th>A_NUMMER</th><th>A_OMSCHRN</th><th>A_REFLEV</th><th>A_WINKEL</th><th>I_ARTCODE</th><th>I_FILE</th></tr>";

while($row = mysqli_fetch_array($sqldata)){
	echo "<tr><td align='right'>";
	echo $row['A_ARTCODE'];
	echo "</td><td align='left'>";
	echo $row['A_NUMMER'];
	echo "</td><td align='left'>";
	echo $row['A_OMSCHRN'];
	echo "</td><td align='left'>";
	echo $row['A_REFLEV'];
	echo "</td><td align='right'>";
	echo $row['A_WINKEL'];
	echo "</td><td align='right'>";
	echo $row['I_ARTCODE'];
	echo "</td><td align='right'>";
	echo $row['I_FILE'];
	//echo "<img src='000000-001000".$row['I_ID']."' />";
	echo "</td></tr>";
	}
	
echo "</table>";

$sql = "SELECT COUNT(A_ARTCODE) FROM artikel";
$rs_result = mysqli_query($dbcon, $sql) or die ("mysqli query dies");
$row = mysqli_fetch_row($rs_result) or die ("mysqli fetch row dies");
$total_records = $row[0];

$total_pages = ceil($total_records / 20);

for ($i=1; $i<=$total_pages; $i++) { 
            echo "<a href='index.php?page=".$i."'>".$i."</a> "; 
};
?>
Link to comment
Share on other sites

Ya but if that worked, I wouldn't putted // in front of it xD

 

Like you say, yes indeed, when I do that I get a icon that there is no image found. But it's not that what I need, there are images behind the word 5.jpg and 6.jpg, it's really strange. I'll show you a picture in this post with the proof of it.

 

Maybe I explained not good enough, my collague made also a version from it and had this and normally it's the same code, I'll double check it after this post. But I'm sure it was the same.

 

https://www.dropbox.com/s/j8q8frdufj9jtn7/strange.jpg

 

Like you see, every name end with 5.jpg in this example, but when I scroll down, a bunch of them ends with 6.jpg. So if im right, the part in front of that makes the url or path to that picture complete.

 

So how can I display this like an image?

 

I thougth something like this: [frontcode]+[i_FILE]=complete url/path and that should give the pictures if I'm right. I think my idea can work, but I don't know how to put this in code.

 

I'm only a noob at php and it's my 5 day I use php in my life.

Link to comment
Share on other sites

Oooh nvm, my collague, fckd it up. Forget my post before, It's totally worthless.

 

 

Now I did this:

echo "<img src='".$row['I_PATH' + 'I_ID']."' />";

I get this as result in the url: http://localhost/DBFact/NWADLIDES-1005D

 

I think that's almost good, but you see, it goes to the localhost, but it should go to my online host, where my database is... how can I do that?

Link to comment
Share on other sites

If that's the case, you should have a variable or constant defined that contains the path to your image server.

define('IMAGE_PATH', 'http://yourhost.com/picpath.../');

Then your image path just needs to be prepended with that variable:

 

 

echo "<img src='". IMAGE_PATH . $row['I_PATH' + 'I_ID']."' />";
Link to comment
Share on other sites

Ok thanks, now I doesn't direct me to my localhost anymore. But I still got no results, really strange. My url is now this: http://dbfact.consult4u.be/images/NWADLIDES-1005D

 

I really thought it should work. Is it possible, it doens't work because there is no '.jpg' behind the url?

 

My code atm is this:

echo "<img src='". IMAGE_PATH . $row['I_PATH' + 'I_ID']."' />";
Link to comment
Share on other sites

Ah, nvm, it works now, I founded it :)

 

 

didn't knew there was another map in the images map xd stupped hidden path

define('IMAGE_PATH', 'images/000000-001000/');

echo "<img src='". IMAGE_PATH . $row['I_ID']. '.JPG' ."' />";
Link to comment
Share on other sites

Noooo, I still got a bug, in my 2 tables, I got 2 keys, one array called 'A_ARTCODE' and in my other one for the images 'I_ARTCODE'. Normally those 2 ID's need to be te same.So normally every product will have his own picture and ID. But now I got this:

 

https://www.dropbox.com/s/mwcadcjbi4ol8cr/wrongid.jpg

 

So the only products that should have a picture, that are the first 2, I think I made a mistake by making a fixed path like this:

define('IMAGE_PATH', 'images/000000-001000/');

So I need to make a relative path in this line:

echo "<img src='". IMAGE_PATH . $row['I_ID']. '.JPG' ."' />";

theoretical it should be something like I_PATH + I_FILE, the path is the name of the folder and the file is the name of my picture. How can put this in php code?

Link to comment
Share on other sites

I think my mistake is in my selection from my tables:

$sqlget = "SELECT *
FROM artikel, images
LIMIT $start_from, 20
";

Normally to set my 2 keys the same I need to do this:

WHERE artikel.A_ARTCODE = images.I_ARTCODE

But when I do this, then I only got 2 products left, I just want to see all my products even when they don't got a picture.

Link to comment
Share on other sites

I think you should take a deep breath and get clear about what you want to do.

 

It's not very helpful if you come back every 5 minutes, present some random idea, tell us that it works, then tell us that it doesn't work and start over with some new random idea. You've probably lost everybody by now.

 

Try to approach this in a more systematic and thought-out way: What is the relevant data in the table?

 

Is it I_ID? No, that's just the primary key. I'm pretty sure that I_PATH is the subdirectory of the main image directory, and I_FILE is the image file within this subdirectory. So the full path would be:

https://yoursite.com/path/to/images/{I_PATH}/{I_FILE}

I cannot verify this. If you're not sure either, ask the person who placed the pictures on the server.

 

If this is indeed the correct path, now you need to write this down with actual PHP syntax.

 

 

 

Link to comment
Share on other sites

Thanks for your reply, but yes, my problem with that link already got fixed with this:

echo "<img src='". IMAGE_PATH . $row['I_PATH']. '/' . $row['I_ID']. '.png' ."' />";

And my problem after that also got fixed a couple of minutes ago with this:

$sqlget = "SELECT *
FROM artikel
LEFT JOIN images
ON artikel.A_ARTCODE = images.I_ARTCODE
LIMIT $start_from, 20
";

Anyway thank you very much for your help making some time for my problem. But for now everthing is fixed :)

Link to comment
Share on other sites

I have no idea how that is a “fix”.

 

Who says that the primary key of the image is the filename? Who says that all images have a “.png” extension? In fact, the table entries you've shown so far all ended with “.JPG”.

 

If you like to deal with the problem again in a few days when people complain about broken images, go ahead. But personally, I'd do it now.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.