Results 1 to 7 of 7

Thread: Store multiple value in single column

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Store multiple value in single column

    Hi..guys! I have a column which need to store multiple time value,like 11:00am,2:00pm,5:30pm.How can that single column fix it?And how to control time format in between 12-hours and 24-hours format?Thanks....

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You have several options: you can store it as a list of comma-separated values, like you have there; you can store it as a string storing a serialised array from whatever language you're using to interact with the database (e.g. PHP's serialize() or Python's pickle module) or you can create two new tables and have a many-to-many relationship between the rows in that table and a special "times" table.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for helping.I am using first option and create an extra column,screeningTime with varchar type.How can I display each of its value accompany by a radio button in PHP?Thanks...

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <form action="">
    <?php foreach(explode(',', $row['screeningTime']) as $time) { ?>
      <label>
        <input type="radio" value="<?php echo $time; ?>">
        <?php echo $time; ?>
      </label>
    <?php } ?>
    </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for reply.Let said now I have seven rows of record need to be fetched out,how can it be achieved?

    I try $result = mysql_query("SELECT name,category,screeningTime FROM $tbl_name WHERE id < 8") but seems like look weird.How can I manipulate each id's name,category and screeningTime be fetched and displayed properly?

    PHP Code:
    <?
    if (isset($_SESSION['gmemberid'])) {
        
    $tbl_name "movie";

        
    $result mysql_query("SELECT name,category,screeningTime FROM $tbl_name 
                               WHERE id ='1'"
    )
                                or die(
    "Cannot execute query.");

        
    $numrow mysql_num_rows($result);

        if (
    $numrow != 0) {
            while(
    $rows mysql_fetch_array($result)){
                echo 
    '<strong><br>' $rows[0] .' (' $rows[1] .') </strong></font>';
                foreach(
    explode(',',$rows[2])as $time) {?>
                <br><br><label>
                <input type="radio" value="<?php echo $time?>">
                <?php echo $time?>
              </label>
              </td></tr>
             <?php ?>
    <?                
             
    }     
                
            }
         }     
    ?>

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php
      $tbl_name = 'movie';
      $rs = mysql_query(sprintf('select name, category, screeningTime from %s limit 7', $tbl_name))
        or die(sprintf('Cannot execute query: %s', mysql_error()));
    
      while($row = mysql_fetch_array($rs))
        foreach(explode(',', $row['screeningTime']) as $time) {
    ?>
    <label>
      <input type="radio" value="<?php echo $time; ?>">
      <?php echo $time; ?>
    </label>
    <?php } ?>
    Using <br> there is most probably an abuse of the element. Use CSS instead. The <font> tag is deprecated.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for helping,by now I would like to submit the form after clicking one of the radio button.How can the selected screeningTime and its movie name being captured by $_POST?Really appreciate for your initiative.

    PHP Code:
    <?
    if (isset($_SESSION['gmemberid'])) {
        
    $tbl_name "movie";

        
    $result mysql_query(sprintf('SELECT name,category,screeningTime FROM %s
                 LIMIT 7'
    $tbl_name)) or die('Cannot execute query.');

        
    //$numrow = mysql_num_rows($result);


        
    while ($rows mysql_fetch_assoc($result)) {
            echo 
    '<table width="100%" border="0"><tr><td height="68">
                      <table width="100%" height="47" border="0">
                       ---------------------------------------------------------------------------------------------------------<br>'
    ;

            echo 
    '<strong>' $rows['name'] . ' (' $rows['category'] . ')
                     <br></strong>'
    ;
            foreach (
    explode(','$rows['screeningTime']) as $time) { ?>
                <label>
                <input type="radio" value="<?php echo $time?>">
                <?php echo $time?>&nbsp;&nbsp;&nbsp;
                </label>
                <?php ?>
    <?
        
    }


    }
    ?>

Bookmarks

Posting Permissions

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