Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 output info from database to layout

Author  Topic 

gwolf2u
Starting Member

1 Post

Posted - 2011-06-04 : 14:00:47
first of all hi guys
this is my first post here
as you might think, I'm new to mysql
well now related to my question
I have a database created and I want that for each row to output some data in my php page
in short
my table is named info
and has two columns, name and image
now I want for each name to output something like this

<a href="page/{name}"><img src="images/{image}.jpg" onMouseOver="this.src='images/over.png';" onMouseOut="this.src='images/{image}.jpg';"></a>


my mysql database looks like this

CREATE TABLE IF NOT EXISTS `info` (
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'game name',
`image` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'image name',
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


INSERT INTO `info` (`name`, `image`) VALUES
('Name 1', 'image1'),
('Name 2', 'image2'),
('Name 3', 'image3');


now any ideas how can I do this
again I'm new to this so no genius here :)

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-06-04 : 17:44:48
You should be able to write a select statement such as this:

declare @string varchar(255);
set @string = 'a href="page/{name}"><img src="images/{image}.jpg" onMouseOver="this.src=''images/over.png'';" onMouseOut="this.src=''images/{image}.jpg'';"></a>';
select replace(replace(@string,{name},name),{image},image) from YourTable

However, the syntax I have given above is for Microsoft SQL Server. It may not work on MySQL. This site is for Microsoft SQL Server, so while there may be people who are familiar with MySQL, I suspect you will get better and faster responses at a MySQL forum or generalized database forums such as dbforums.com
Go to Top of Page
   

- Advertisement -