SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 30

Thread: 2 questions

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 questions

    Hi,
    I have 2 things
    1) In ASP, we have a Gridview through which we can show a table. Do we have this in PHP? Is there an example if yes?
    2) For example we have a shown field in the screen like this. How can we make it refer to a table column in the database or how can we make it take the value of a table column in there?

    <tr>
    <td>Party</td>
    <td align=left><select name="party" size="1" id="party">
    <option selected>OK</option>
    <option>Not OK</option>
    </select></td>
    </tr>
    Many Thanks & Best Regards,
    HuaMin Chen

  2. #2
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    North Richmond
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to establish connection with the database then do a query that calls all the data you are requiring and then display it.

    For the second question in relation to the field reference back to the database, you need to add a "value" attribute to the options

    E.g.
    Code php:
    <?php
    echo "<tr>
       <td>Party</td>
       <td align=left>
          <select name='party' size='1' id='party'>
             <option value='ok'>OK</option>
             <option value='notOk'>Not OK</option>
          </select>
       </td>
    </tr>";
    ?>
    If you send this data via $_POST, then to collect the information and place into a variable, you then use:
    Code php:
    <?php
    $party = $_POST['party'];
    // the $_POST['party'] value will collect the value of whatever 
    // option the user selected
    ?>
    This variable is then entered into a query back to the database using the syntax by whatever database engine you are using.

    I hope this has answered your question. If not, please clarify further details and I will try to answer it better for you.
    Regards,
    BJ Duncan

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    .Net is a framework - therefore a massive majority of its objects and all of its components aren't built into the language, but instead into a framework integrated into the language.

    Because of this, no languages actually supply such things as gridviews. Instead you can either write a component in PHP or find a framework out there which caters to your needs.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks to all of you. Jake, is there any framework like that, to which we can refer?
    Last edited by HuaMin; May 3, 2009 at 19:05.
    Many Thanks & Best Regards,
    HuaMin Chen

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Duncan, thanks.
    For instance, we have a name for the field. Can we assign a value to that when loading the page? In ASP, we do have a 'page_load' event in code-behind and we can do this inside that. How can do this in PHP?

    <tr>
    <td>IDNo</td>
    <td align=left><input type="text" IDNo="IDNo" id="IDNo" size=15 maxlength=6"></td>
    <td><div id=IDNoHint></div></td>

    </tr>
    Many Thanks & Best Regards,
    HuaMin Chen

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP works very different to ASP.Net. Whilst PHP outputs HTML, ASP.Net stores the output as XML and would apply that function to the XML before outputting.

    You could do it that with PHP, but again you'd have a framework doing that for you (like ASP.Net uses natively). I don't know of any frameworks that do this, because I don't work with external frameworks personally.

    However, the simple approach to what you want is:
    PHP Code:
    <tr>
    <td>IDNo</td>
    <td align=left><input type="text" IDNo="IDNo" id="IDNo" value="<?php echo $theValue?>" size=15 maxlength=6"></td>
    <td><div id=IDNoHint></div></td>
    </tr>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks. What's the usual way for that we're retrieving a list of records (for a detail subset in a master/detail relationship)? Do we still use the similar way like what you've suggested?
    Many Thanks & Best Regards,
    HuaMin Chen

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do think that by 'PHPLensConnect' we can call a query and further we can call a Gridview-like object. Am I right?
    Last edited by HuaMin; May 7, 2009 at 00:51.
    Many Thanks & Best Regards,
    HuaMin Chen

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For example we can retrieve the column values to a variable like the following codes. But I don't have the ideas for the way by which we retrieve the column values to the detail group of a master/detail relationship.

    $sql="SELECT distinct TOP 5 name FROM tab_a where type='".$q[0]."' and class='".$q[1]."' and name like '".$q[2]."&#37;' order by name";
    $rst = odbc_exec($con, $sql);
    while($row = odbc_fetch_array($rst)) {
    echo $row['name']." " ;
    Last edited by HuaMin; May 8, 2009 at 00:37.
    Many Thanks & Best Regards,
    HuaMin Chen

  10. #10
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm afraid you're going to have to rephrase your question - I don't know what you're asking.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  11. #11
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean how to retrieve the data to the detail group for displaying a master/detail relationship.

    http://www.sitepoint.com/ is very good to some extents but it's not the best, for solving PHP questions.(Some other sites I used nearly have nothing responded!) I think it's not easy to quickly have any responses for PHP. Any advice?
    Last edited by HuaMin; May 12, 2009 at 23:43.
    Many Thanks & Best Regards,
    HuaMin Chen

  12. #12
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any advice?
    Many Thanks & Best Regards,
    HuaMin Chen

  13. #13
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    What is a master/detail relationship? Could you please post the tables and associations because I don't really understand what your talking about.

  14. #14
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ^ My thoughts exactly.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  15. #15
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For instance, the master table is for the employee record and the detail table is the employee's In/Out records. Can we show them together inside one page?
    Many Thanks & Best Regards,
    HuaMin Chen

  16. #16
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You mean like the dates and times an employee punches in and out from work? The sql and php code will depend on your database structure. Show the table structures, along with a few relevant sample rows of data for each table. Then give us an idea of what type of html output you're looking for.

  17. #17
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's like

    Employee ID 20003
    Employee Name Peter
    Position Accountant

    Date In Time Out Time
    12/05/2009 09:03 AM 06:32 PM
    13/05/2009 09:01 AM 06:42 PM
    ...

    Can we show these in one web page?
    Many Thanks & Best Regards,
    HuaMin Chen

  18. #18
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    Based on that schema no because there isn't a way to relate a employee to their clock-in and clock-out times. What do the actual tables look like?

    Seems like the most appropriate schema would involve three tables:

    employees
    • id (primary key)
    • name
    • account


    clock_ins
    • id (primary key)
    • employee_id (references employees(id))
    • created



    clock_outs
    • id (primary key)
    • clock_in_id (references clock_ins(id))
    • created
    • unique key(clock_in_id)


    You can't clock out without clocking in.

  19. #19
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean to show the info of the 2 tables together in one web page. Is there an example for this?

    I don't need more info for the tables but the way to handle this in PHP!
    Last edited by HuaMin; May 14, 2009 at 02:08.
    Many Thanks & Best Regards,
    HuaMin Chen

  20. #20
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not with your above schema.

    Without an employee ID in the clocking table, there is no way of knowing who is clocking in or out.

    If, however, there's a field for EmployeeID, you can with a simple inner join.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  21. #21
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I need the way to do in PHP.

    Ok let's go further with this example. Let employee ID be the linking key in both master/detail tables. Any further advice?
    Last edited by HuaMin; May 14, 2009 at 20:04.
    Many Thanks & Best Regards,
    HuaMin Chen

  22. #22
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    You can't From what you've posted your schema is not set-up to support this type of relationship.

  23. #23
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As I'm urgent to have more details for the way, pls accept my apology. Can we now see further for the way from the tables?
    Many Thanks & Best Regards,
    HuaMin Chen

  24. #24
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    The tables need a way to relate to each other.

    A user has many work records.

    Therefore, inside the work records table there should be a key that identifies a unique user. This is called a foreign key and is responsible for relating a user to the specific work record.

    users
    -- id (primary key identifies unique user)

    work_records
    -- user_id identifies user which this record corresponds

    That is all that is needed to relate a user to a work record and vice versa.

    The SQL would then have a similar structure to the below to select all users and their work records given the two table relationship described above.

    Code SQL:
    SELECT
        t1.id AS user_id
     FROM
        users AS t1
     LEFT
     JOIN
        work_records AS t2
       ON
         t1.id = t2.user_id

    However, I recommended this structure because you can't clock out without clocking in. The structure represented in that post supports the notion that a clock-out is dependent on a clock-in. While the structure shown in this post does not.

  25. #25
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    China
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks. From the coding, we can further prevent the case, i.e., for each day, there should be one clock-in first before any clock-out. For instance, to disallow any input of clock-out record before any clock-in on the same day. This can be easily controlled by the coding from the input. Can we go further now?

    Is the road I expect to have, a very very hard way to go?

    Can anyone show me the way I expect to have?
    Last edited by HuaMin; May 14, 2009 at 23:44.
    Many Thanks & Best Regards,
    HuaMin Chen


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
  •