PHP 'IF Statement' comparing two tables in MYSQL

I am relatively new to PHP, I understand some and other bits confuse me... I have two tables n a database one called timages (Where I keep images) and one called technical data (where I store data)
On adding the data to the database, if there is no image for the particular data being added I auto upload a default gif image in its place.
When the data is called, the imageid in the technocaldata calls the reference for the image by id in timages.
My problem is that in technicaldata I store an imageid that relates to timages, so that I can call the technicaldata image as requested. what I need to do is have an IF Statement (think) that if the image that is called by the imageid is a gif, it doesnot display the links.
What I can do is call the timages type as stored and then checj if it is a gif and then have the IF replace the coe in the script.

I have attached the code where I call the technicaldata whee I have added to if statements to replace the links if they are needed or not. It is the val [6} in the IF staement that I need to compare to:
SELECT type FROM timages WHERE id="'.$val[6].'"
Then either display nothing if $val[6] = to a gif or if not display the two links $tdsdownload $tdslink

This is probably a bit confusing! Any help would be much a[[reciated
include 'admin/connect.php';
$res=mysql_query('SELECT id,tdstitle,subheading,supplier,dat,category,imageid FROM technicaldata WHERE category="2" ORDER BY tdstitle DESC',$dbh) or die(mysql_error());
for($run=0; $run<$num; $run++)
if ($val[6]=='0') $tdsdownload='&nbsp;'; else $tdsdownload='<a href="imagedownload.php?a='.$val[6].'"><img src="images/download.gif" alt="Download TDS" width="30" height="22" border="0"></a>';
if ($val[6]=='0') $tdslink='&nbsp;'; else $tdslink='<a href="image.php?a='.$val[6].'&TB_iframe=true&height=760&width=730" rel="sexylightbox"><img src="images/tds.gif" alt="View TDS" width="30" height="22" border="0"></a>';
echo '<table width="820" border="0" cellspacing="0" cellpadding="0" bgcolor="'.$col.'">
  <td height="40" align="right" valign="middle"><table width="820" height="22" border="0" cellspacing="0" cellpadding="0">
      <td width="303" align="left" class="mainTXT12LEFT"><a href="image.php?a='.$val[6].'&TB_iframe=true&height=760&width=730" rel="sexylightbox"><span class="Formtitles13">'.$val[1].'</span></td>
      <td width="327" align="left" class="mainTXT12LEFT">'.$val[2].'</td>
      <td width="110" height="22" align="left"><span class="mainTXT12LEFT">'.$val[4].'</span></td>
      <td width="41" align="left">'.$tdsdownload.'</td>
      <td width="39" align="center" class="maineleven_BK">'.$tdslink.'</td>
      <td height="1" align="center" valign="top"><img src="images/greenspacer.gif" width="820" height="1"></td>

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OK, first, to get the image from the timage tabl;e in the same query, change your SQL on line 4 to this:

$res=mysql_query('SELECT,t.tdstitle,t.subheading,t.supplier,t.dat,t.category,t.imageid,,i.image FROM technicaldata as t, timages as i WHERE t.category="2" and t.imageid = ORDER BY t.tdstitle DESC',$dbh) or die(mysql_error());

#this assumes your timages table has an "id" collumn that matches the imageid collumn in technicaldata, and that you store the image in a collumn called "image" in the timages table AND that you "store" only the image name and not the actual image as a blob.

So, now your SQL will return all the data as previous but in addition, you will laos now have the link between the tecnical data you queried and it's associated image from the timages table, as well as the image name.

Now, you need to first get the image name from your query - insert this on line 9 of your code:

$imagename= $val['image'];

Now we need to check if the image is a .gif or something else:

$extension = substr($imagename,-3);
This returns the last three characters of the filename.

Now we can check to see if it matches "gif" or "GIF" or "Gif" to then either display or not.

if (($extension == "gif") || ($extension == "GIF") || ($extension == "Gif)) {

} else {

 You can ajust your code on lines 10 and 11 using this.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flashjordanAuthor Commented:
That was great thanks... It was the selecting from two tables that was confusing me, but your clear explanasion did it... Perfect Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.