PDA

View Full Version : PHP Image Variable.



Jack!
22-12-2013, 10:00 PM
I have a variable stored in a database, which is a number up to three characters long (I.e 234)

I wish to display an image called the same as the number in the database, which obviously varies per account.

How can I get it to display something like www.site.com/234.png on the page? www.site.com/number.png?

Sorry if it doesn't make sense.

Jack.

Huggies
22-12-2013, 11:03 PM
I have a variable stored in a database, which is a number up to three characters long (I.e 234)

I wish to display an image called the same as the number in the database, which obviously varies per account.

How can I get it to display something like www.site.com/234.png (http://www.site.com/234.png) on the page? www.site.com/number.png? (http://www.site.com/number.png?)

Sorry if it doesn't make sense.

Jack.

<?php
$sql = "SELECT your_image FROM your_table WHERE your_conditions_here";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
?>
<img src="<?php echo $row['your_image']; ?>" />
<?php
} ?>

something like that?

Jack!
22-12-2013, 11:44 PM
<?php
$sql = "SELECT your_image FROM your_table WHERE your_conditions_here";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
?>
<img src="<?php echo $row['your_image']; ?>" />
<?php
} ?>

something like that?

<img src="/images/skins/<?php echo $row['your_image']; ?>.png" />

Would that work?

Huggies
23-12-2013, 01:05 AM
<img src="/images/skins/<?php echo $row['your_image']; ?>.png" />

Would that work?

I think it should, sorry I can't help you out alot, I'm fairly new to PHP. Let me know if it does work though!

Jack!
23-12-2013, 04:09 PM
I think it should, sorry I can't help you out alot, I'm fairly new to PHP. Let me know if it does work though!

Didn't work, haha.

Blinger
23-12-2013, 07:47 PM
You need to get $row from a query from the database. So you perform your query, then I do a number rows to see if it exists (returns 1 - not sure if needed), then do the $rows = mysql_fetch_array.
Jacks method looks okay.

Jack!
23-12-2013, 07:57 PM
You need to get $row from a query from the database. So you perform your query, then I do a number rows to see if it exists (returns 1 - not sure if needed), then do the $rows = mysql_fetch_array.
Jacks method looks okay.

Well what I currently have is a config file that grabs the data from the database and stores it in a session which all works fine, what I was trying is:

<img src="/images/skins/<?php echo $_SESSION['skin']; ?>.png" />

Is what I was trying but no luck, should that work?

Blinger
23-12-2013, 08:08 PM
Well what I currently have is a config file that grabs the data from the database and stores it in a session which all works fine, what I was trying is:

<img src="/images/skins/<?php echo $_SESSION['skin']; ?>.png" />

Is what I was trying but no luck, should that work?
post your config file.

Jack!
23-12-2013, 08:20 PM
post your config file.

Config file works fine as I have other sessions stored that gather the information and display it elsewhere on the system fine.

Blinger
23-12-2013, 08:24 PM
Config file works fine as I have other sessions stored that gather the information and display it elsewhere on the system fine.
It's hard to say if your script should work or not without seeing it. Post that snippet of code then.

Jack!
23-12-2013, 08:26 PM
It's hard to say if your script should work or not without seeing it. Post that snippet of code then.


$result= mysqli_query($con,"SELECT * FROM website WHERE `WebsiteID` = 1");
$row = mysqli_fetch_array($result);

$maresult= mysqli_query($con,"SELECT * FROM masteraccount WHERE `username` = '". $_SESSION['username'] ."'");
$marow = mysqli_fetch_array($maresult);

//===============Setting Variables:
$_SESSION['skin'] = $marow['cskin'];

Snipped the majority of it out, the other sessions work the same way and work fine.

Blinger
23-12-2013, 08:32 PM
Snipped the majority of it out, the other sessions work the same way and work fine.
That looks like it should work. Have you tried "hardcode" the $_SESSION['skin'] so it is the name of your .PNG file? Does the file name match exactly your image? What is your output? Not from the program you're coding in, but your browser

Jack!
23-12-2013, 08:52 PM
That looks like it should work. Have you tried "hardcode" the $_SESSION['skin'] so it is the name of your .PNG file? Does the file name match exactly your image? What is your output? Not from the program you're coding in, but your browser

That bit does work fine, I'll try it and see what happens.

Want to hide these adverts? Register an account for free!