Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need help displaying an image on a drop down list selection

Featured Replies

Can someone please help me, does anyone know how i can get an image to show depending on the selection. Can this be done in php? i know it can if it where a normal html drop down list i.e. <option value='1'>selection 1</option> as i could use the value but with the php, i don't have that

 

Thanks in advanced.

 

the <option>$frame</option> has 5 options in the sql database, i would an image to show for each selection so that when you click on it, the user has something visual to confirm what they are about to buy etc.

Please find the code below

 

 

<html><head></head><body>

<form method="get" action="test8.php">

<select name="frame">

<?php

 

 

error_reporting (0) ;

 

$connect = mysql_connect ("*****","*******","******") or die(mysql_error());

mysql_select_db("********") or die (mysql_error());

 

echo "connected<p>";

 

//extract data

$extract = mysql_query("SELECT * from frame ORDER BY id ASC");

$numrows = mysql_num_rows ("$extract");

echo "<option>Please Select</option>";

while ($row = mysql_fetch_assoc ($extract))

{

$id = $row['id'];

$frame = $row['frame'];

echo "

<option>$frame</option>";

}

?>

</select>

<input type="submit" value="next page" />

</form>

</body></html>

the fastest would be to use Javascript

 

first use php to populate the list.

 

$query= mysql_query("SELECT * from frame ORDER BY id ASC"); //set SQL query
echo "<option value='null'>Please Select ...</option>"; //echo first option set it's value to null
$framedata = mysql_query($query) or die('Query failed: ' . mysql_error()); //fetch all the data
unset($query); //save resources by killing unused variables
if (!$framedata ) //some simple error checking
{ 
	//communicate with user if there is an error
	echo "sorry there was an error if you think we should know about this please let us know at <a href='mailto:email@server.com'>email@server.com</a>"; 
	exit; //stop processing if there is an error
}
else
{
	while($row = mysql_fetch_row($framedata ))
	{ 
	echo "<option value=".$row['id'].">".$row['frame']."</option>"; //echo EACH option set it's value to the ID
	}
	unset($framedata); //save resources by killing unused variables
}
unset $query //save resources by killing unused variables

 

I would use jquery ajax for displaying the image go see http://api.jquery.com/jQuery.ajax/

  • Author

the fastest would be to use Javascript

 

first use php to populate the list.

 

I would use jquery ajax for displaying the image go see http://api.jquery.com/jQuery.ajax/

 

 

Hi geeks, you have been a fantastic help and i don't know where i would be if it wasn't for you but i think you over estimate me, i've never used ajax before and and i've looked at the link and can't make sense of it or know where to add it, i've also got the next page which again need the images to show on the selection, could you help me out one last time

 

<?php if(!isset($_GET['frame'])){ header( 'Location: test7.php' ) ; }?>

<html><head></head><body>

<form method="get" action="test9.php">

<input type="hidden" name="frame" value="<?php echo $_GET['frame']; ?>">

<select name="image_style">

<?php

 

 

error_reporting (0) ;

 

$connect = mysql_connect ("*****","******","*******") or die(mysql_error());

mysql_select_db("******") or die (mysql_error());

 

echo "connected<p>";

 

//extract data

$extract = mysql_query("SELECT * from image_style ORDER BY id ASC");

$numrows = mysql_num_rows ("$extract");

//Selection 1

echo "<option>Please Select</option>";

if($_GET['frame'] == "Acrylic")

{while ($row = mysql_fetch_assoc ($extract)){

$id = $row['id'];

$image_style = $row['image_style'];

echo "<option>$image_style</option>";}}

//Selection 2

echo "";

if($_GET['frame'] == "Block Mounted"){

while ($row = mysql_fetch_assoc ($extract)){

$id = $row['id'];

$image_style = $row['image_style'];

echo "<option>$image_style</option>";}}

//Selection 3

echo "";

if($_GET['frame'] == "Canvas"){

while ($row = mysql_fetch_assoc ($extract)){

$id = $row['id'];

$image_style = $row['image_style'];

echo "<option>$image_style</option>";}}

//Selection 4

echo "";

if($_GET['frame'] == "Clipped"){

while ($row = mysql_fetch_assoc ($extract)){

$id = $row['id'];

$image_style = $row['image_style'];

echo "<option>$image_style</option>";}}

//Selection 5

echo "";

if($_GET['frame'] == "Framed"){

while ($row = mysql_fetch_assoc ($extract)){

$id = $row['id'];

$image_style = $row['image_style'];

echo "<option>$image_style</option>";}}

?>

</select>

<input type="submit" value="next page" />

</form>

</body></html>

Lets do one step at a time, you select list won't populate properly like this.

 

send me a layout of you DB

 

eg :

[frames]

[iD][frame_name]

 

[image_style]

[iD][image_style]

no problem Dan I am still a relative newby to PHP so we can learn together :clapping:

 

by the place your code in a code tag in the forum it is easier to read

  • Author

no problem Dan I am still a relative newby to PHP so we can learn together :clapping:

 

by the place your code in a code tag in the forum it is easier to read

 

This is my database, i've just been testing it at the moment

 

 

database : test

[frames]

[iD][frame]

 

[image_style]

[iD][image_style]

 

[edge_style]

[iD][edge_style]

 

 

page1

<html><head></head><body>
<form method="get" action="test8.php">
<select name="frame">
       <?php


error_reporting (0) ;

$connect = mysql_connect ("********","******","******") or die(mysql_error());
mysql_select_db("test") or die (mysql_error());

echo "connected<p>";

//extract data
$extract = mysql_query("SELECT * from frame ORDER BY id ASC");
$numrows = mysql_num_rows ("$extract");
echo "<option>Please Select</option>";
while ($row = mysql_fetch_assoc ($extract))
{
$id		= $row['id'];
$frame	= $row['frame'];
echo "
<option>$frame</option>";
}
?>
</select>
<input type="submit" value="next page" />
</form>
</body></html>

 

page2

<?php if(!isset($_GET['frame'])){ header( 'Location: test7.php' ) ; }?>
<html><head></head><body>
<form method="get" action="test9.php">
<input type="hidden" name="frame" value="<?php echo $_GET['frame']; ?>">
<select name="image_style">
       <?php


error_reporting (0) ;

$connect = mysql_connect ("********","******","******") or die(mysql_error());
mysql_select_db("test") or die (mysql_error());

echo "connected<p>";

//extract data
$extract = mysql_query("SELECT * from image_style ORDER BY id ASC");
$numrows = mysql_num_rows ("$extract");
//Selection 1
echo "<option>Please Select</option>";
if($_GET['frame'] == "Acrylic")
{while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$image_style	= $row['image_style'];
echo "<option>$image_style</option>";}}
//Selection 2
echo "";
if($_GET['frame'] == "Block Mounted"){
while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$image_style	= $row['image_style'];	
echo "<option>$image_style</option>";}}
//Selection 3
echo "";
if($_GET['frame'] == "Canvas"){
while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$image_style	= $row['image_style'];	
echo "<option>$image_style</option>";}}
//Selection 4
echo "";
if($_GET['frame'] == "Clipped"){
while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$image_style	= $row['image_style'];	
echo "<option>$image_style</option>";}}
//Selection 5
echo "";
if($_GET['frame'] == "Framed"){
while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$image_style	= $row['image_style'];	
echo "<option>$image_style</option>";}}
?>
</select>
<input type="submit" value="next page" />
</form>
</body></html>

 

page3

<?php if(!isset($_GET['image_style'])){ header( 'Location: test8.php' ) ; }?>
<html><head></head><body>
<form method="get" action="test9.php">
<input type="hidden" name="image_style" value="<?php echo $_GET['image_style']; ?>">
<select name="edge_style">
       <?php



error_reporting (0) ;

$connect = mysql_connect ("********","******","******") or die(mysql_error());
mysql_select_db("test") or die (mysql_error());

echo "connected<p>";

//extract data
$extract = mysql_query("SELECT * from edge_style ORDER BY id ASC");
$numrows = mysql_num_rows ("$extract");
//Selection 1
echo "<option>Please Select</option>";
if($_GET['Image_style'] == "Original")
{while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$edge_style	= $row['edge_style'];	
echo "<option>$edge_style</option>";}}	
//Selection 2
echo "";
if($_GET['Image_style'] == "Black & White"){
while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$edge_style	= $row['edge_style'];	
echo "<option>$edge_style</option>";}}
//Selection 3
echo "";
if($_GET['Image_style'] == "Sepia"){
while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$edge_style	= $row['edge_style'];	
echo "<option>$edge_style</option>";}}
//Selection 4
echo "";
if($_GET['Image_style'] == "Colour Splash"){
while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$edge_style	= $row['edge_style'];	
echo "<option>$edge_style</option>";}}
//Selection 5
echo "";
if($_GET['Image_style'] == "Framed"){
while ($row = mysql_fetch_assoc ($extract)){
$id		= $row['id'];
$edge_style	= $row['edge_style'];	
echo "<option>$edge_style</option>";}}
?>
</select>
<input type="submit" value="next page" />
</form>
</body></html>

 

page 4

<html><head></head><body>
<?php
if(isset($_GET['frame']))
{
echo "frame = " . $_GET['frame'];
}
if(isset($_GET['image_style']))
{
echo "<br /><br />color = " . $_GET['image_style'];
}
?>
</body></html>

lets see if I understand right here,

 

user selects a frame -> image style is relative to frame

-> user selects image style -> edge_style is relative to image syle

-> user selects edge_style

 

if that is correct how do you know which image styles go with a frame and which edge style goes with a image_style?

 

I think you need linking tables :

 

eg

[frame_image_link]

[iD][Frame_ID][image_ID]

-> this table will tell you which image goes with which frame

[image_edge_link]

[iD][image_ID][edge_ID]

-> this table will tell you which frame goes with which edge

 

 

 

 

 

  • Author

lets see if I understand right here,

 

user selects a frame -> image style is relative to frame

-> user selects image style -> edge_style is relative to image syle

-> user selects edge_style

 

if that is correct how do you know which image styles go with a frame and which edge style goes with a image_style?

 

I think you need linking tables :

 

eg

[frame_image_link]

[iD][Frame_ID][image_ID]

-> this table will tell you which image goes with which frame

[image_edge_link]

[iD][image_ID][edge_ID]

-> this table will tell you which frame goes with which edge

 

I forgot about that, but yeah i need it to link somehow, what you have put down is how it should be, i need that put in as well somehow lol

  • Author

I forgot about that, but yeah i need it to link somehow, what you have put down is how it should be, i need that put in as well somehow lol

 

eg

[frame_image_link]

[iD][Frame_ID][image_ID]

-> this table will tell you which image goes with which frame

[image_edge_link]

[iD][image_ID][edge_ID]

-> this table will tell you which frame goes with which edge

are you running phpmyadmin?

what image styles are there ?

  • Author

sorry I mean edge styles

 

acrylic

5mm

10mm

 

block mounted

white

black

wrapped

 

canvas

white

black

coloured

wrapped

delete your database 'test'

 

then in phpmyadmin go to SQL and run this:

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 15, 2010 at 11:57 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `test`
--
CREATE DATABASE `test` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `test`;

-- --------------------------------------------------------

--
-- Table structure for table `edge_style`
--

CREATE TABLE IF NOT EXISTS `edge_style` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`edge_style` text NOT NULL,
`frames` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;

--
-- Dumping data for table `edge_style`
--

INSERT INTO `edge_style` (`ID`, `edge_style`, `frames`) VALUES
(10, 'white', '3'),
(9, 'wrapped', '2'),
(8, 'black ', '2'),
(6, '10mm', '1'),
(7, 'white', '2'),
(5, '5mm', '1'),
(11, 'black', '3'),
(12, 'coloured', '3'),
(13, 'wrapped ', '3');

-- --------------------------------------------------------

--
-- Table structure for table `frames`
--

CREATE TABLE IF NOT EXISTS `frames` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`frame` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `frames`
--

INSERT INTO `frames` (`ID`, `frame`) VALUES
(1, 'Acrylic'),
(2, 'Block Mounted'),
(3, 'Canvas'),
(4, 'Clipped'),
(5, 'Framed');

-- --------------------------------------------------------

--
-- Table structure for table `image_style`
--

CREATE TABLE IF NOT EXISTS `image_style` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`image_style` text NOT NULL,
`Frames` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `image_style`
--

INSERT INTO `image_style` (`ID`, `image_style`, `Frames`) VALUES
(1, 'Original', '1,2,5'),
(2, 'Black & White', '2,4,5'),
(3, 'Sepia', '1,4,5'),
(4, 'Colour Splash', '4,5'),
(5, 'Framed', '2,1,3');

 

EDIT: in the image style table change the values of the Frames column to suit your needs

 

EDIT: I will send you the pages once you have this done

  • Author

delete your database 'test'

 

then in phpmyadmin go to SQL and run this:

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 15, 2010 at 11:57 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `test`
--
CREATE DATABASE `test` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `test`;

-- --------------------------------------------------------

--
-- Table structure for table `edge_style`
--

CREATE TABLE IF NOT EXISTS `edge_style` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`edge_style` text NOT NULL,
`frames` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;

--
-- Dumping data for table `edge_style`
--

INSERT INTO `edge_style` (`ID`, `edge_style`, `frames`) VALUES
(10, 'white', '3'),
(9, 'wrapped', '2'),
(8, 'black ', '2'),
(6, '10mm', '1'),
(7, 'white', '2'),
(5, '5mm', '1'),
(11, 'black', '3'),
(12, 'coloured', '3'),
(13, 'wrapped ', '3');

-- --------------------------------------------------------

--
-- Table structure for table `frames`
--

CREATE TABLE IF NOT EXISTS `frames` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`frame` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `frames`
--

INSERT INTO `frames` (`ID`, `frame`) VALUES
(1, 'Acrylic'),
(2, 'Block Mounted'),
(3, 'Canvas'),
(4, 'Clipped'),
(5, 'Framed');

-- --------------------------------------------------------

--
-- Table structure for table `image_style`
--

CREATE TABLE IF NOT EXISTS `image_style` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`image_style` text NOT NULL,
`Frames` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `image_style`
--

INSERT INTO `image_style` (`ID`, `image_style`, `Frames`) VALUES
(1, 'Original', '1,2,5'),
(2, 'Black & White', '2,4,5'),
(3, 'Sepia', '1,4,5'),
(4, 'Colour Splash', '4,5'),
(5, 'Framed', '2,1,3');

 

EDIT: in the image style table change the values of the Frames column to suit your needs

 

EDIT: I will send you the pages once you have this done

 

 

OK, i have deleted the test table and put this in the database, but i don't get what you mean

 

in the image style table change the values of the Frames column to suit your needs

 

?

 

Does it mean that if i select 2 Block Mounted / 4 Clipped or 5 Framed then the field that has 2,4,5 will show?

?

lol

 

the numbers represent the ID of the frame eg Acrylic = 1 so if Acrylic should show Framed then add 1 to that one.

else send me a list of frames and what image style they should have

 

the same as you did with edges

here are the pages maybe it will make more sense :

 

test7.php

<html><head></head><body>
<form method="get" action="test8.php">
<select name="frame"> <option>Please Select</option>	
	<?php
	$username="root"; //set username
	$password="pass"; //set password
	$database = "test"; //set database
	$server = "localhost"; //set server
	$sqlcon = mysql_connect($server,$username,$password); //connect to DB 
	@mysql_select_db($database) or die( "Unable to select database");
	$query = "SELECT * from frames ORDER BY ID ASC";
	$framedata = mysql_query($query) or die('Query failed: ' . mysql_error()); //fetch data
	//unset($query); //save resources by killing unused variables
	if (!$framedata ) //some simple error checking 
	{ 
	//communicate with user if there is an error
	echo "sorry there was an error if you think we should know about this please let us know at <a href='mailto:email@server.com'>email@server.com</a>"; 
	exit; //stop processing if there is an error
	}
	else
	{ 
	while($row = mysql_fetch_row($framedata)) //loop through results which are now matched with parameters
	{ 
	echo "<option value=".$row[0].">".$row[1]."</option>"; //echo each option set it's value to the ID
	}
	unset($framedata); //save resources by killing unused variables
	} 
?>
</select>
<input type="submit" value="next page" />
</form>
</body></html>

test8.php

<?php if(!isset($_GET['frame'])){ header( 'Location: test7.php' ) ; }?>
<html><head></head><body>
<form method="get" action="test9.php">
<input type="hidden" name="frame" value="<?php echo $_GET['frame']; ?>">
<select name="image_style"> 
<option>Please Select ...</option> 
<?php 
	$username="root"; //set username
	$password="pass"; //set password
	$database = "test"; //set database
	$server = "localhost"; //set server
	$sqlcon = mysql_connect($server,$username,$password); //connect to DB 
	@mysql_select_db($database) or die( "Unable to select database");
	$frame = $_GET['frame']; // set variable 
	$query= "SELECT * FROM image_style WHERE Frames LIKE '%$frame%' LIMIT 0 , 30"; //set SQL query with parameters
	$framedata = mysql_query($query) or die('Query failed: ' . mysql_error()); //fetch data
	unset($query); //save resources by killing unused variables
	if (!$framedata ) //some simple error checking 
	{ 
	//communicate with user if there is an error
	echo "sorry there was an error if you think we should know about this please let us know at <a href='mailto:email@server.com'>email@server.com</a>"; 
	exit; //stop processing if there is an error
	}
	else
	{
	while($row = mysql_fetch_row($framedata )) //loop through results which are now matched with parameters
	{ 
	echo "<option value=".$row[0].">".$row[1]."</option>"; //echo each option set it's value to the ID
	}
	unset($framedata); //save resources by killing unused variables
	} 
?> 	
</select>
<input type="submit" value="next page" />
</form>
</body></html> 

test9.php

<?php if(!isset($_GET['frame']) && !isset($_GET['image_style'])){ header( 'Location: test7.php' ) ; }?>
<html><head></head><body>
<form method="get" action="test10.php">
<input type="hidden" name="frame" value="<?php echo $_GET['frame']; ?>">
<input type="hidden" name="image_style" value="<?php echo $_GET['image_style']; ?>">
<select name="edge_style"> 
<option>Please Select ...</option> 
<?php 
	$username="root"; //set username
	$password="pass"; //set password
	$database = "test"; //set database
	$server = "localhost"; //set server
	$sqlcon = mysql_connect($server,$username,$password); //connect to DB 
	@mysql_select_db($database) or die( "Unable to select database");
	$frame = $_GET['frame']; // set variable 
	$query= "SELECT * FROM edge_style WHERE frames LIKE '%$frame%' LIMIT 0 , 30"; //set SQL query with parameters
	$framedata = mysql_query($query) or die('Query failed: ' . mysql_error()); //fetch data
	unset($query); //save resources by killing unused variables
	if (!$framedata ) //some simple error checking 
	{ 
	//communicate with user if there is an error
	echo "sorry there was an error if you think we should know about this please let us know at <a href='mailto:email@server.com'>email@server.com</a>"; 
	exit; //stop processing if there is an error
	}
	else
	{
	while($row = mysql_fetch_row($framedata )) //loop through results which are now matched with parameters
	{ 
	echo "<option value=".$row[0].">".$row[1]."</option>"; //echo each option set it's value to the ID
	}
	unset($framedata); //save resources by killing unused variables
	} 
?> 	
</select>
<input type="submit" value="next page" />
</form>
</body></html> 

test10.php

<?php if(!isset($_GET['frame']) && !isset($_GET['image_style']) && !isset($_GET['edge_style'])){ header( 'Location: test7.php' ) ; }?>
<html><head></head><body>
<?php
if(isset($_GET['frame']))
{
echo "frame = " . $_GET['frame'];
} 
if(isset($_GET['image_style']))
{
echo "<br /><br />image style = " . $_GET['image_style'];
} 
if(isset($_GET['edge_style']))
{
echo "<br /><br />edge style = " . $_GET['edge_style'];
}
?>
</body></html>

  • Author

here are the pages maybe it will make more sense :

 

 

I get it now lol, even then i had to keep going back and checking it before it clicked.

 

ok, could you please help me out with the image part, i know i'm asking a lot but you've been great and patient.

Glad to help, does it all make sense not just work, it doesn't help if it just works because then you have gained nothing.

 

explain the image part to me at what point do you want images and what images ?

Edited by Geeks

  • Author

Glad to help, does it all make sense not just work, it doesn't help if it just works because then you have gained nothing.

 

explain the image part to me at what point do you want images and what images ?

 

Your right, but i actually understand it, i'm now trying to see if i can add more pages to see if i can actually do it by myself, i find this is my best way of learning.

 

Let's start on the first selection,

 

I would like an image to show next to the drop down list (I guess i can do this with css, i hope) then once i choose Acrylic, it will replace the standard image with an image of acrylic, then if i select Block Mounted, it will replace the Acrylic image with the Block Mounted one etc etc

 

check out my site to show you what i mean but this is done in html and i need it working the new way to talk to the database etc http://www.evco-design.co.uk/

  • Author

Your right, but i actually understand it, i'm now trying to see if i can add more pages to see if i can actually do it by myself, i find this is my best way of learning.

 

Let's start on the first selection,

 

I would like an image to show next to the drop down list (I guess i can do this with css, i hope) then once i choose Acrylic, it will replace the standard image with an image of acrylic, then if i select Block Mounted, it will replace the Acrylic image with the Block Mounted one etc etc

 

check out my site to show you what i mean but this is done in html and i need it working the new way to talk to the database etc http://www.evco-design.co.uk/

 

p.s. I have added another page to it, so i do now understand more

I recall you never had working hosting, try (it is free I use it for my testing)

 

it has PHP, mySQL support

  • Author

I recall you never had working hosting, try (it is free I use it for my testing)

 

it has PHP, mySQL support

 

 

i might have to take that on board, the evco-design site which i use for testing is free at the moment but i think that runs out soon.

in the database in the frames table add a column at the end called img_src

 

for each entry add the value for img_src e.g : my images/Thumbnails/Image Styles/style4.jpg

 

let me know when that is done .

  • Author

in the database in the frames table add a column at the end called img_src

 

for each entry add the value for img_src e.g : my images/Thumbnails/Image Styles/style4.jpg

 

let me know when that is done .

 

I've never added an image to the database before, do i use varchar or something else?

no just add the location of the image relative to the page.

  • Author

no just add the location of the image relative to the page.

 

sorry geeks i'm lost?

make your frames table look something like this

 

[frames]

[iD] [frame] [img_src]

 

then for the values something like :

 

[1] [Acrylic] [images/1.jpg]

[2] [block Mounted] [images/blockmounted.jpg]

[3] [Canvas] [images/image_3.gif]

[4] [Clipped] [images/clipped_image.png]

[5] [framed] [images/5.jpg]

here is a solution but it does not validate, dan - IM me for the working code

 

Can anyone help me get it to validate ? The custom attribute "image" is giving problems

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<title>insert title here</title>
</head>
<body>
<form method="get" action="test8.php">
	<img alt='Sample image' id="change_me" src="images/base.jpg" /> 	
	<select id="frame" onchange='image_rollover()' name="frame" size="12">	
	<option image="images/base.jpg">Please Select
	</option> 	
	<option image="images/1.jpg">Please Select
	</option> 	
	<option image="images/2.jpg">Please Select
	</option> 	
	<option image="images/3.jpg">Please Select
	</option> 	
	<option image="images/4.jpg">Please Select
	</option> 	
	</select> <br /><br /> <br /> 
	<input type="submit" value="next page" />
</form>
<script type="text/javascript">
function image_rollover()
{ 
var x=document.getElementById("frame"); //get element 
var index = x.selectedIndex; // get selected index
var image = x.options[index].getAttribute("image"); // get image attribute 	
document.getElementById("change_me").src=image; //change img src 
}
</script>
<img alt='Sample image' src='images/1.jpg' style='display:none' />
<img alt='Sample image' src='images/2.jpg' style='display:none' />
<img alt='Sample image' src='images/3.jpg' style='display:none' />
<img alt='Sample image' src='images/4.jpg' style='display:none' />
</body>
</html>	

final code for those interested


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function image_rollover()
{ 
  var x=document.getElementById("frame"); //get element 
  var index = x.selectedIndex; // get selected index
  var image = x.options[index].getAttribute("image"); // get image attribute 
  var caption = x.options[index].getAttribute("caption"); // get caption attribute                   
  document.getElementById("change_me").src=image; //change img src 
  document.getElementById("caption_holder").innerHTML = caption;
  if (x.options[0].getAttribute("value") == "null")
  {
   x.remove(0);
  }                             
}
</script>
</head>
<body>
 <form method="get" action="test8.php">  
   <img alt="Sample image" id="change_me" src="images/base.jpg" />                  
   <select id="frame" onchange='image_rollover()' name="frame"> 
    <option caption="please select your option" value="null" image="images/base.jpg">Please Select</option>    
     <?php
         $username="****";   //set username
         $password="****";   //set password
         $database = "****";  //set database
         $server = "******";  //set server
         $sqlcon = mysql_connect($server,$username,$password);  //connect to DB 
         @mysql_select_db($database) or die( "Unable to select database");  //connect to table
         $query = "SELECT * from frames ORDER BY ID ASC"; //set query
         $framedata = mysql_query($query) or die('Query failed: ' . mysql_error()); //fetch data
         unset($query); //save resources by killing unused variables
           if (!$framedata ) //some simple error checking 
           { 
             //communicate with user if there is an error
             echo "sorry there was an error if you think we should know about this please let us know at <a href='mailto:email@server.com'>email@server.com</a>"; 
             exit; //stop processing if there is an error
           }
           else
           {   
             while($row = mysql_fetch_row($framedata)) //loop through results which are now matched with parameters
             { 
               echo "<option value=".$row[0]." image='$row[2]' caption='$row[3]'>".$row[1]."</option>"; //echo each option set it's value to the ID
             }
             unset($framedata); //save resources by killing unused variables
           } 
     ?>
    </select> 
   <br /><br /> <br />  
<div id="caption_holder">please select your option</div>
   <input type="submit" value="next page" />
 </form>
 <?php
                   ///////////////////////////
                   // TO PRELOAD THE IMAGES //
                   ///////////////////////////
       $images_query = "SELECT * from frames ORDER BY ID ASC";
       $images_data = mysql_query($images_query) or die('Query failed: ' . mysql_error()); //fetch data
       unset($images_query); //save resources by killing unused variables
         if (!$images_data ) //some simple error checking 
         { 
           //communicate with user if there is an error
           echo "sorry there was an error if you think we should know about this please let us know at <a href='mailto:email@server.com'>email@server.com</a>"; 
           exit; //stop processing if there is an error
         }
         else
         {   
           while($row = mysql_fetch_row($images_data)) //loop through results which are now matched with parameters
           { 
             echo "<img alt='Sample image' src='$row[2]' style='display:none' />";
           }
           unset($images_data); //save resources by killing unused variables
         } 
 ?>
</body></html>    

 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.