Work to relate tables

Asked

Viewed 108 times

0

Personal talk.

I am developing a portal aimed at music, the idea and give all necessary information to the visitor about his favorite artist/ band: as Photo of the band, Description , Website, Facebook and on the page of the same list A grid with all the news of the same.

In the development I created a table tbl_post with the fields:

id | status | sessao | categoria | capa | titulo | url | conteudo | banda | video | data | visitas

id - unique for each post with auto increment status - 1 or 0 to inactivate or not post sessao - shows whether it is category or sub-category category - shows the category cover - the cover of the post (Thumbnail) title - the title url - the friendly url of the post content - needless to say rsrs band - band name video - video url date - post release visits - account of visits

And I also created a table called tbl_band and put the following fields:

id - unique id for band cover with auto increment Vert - shows the musical style cover - cover of the same band - band name url - band page url origin - I place the Country of Origin facebook - twitter - website - description - date -

It’s the following guys. I’ve been racking my brain for a while and worse, I feel like it’s something very primary that I’m doing wrong.

I’m having trouble relating the post to the band,want when I post a post and choose the band in the post. That the post be updated on the due page of the band. to feeling that the band field in the post table will not be used, whatever the medium used.

Below is the code to update the post, find a way for me to implement the information in the bands table through the update post:

// Script in progress//

            case 'post_atualiza':
    sleep(1);
    $postid = mysql_real_escape_string($_POST['postid']);
    $c['titulo']    = mysql_real_escape_string($_POST['titulo']);
    $c['categoria'] = mysql_real_escape_string($_POST['categoria']);

    //LE E RECUPERA A SESSAO
    $readSes = read('categorias',"WHERE id = '$c[categoria]'");
    if($readSes): foreach($readSes as $ses); endif;
    $c['sessao'] = $ses['sessao'];      
    $c['banda']     = mysql_real_escape_string($_POST['banda']);
    $c['video']     = mysql_real_escape_string($_POST['video']);
    $c['conteudo']  = mysql_real_escape_string($_POST['conteudo']);
    $c['cadastro']  = mysql_real_escape_string($_POST['cadastro']);
    $c['status']    = mysql_real_escape_string($_POST['status']);
    $c['url'] = setUri($c['titulo']);
    $c['cadastro'] = formDate($c['cadastro']);
    $verificaURL = read('posts',"WHERE id != '$postid' AND url = '$c[url]'");

            aqui fica o script das imgs,desnecessário para o assunto                    
            ---------------------------------------------------------


    update('post',$c,"id = '$postid'");


break;

Tabela Post

Tabela Bandas

  • You can edit your question and add these links. (http://answall.com/posts/16894/edit)

1 answer

1


You need a Foreign key that relates the table "tbl_post" to the table "tbl_band". for example:

1º -(Table) "tbl_banda" with the field "idBanda (PK)"

2º -(Table) "tbl_post" with the field "idPost" and "idBanda (FK)"

The relationship is 1 for "n", IE, 1 band for various posts.

  • Thanks for your help, I appreciate it. Sorry it took me so long to answer,.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.