I am trying to have two databases work together, however, I am having problems figuring it out.
DATABASE 1: FIELDS = id, title, description, image_name_id
DATABASE 2: FIELDS = id, image_name
I already wrote a script that uploads an image and writes the name of the image to “image_name” in database 2.
When I want to output that image, I just use the link where the image was stored in my ftp. E.g.
However, I would like to do something different.
I would like to have DATABASE 1 used to store articles. Sometimes, the articles would have images associated with them. The same image may be used often by any given number of articles, hence the need for a database for the image. However, sometimes an image doesn’t exist.
I wrote a script already that allows me to add articles along with a selection of images that exist. That was easy. The hard part is the actual content page.
IF NOT IMAGE EXIST, then don’t display, however, if an image exist, then display the image.
[code=php]<? if($onecontent->image_name_id!=””) { ?>
<?php
include(“../class/config.php”);
$id=$onefea->image_name;
$start=$_REQUEST[‘start’];
$WHERE = “WHERE `id` = ” . $onefea->image_name;
$sqlfea = “SELECT * FROM `DATABASE2` $WHERE”;
$linkfea = mysql_query($sqlfea,$db);
while ($onefea = mysql_fetch_object($linkfea)) {
echo “<img border=0 src=’images/theme_images/”.$onecontent->image_name.”‘ />”; ?>
<? } ?>
I am so confused now and my code is totally wrong. Can someone send me in the right direction so that I can include the image name from DATABASE 2, into my script with output information for DATABASE 1.