Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Categories Problem

    i need ur help i put category id in my articles table and use that id to find the name of the category and display but i dont know hot to select multiple categories and insert it into database and show selected categories to users from database.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    We need context. So far we know nothing about your code, what you've done, what you've triend, and what the issue is. You need to actually give up more then a one line description, including stuff like code and database schema.

  • #3
    New Coder
    Join Date
    Aug 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    This is my category list php code to display categories if selected and if not than display list to select

    PHP Code:
    function categorylist($selected) {
        
    $cq mysql_query("SELECT * FROM some_categories ORDER BY cat_order ASC");
        while(
    $ca mysql_fetch_array($cq)) {
            if (
    $ca['id'] == $selected) {
                echo 
    '<option value="'.$ca['id'].'" selected>'
            }
            else {
                echo 
    '<option value="'.$ca['id'].'">';
            }
            if (
    $ca['parent_id'] != 0) {
                echo 
    ' &nbsp; &nbsp;';
            }
            echo 
    $ca['name'].'</option>'
           }

    this is form to add games

    PHP Code:
    <div class="add_game_form_container">
    <form id="form1" name="form1" method="post" action="includes/edit_game_submit.php">
    <div class="form_element_container">
       <div class="form_lable">
       <label>Game name</label></div>
       <div class="form_element"><input class="text_box" name="game_name" type="text" id="game_name0"/></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Description</label></div>
       <div class="form_element"><textarea class="text_area" name="game_description" id="game_description0"></textarea></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>How to play</label></div>
       <div class="form_element"><textarea class="text_area" name="game_instructions" id="game_instructions0"></textarea></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable">
       <label>Tags</label></div>
       <div class="form_element"><input class="text_box" name="game_tags" type="text" id="game_tags0"/></div>
    </div>
      
    <div class="form_element_container">
       <div class="form_lable"><label>File</label></div>
       <div class="form_element">
          <a href="#" onclick="file_selector(3, 0, 0);return false" id="enter_url_link0" class="bold">Enter URL</a> | <a href="#" onclick="file_selector(2, 0, 0);return false" id="select_link0">Select from games folder</a> | <a href="#" onclick="file_selector(1, 0, 0);return false" id="upload_link0">Upload file</a> | <a href="#" onclick="file_selector(4, 0, 0);return false" id="grab_link0">Grab file</a>
          <div id="file_selection0"><input name="url" type="text" class="text_box" id="url0" /></div>
       </div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Image</label></div>
       <div class="form_element">
          <a href="#" onclick="image_selector(3, 0, 0);return false" id="enter_url_link_image0" class="bold">Enter URL</a> | <a href="#" onclick="image_selector(2, 0, 0);return false" id="select_link_image0">Select from images folder</a> | <a href="#" onclick="image_selector(1, 0, 0);return false" id="upload_link_image0">Upload image</a> | <a href="#" onclick="image_selector(4, 0, 0);return false" id="grab_link_image0">Grab image</a>
          <div id="image_selection0"><input name="url" type="text" class="text_box" id="img0" /></div>
       </div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Dimensions</label></div>
       <div class="form_element"><input name="width" type="text" class="text_box_dimensions" id="width0" size="3" /> x <input name="height" type="text" class="text_box_dimensions" id="height0" size="3" /> (<a href="#" onclick="GetDimensions(0);return false">Auto</a>)
       </div></div>

    <div class="form_element_container">
       <div class="form_lable"><label for="categories[]">Category</label></div>
       <div class="form_element"><select multiple="multiple" name="categories[]" id="category0">
       <?php categorylist(0); ?>
       </select></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Advert</label></div>
       <div class="form_element"><select name="advert" id="advert0">
       <?php $cq mysql_query("SELECT * FROM some_ads ORDER BY id ASC");
        echo 
    '<option value="0">None</option><option value="1" selected>Sitewide default</option>';
        while(
    $ca mysql_fetch_array($cq)) {
            if (
    $ca['id'] != 1)    
               echo 
    '<option value="'.$ca['id'].'">'.$ca['ad_name'].'</option>'
       }
    ?>
       </select></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Highscores</label></div>
       <div class="form_element">
               <input type="checkbox" name="highscores" value="1" id="highscores0">
       </div>
    </div>

    <div class="form_element_container">
       <div class="form_lable">
       <label>Mochi game tag</label></div>
       <div class="form_element"><input class="text_box" name="mochi_id" type="text" id="mochi_id0" value=""/></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Published</label></div>
       <div class="form_element">
               <input type="checkbox" name="published" value="1" id="published0" checked="checked">
       </div>
    </div>

    <div class="form_element_container">
       <div class="form_lable">
       <label>Submitter ID</label></div>
       <div class="form_element"><input class="text_box_id" name="submitter" type="text" id="submitter0" /></div>
    </div>

    <input name="id" type="hidden" value="0" id="id0" />
    <div class="button_container"><input class="button" name="Submit" type="button" value="Submit" id="submit0" onclick="SubmitGame(0);" /></div>
    </form>
    </div>
    this the funcltion to add data to database

    PHP Code:
    $category mysql_fetch_array(mysql_query("SELECT parent_id FROM some_category WHERE id = $_POST[game_category]"));

    $category1 implode(',' $_POST["categories"]);
    $category2 explode(',' $category2);

    if (
    $_POST['id'] == 0) {
        
    $date date("Y-m-d H:i:s");
        
    $seo_url create_seoname($name0'game');


            
    mysql_query("INSERT INTO ava_games (name, description, url, category_id, category_parent, width, height, image, published, filetype, instructions, date_added, advert_id, highscores, mochi_id, seo_url, submitter)
        VALUES ('"
    .escape($_POST['game_name'])."', '".escape($_POST['game_description'])."', '$url', $category2, $category[parent_id], '$_POST[width]', '$_POST[height]', '$img', $_POST[published], '$ext', '".escape($_POST['game_instructions'])."', '$date', $_POST[game_advert], $_POST[highscores], '$_POST[mochi_id]', '$seo_url', '$_POST[submitter]')") or die ('There was a MySql error when adding the game: '.mysql_error());

        
    $newid mysql_insert_id();

        
    $category mysql_query("SELECT * FROM some_category WHERE id=".$_POST['game_category']."");
        
    $category mysql_fetch_array($category); 
    and now how to add data to database and display it.
    i assign multiple categories and when added to database it shows an error and when i add category id in games table it shows error while displaying multiple categories plz help.

    PHP Code:
    this code to display categories

    $query 
    mysql_query("SELECT * FROM some_games WHERE $where ORDER BY id DESC LIMIT $limit");

    while (
    $go mysql_fetch_array($query)) 
    {

    $category mysql_query("SELECT * FROM some_cats WHERE id=".$go['category_id']."");
    $categorya mysql_fetch_array($category);

    $url GameUrl($go['id'], $go['seo_url'], $go['category_id']);

    if (isset(
    $_GET['id']) && $_GET['id'] == $go['id']) {
        
    $class 'manage_item_extended';
    }
    else {
        
    $class 'manage_item';
    }

    echo 
    '
    <div id="game-'
    .$go['id'].'" class="'.$class.'"><div class="manage_column0">'.$go['id'].'</div><div id="tgame_name'.$go['id'].'" class="manage_column"><a href="'.$url.'" class="manage_link">'.$go['name'].'</a></div><div id="tcategory_name'.$go['id'].'" class="manage_column2"><a href="#page=1&cat='.$categorya['id'].'">'.$categorya['name'].'</a></div>

    <div class="manage_column3" id="edit-image-'
    .$go['id'].'">'
    and this code to display games in categories

    PHP Code:
    $category_games mysql_query("SELECT * FROM some_games WHERE (category_id = $row[id] OR category_parent = $row[id]) AND published=1 ORDER BY $order LIMIT ".$template['homepage_game_limit']."");
        
    while(
    $cat_games mysql_fetch_array($category_games)) {
        
    $game GameData($cat_games'homepage'); 

  • #4
    New Coder
    Join Date
    Aug 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by dineshjumani View Post
    This is my category list php code to display categories if selected and if not than display list to select

    PHP Code:
    function categorylist($selected) {
        
    $cq mysql_query("SELECT * FROM some_categories ORDER BY cat_order ASC");
        while(
    $ca mysql_fetch_array($cq)) {
            if (
    $ca['id'] == $selected) {
                echo 
    '<option value="'.$ca['id'].'" selected>'
            }
            else {
                echo 
    '<option value="'.$ca['id'].'">';
            }
            if (
    $ca['parent_id'] != 0) {
                echo 
    ' &nbsp; &nbsp;';
            }
            echo 
    $ca['name'].'</option>'
           }

    this is form to add games

    PHP Code:
    <div class="add_game_form_container">
    <form id="form1" name="form1" method="post" action="includes/edit_game_submit.php">
    <div class="form_element_container">
       <div class="form_lable">
       <label>Game name</label></div>
       <div class="form_element"><input class="text_box" name="game_name" type="text" id="game_name0"/></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Description</label></div>
       <div class="form_element"><textarea class="text_area" name="game_description" id="game_description0"></textarea></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>How to play</label></div>
       <div class="form_element"><textarea class="text_area" name="game_instructions" id="game_instructions0"></textarea></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable">
       <label>Tags</label></div>
       <div class="form_element"><input class="text_box" name="game_tags" type="text" id="game_tags0"/></div>
    </div>
      
    <div class="form_element_container">
       <div class="form_lable"><label>File</label></div>
       <div class="form_element">
          <a href="#" onclick="file_selector(3, 0, 0);return false" id="enter_url_link0" class="bold">Enter URL</a> | <a href="#" onclick="file_selector(2, 0, 0);return false" id="select_link0">Select from games folder</a> | <a href="#" onclick="file_selector(1, 0, 0);return false" id="upload_link0">Upload file</a> | <a href="#" onclick="file_selector(4, 0, 0);return false" id="grab_link0">Grab file</a>
          <div id="file_selection0"><input name="url" type="text" class="text_box" id="url0" /></div>
       </div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Image</label></div>
       <div class="form_element">
          <a href="#" onclick="image_selector(3, 0, 0);return false" id="enter_url_link_image0" class="bold">Enter URL</a> | <a href="#" onclick="image_selector(2, 0, 0);return false" id="select_link_image0">Select from images folder</a> | <a href="#" onclick="image_selector(1, 0, 0);return false" id="upload_link_image0">Upload image</a> | <a href="#" onclick="image_selector(4, 0, 0);return false" id="grab_link_image0">Grab image</a>
          <div id="image_selection0"><input name="url" type="text" class="text_box" id="img0" /></div>
       </div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Dimensions</label></div>
       <div class="form_element"><input name="width" type="text" class="text_box_dimensions" id="width0" size="3" /> x <input name="height" type="text" class="text_box_dimensions" id="height0" size="3" /> (<a href="#" onclick="GetDimensions(0);return false">Auto</a>)
       </div></div>

    <div class="form_element_container">
       <div class="form_lable"><label for="categories[]">Category</label></div>
       <div class="form_element"><select multiple="multiple" name="categories[]" id="category0">
       <?php categorylist(0); ?>
       </select></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Advert</label></div>
       <div class="form_element"><select name="advert" id="advert0">
       <?php $cq mysql_query("SELECT * FROM some_ads ORDER BY id ASC");
        echo 
    '<option value="0">None</option><option value="1" selected>Sitewide default</option>';
        while(
    $ca mysql_fetch_array($cq)) {
            if (
    $ca['id'] != 1)    
               echo 
    '<option value="'.$ca['id'].'">'.$ca['ad_name'].'</option>'
       }
    ?>
       </select></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Highscores</label></div>
       <div class="form_element">
               <input type="checkbox" name="highscores" value="1" id="highscores0">
       </div>
    </div>

    <div class="form_element_container">
       <div class="form_lable">
       <label>Mochi game tag</label></div>
       <div class="form_element"><input class="text_box" name="mochi_id" type="text" id="mochi_id0" value=""/></div>
    </div>

    <div class="form_element_container">
       <div class="form_lable"><label>Published</label></div>
       <div class="form_element">
               <input type="checkbox" name="published" value="1" id="published0" checked="checked">
       </div>
    </div>

    <div class="form_element_container">
       <div class="form_lable">
       <label>Submitter ID</label></div>
       <div class="form_element"><input class="text_box_id" name="submitter" type="text" id="submitter0" /></div>
    </div>

    <input name="id" type="hidden" value="0" id="id0" />
    <div class="button_container"><input class="button" name="Submit" type="button" value="Submit" id="submit0" onclick="SubmitGame(0);" /></div>
    </form>
    </div>
    this the funcltion to add data to database

    PHP Code:
    $category mysql_fetch_array(mysql_query("SELECT parent_id FROM some_category WHERE id = $_POST[game_category]"));

    $category1 implode(',' $_POST["categories"]);
    $category2 explode(',' $category2);

    if (
    $_POST['id'] == 0) {
        
    $date date("Y-m-d H:i:s");
        
    $seo_url create_seoname($name0'game');


            
    mysql_query("INSERT INTO ava_games (name, description, url, category_id, category_parent, width, height, image, published, filetype, instructions, date_added, advert_id, highscores, mochi_id, seo_url, submitter)
        VALUES ('"
    .escape($_POST['game_name'])."', '".escape($_POST['game_description'])."', '$url', $category2, $category[parent_id], '$_POST[width]', '$_POST[height]', '$img', $_POST[published], '$ext', '".escape($_POST['game_instructions'])."', '$date', $_POST[game_advert], $_POST[highscores], '$_POST[mochi_id]', '$seo_url', '$_POST[submitter]')") or die ('There was a MySql error when adding the game: '.mysql_error());

        
    $newid mysql_insert_id();

        
    $category mysql_query("SELECT * FROM some_category WHERE id=".$_POST['game_category']."");
        
    $category mysql_fetch_array($category); 
    and now how to add data to database and display it.
    i assign multiple categories and when added to database it shows an error and when i add category id in games table it shows error while displaying multiple categories plz help.

    PHP Code:
    this code to display categories

    $query 
    mysql_query("SELECT * FROM some_games WHERE $where ORDER BY id DESC LIMIT $limit");

    while (
    $go mysql_fetch_array($query)) 
    {

    $category mysql_query("SELECT * FROM some_cats WHERE id=".$go['category_id']."");
    $categorya mysql_fetch_array($category);

    $url GameUrl($go['id'], $go['seo_url'], $go['category_id']);

    if (isset(
    $_GET['id']) && $_GET['id'] == $go['id']) {
        
    $class 'manage_item_extended';
    }
    else {
        
    $class 'manage_item';
    }

    echo 
    '
    <div id="game-'
    .$go['id'].'" class="'.$class.'"><div class="manage_column0">'.$go['id'].'</div><div id="tgame_name'.$go['id'].'" class="manage_column"><a href="'.$url.'" class="manage_link">'.$go['name'].'</a></div><div id="tcategory_name'.$go['id'].'" class="manage_column2"><a href="#page=1&cat='.$categorya['id'].'">'.$categorya['name'].'</a></div>

    <div class="manage_column3" id="edit-image-'
    .$go['id'].'">'
    and this code to display games in categories

    PHP Code:
    $category_games mysql_query("SELECT * FROM some_games WHERE (category_id = $row[id] OR category_parent = $row[id]) AND published=1 ORDER BY $order LIMIT ".$template['homepage_game_limit']."");
        
    while(
    $cat_games mysql_fetch_array($category_games)) {
        
    $game GameData($cat_games'homepage'); 
    help plz its urgent


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •