The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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?

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?

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.

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']." " ;

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?

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.

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
LEFTJOIN
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.

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?