Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP, MySQL] Fetch Image Link From Database

Newbie Spellweaver
Joined
Jan 10, 2010
Messages
15
Reaction score
0
I have been working with PHP for about a month now; I only decided to start working with MySQL a few days ago.

So I have been able to fetch information in text form but I want it as the background image of a div, and it's not working.

This is my database table I created. I want to take the topstory link and put it as the background of a div.

TechniQue - [PHP, MySQL] Fetch Image Link From Database - RaGEZONE Forums


It's just not working, any tutorials on how to do this? Or any advice?
 
Status: Pooping
Joined
Jul 16, 2008
Messages
861
Reaction score
25
Re: Fetch Image Link From Database [PHP, MySQL]

Like
<div style="background-image:url(<?php $fetch['topstory']; ?>);">
 
Newbie Spellweaver
Joined
Jan 10, 2010
Messages
15
Reaction score
0
Re: Fetch Image Link From Database [PHP, MySQL]

It's still not working, this is my code.

PHP:
<?php
$con = mysql_connect("localhost","root","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("cms", $con);

$result = mysql_query("SELECT num, title, topstory FROM cms_news");

mysql_close($con);

?>

<div style="background-image:url(<?php $result['topstory']; ?>);">
 
Skilled Illusionist
Joined
Apr 6, 2007
Messages
384
Reaction score
2
Re: Fetch Image Link From Database [PHP, MySQL]

mysql_fetch_assoc($result);



put that before you access the data.
 
Status: Pooping
Joined
Jul 16, 2008
Messages
861
Reaction score
25
Re: Fetch Image Link From Database [PHP, MySQL]

Complete script

PHP:
<?php
$con = mysql_connect("localhost","root","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("cms", $con);

$result = mysql_query("SELECT num, title, topstory FROM cms_news");
$info = mysql_fetch_assoc($result);
mysql_close($con);

?>

<div style="background-image:url(<?php $info['topstory']; ?>);">
 
Newbie Spellweaver
Joined
Jan 10, 2010
Messages
15
Reaction score
0
Re: Fetch Image Link From Database [PHP, MySQL]

It's still not working, this is the code up to now:

PHP:
<?php
$con = mysql_connect("localhost","root","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("cms", $con);

$result = mysql_query("SELECT num, title, topstory FROM cms_news");
$info = mysql_fetch_assoc($result);
mysql_close($con);

?>

<div style="background-image:url(<?php $info['topstory']; ?>); height:100px; width:100px;"></div>
 
Last edited:
Infraction Baɴɴed
Loyal Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
try mysql_fetch_array instead.
 
Last edited:
Divine Celestial
Loyal Member
Joined
Sep 13, 2008
Messages
853
Reaction score
14
Code:
<?php $info['topstory']; ?>
you need to echo it like this:
Code:
<?php echo $info['topstory']; ?>
or you could use <?= $info['topstory']; ?> but this is not recommended as this can be disabled at php config file, so it may not work on some servers killing compatibility.
 
Newbie Spellweaver
Joined
Jan 10, 2010
Messages
15
Reaction score
0
Code:
<?php $info['topstory']; ?>
you need to echo it like this:
Code:
<?php echo $info['topstory']; ?>
or you could use <?= $info['topstory']; ?> but this is not recommended as this can be disabled at php config file, so it may not work on some servers killing compatibility.

It works! Thanks! :thumbup:

Now for the add news article page. :(
 
Last edited:
Back
Top