Ok so I wrote a little script that allows me to call information from my database. Basicly this.

<table>
<tr>
<td id="seal"><?php
include("sql.php");
echo "$websiteaddress";
?></td></tr>
</table>

All this does is connects to the sql file echoing the users website address thus I type in mywebsite.com/index.php?name=aname and it returns their name now it also connects to a css file to display an image.

What I want to be able to do is display a different image depending on the url such as mywebsite.com/index.php?name=aname=red or mywebsite.com/index.php?name=aname=blue and it displays a red or blue image depending.

I thought about trying else elseif but can seem to get it to work.

How would I go about doing this? Any help would be appreciated. Please remember I am still learning so take it easy on me and if possible post the code for examples so I can try it and better understand the idea and concept.

Thank you.

It seems that, its the code in sql.php which is working for it.
You need to post that script here.

What I want to be able to do is display a different image depending on the url such as mywebsite.com/index.php?name=aname=red or mywebsite.com/index.php?name=aname=blue and it displays a red or blue image depending.

You would have to supply two variables in the URL, then use $_GET. I do this same thing, only with PDF or xls files:

Code that sets the vars:

<?php

$excel_icon = "<IMG SRC='/images/misc/excel_48.png' ALT='Excel Icon' WIDTH='48' HEIGHT='48' BORDER='0'>";
$pdf_icon = "<IMG SRC='/images/misc/pdf_48.png' ALT='PDF Icon' WIDTH='48' HEIGHT='48' BORDER='0'>";
$prefix = "/protected-folder/secret/getfile.php?";

switch ($row_files['pdf-xls-files'])
{
    case '12':
        $pdfFile = "pdffile=12.pdf";
	echo "<A HREF='".$prefix.$pdfFile."'>$pdf_icon</A>";
	break;
    case '15':
	$pdfFile = "pdffile=15.pdf";
	echo "<A HREF='".$prefix.$pdfFile."'>$pdf_icon</A>";
	break;
    case '18':
	$pdfFile = "pdffile=18.pdf";
	echo "<A HREF='".$prefix.$pdfFile."'>$pdf_icon</A>";
	break;
    default:
	$pdfFile = "pdffile=12.pdf";
	echo "<A HREF='".$prefix.$pdfFile."'>$pdf_icon</A>";
	break;										
}
?>
</td>
<td align="center" valign="middle">
<?php
switch ($row_files['pdf-xls-files'])
{
    case '12':
	$xlsFile = "xlsfile=12.xls";
	echo "<A HREF='".$prefix.$xlsFile."'>$excel_icon</A>";
	break;
    case '15':
	$xlsFile = "xlsfile=15.xls";
	echo "<A HREF='".$prefix.$xlsFile."'>$excel_icon</A>";
	break;
    case '18':
	$xlsFile = "xlsfile=18.xls";
	echo "<A HREF='".$prefix.$xlsFile."'>$excel_icon</A>";
	break;
    default:
	$xlsFile = "xlsfile=default.xls";
	echo "<A HREF='".$prefix.$xlsFile."'>$excel_icon</A>";
	break;										
}
?>

Script that displays the files:

<?php

require_once("../../includes/protected-folder/_session_vars.php");

$folder = "plfiles/";
$pdfFile = $_GET['pdffile'];
$xlsFile = $_GET['xlsfile'];
$rURL_long = "http://www.domain.com/protected-folder/secret/index.php";
$rURL_short = "http://www.domain.com/protected-folder/secret/";
$ref = $_SERVER['HTTP_REFERER'];


if (!isset($pdfFile) && !isset($xlsFile)) {
	header("Location: index.php");
	exit();
}

if ($ref != $rURL_long && $ref != $rURL_short) {
	header("Location: index.php");
	exit();
}

if (isset($pdfFile)) {
	$file = $folder.$pdfFile;
	header("Content-type: application/pdf");
	header("Content-Disposition: attachment; filename=".$file);
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: pre-check=0, post-check=0, max-age=0");
	header("Cache-Control: private");
	readfile($file);
	break;
}
else if (isset($xlsFile)) {
	$file = $folder.$xlsFile;
	header("Content-type: application/vnd.ms-excel");
	header("Content-Disposition: attachment; filename=".$file);
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: pre-check=0, post-check=0, max-age=0");
	header("Cache-Control: private");
	readfile($file);
	break;
}
else {
	die("An error has occured while getting the requested file.  Please notify the website owner. Error: getfile-both=True");
}

exit();
?>

I imagine that this same concept can be applied to display an image or CSS file based on URL vars using $_GET.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.