Im sure this is simple but newbie here.
I have 5 URLS
cards.php&type=one
cards.php&type=two
cards.php&type=three
cards.php&type=four
Question.
How will I display an image based on the URL
Image Directory = images/cards/one.jpg,two.jpg etc...
Thanks your help is much appreciated
Try this:
echo "<img src='{$_GET['type']}.jpg' />";
And with a check:
if (isset($_GET['type']) && (trim($_GET['type']) != "")) {
echo "<img src='". $_GET['type'] .".jpg";
}
$type = $_REQUEST['type'];
if($type == "one")
{
$imag = "images/cards/one.jpg";
}
else if($type == "two")
{
$imag = "images/cards/two.jpg";
}......
or use
switch ($type)
{
case one:
$imag = "images/cards/one.jpg";
break;
case two:
$imag = "images/cards/two.jpg";
break;
case three:
$imag = "images/cards/three.jpg";
break;
default:
$imag = "images/cards/default.jpg";
}
try this one i think it might help you.
First of, the delimiter between the "hier-part" and the query string is ?
, not &
, cf. RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax . Your URLs should thus look like:
cards.php?type=one
cards.php?type=two
cards.php?type=three
cards.php?type=four
Now, inspect the contents of the global $_GET
array using eg print_r($_GET)
. You should find an entry with the key type
corresponding with the query string parameter.
Next, use the value of type
( $_GET['type']
) to write an image tag. Beware that users can easily manipulate the query string so some input sanitation should be performed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.