need some help with php

Discussion in 'PHP' started by lonely88, Apr 28, 2012.

  1. #1
    hi
    i want to add multiply categories to my website.Now i can only add movie to one category.
    the database build that way:
    -i have categories table that contains only the names of the categories.
    -in the video table i have a column that contains the name of the category and the script fetches the videos by the category.

    how can i add more categories to the movie so i could add video to several categories...
    anyone have idea?is there any way to fetch only videos with specific category?
     
    lonely88, Apr 28, 2012 IP
  2. Oli3L

    Oli3L Active Member

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    70
    #2
    hm.. you can just seperate with commas "," and then when you call the video from database, split the commas.
     
    Oli3L, Apr 28, 2012 IP
  3. lonely88

    lonely88 Well-Known Member

    Messages:
    328
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #3
    i thought so too but how i can retrive it after that ,from mysql i mean...
    the video table build like that :
    id|name|description|code|link1|link2|link3|thumb|category|statusv|views|votes|rpoints|featured|queued|dateadded

    you mean i add the categories like this:category1,category2,category3,.....?
     
    Last edited: Apr 28, 2012
    lonely88, Apr 28, 2012 IP
  4. Oli3L

    Oli3L Active Member

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    70
    #4
    yes, or you can also use serialize() and unserialize(). put the categories IDs (or names) in an array ( $cats = array(name1, name2) ) and the use serialize($cats) so store it in the DB, and unserialize($cats) when you read it.
    you can also create more database fields to the video table.
     
    Oli3L, Apr 28, 2012 IP
  5. lonely88

    lonely88 Well-Known Member

    Messages:
    328
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #5
    i tried to split them like that:
    $queryrr=mysql_query("Select category from videos");
    while($rowpad=mysql_fetch_array($queryrr)){
    foreach ($rowpad as $wtf){
    $puke = explode(',',$wtf);
    echo $puke[$j];
    }


    how can i count the the number of the lines fetched from the database?
     
    lonely88, Apr 28, 2012 IP
  6. Oli3L

    Oli3L Active Member

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    70
    #6
    you forgot to close the while/foreach loop.

    does it work though?

    EDIT:
    this is wrong. let me fix it.

    $queryrr=mysql_query("Select category from videos");
    while($rowpad=mysql_fetch_array($queryrr)){
        foreach ($rowpad as $wtf){
            $categories = explode(',',$wtf); 
            // Now the categories are inside $categories. use foreach to read them.
        }
    }
    
    
    // you can read them like this:
    foreach($categories as $catid) {
        // $catid = the category id/name
    }
    
    PHP:
     
    Oli3L, Apr 28, 2012 IP
  7. lonely88

    lonely88 Well-Known Member

    Messages:
    328
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #7
    yes but what will it give me to add more database fields?isnt it will be waste?
     
    lonely88, Apr 28, 2012 IP
  8. lonely88

    lonely88 Well-Known Member

    Messages:
    328
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #8
    i want after the retrive of the category fetch all the videos in this category...look at this please:
    
    $queryrr=mysql_query("Select category from videos");
    while($rowpad=mysql_fetch_array($queryrr)){
        foreach ($rowpad as $wtf){
            $categories = explode(',',$wtf); 
            // Now the categories are inside $categories. use foreach to read them.
        }
    }
    
    
    // you can read them like this:
    foreach($categories as $catid) {
       if($catid == $preca){
                     $queryr=mysql_query("Select * from videos where status='active' and queued='' and category='$catid'  and featured='$featured' $outin ORDER BY id desc limit $start,$tvideos ");
                   }else{
                         echo"|";
    PHP:
    its not really working i get only one line from the database...i dont really get why?can you please explain it to me?
    how can i fetch the videos using the categories?
     
    Last edited: Apr 28, 2012
    lonely88, Apr 28, 2012 IP