Jump to content

Fetching column values for particular row


ksumanth

Recommended Posts

Hello guys,

 

I created one form called Events in that 9 fields there like Id, Title, Eventdesc, video1,video2,video3,video4,video5,video6.

 

This is storing in database and while fetching data from database to frontend. i need to display all the videos video1,video2,video3,video4,video5,video6 for the particular event.

 

For that i need to fetch all the columns for particular row can any suggest me

 

 

Regards,

 

Sumanth

To answer the question explicitly, you should have a primary key column, most people call this the id, and make it an integer auto-incremented. I'm not sure that is what your id is set up as. Then you can call any row by "WHERE id=".

 

For pointers, your posted structure is going to limit you for future expansion (scaling). I would suggest that you normalize your database, which would include making 2 tables. 1 for events, and 1 for video's. In this way, you could have many more than 6 video's for every event, and could easily add pics, comments, or any other thing you might think of.

 

Example:

tables


CREATE TABLE IF NOT EXISTS `events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(25) NOT NULL,
`description` text NOT NULL,
`event_date` datetime NOT NULL,
PRIMARY KEY (`id`)
);


CREATE TABLE IF NOT EXISTS `videos` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`event` int(11) NOT NULL,
`title` varchar(20) NOT NULL,
`url` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);

 

Now you can access all your video's for any event, 100's if you wish. To add pictures, music, comments, etc, just add the relevant table, and join it to the events with the event to event.id column.

"SELECT e.title, e.description, v.title AS vidTitle, v.url FROM events AS e JOIN videos AS v ON e.id = v.event WHERE e.id = 1";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.