Ask for a PHP call code

Source: Internet
Author: User
Look at the picture and talk.

Suppose the above is a table:
The table contains information ID and user UID and a specific PID

How to determine the PID of other bar information when looping the loop call variable (the red box is the ID of the current information)

When I call, I judge.

{Loop $list} ... {if $id = = $pid} .... {/if} ..... {/loop}


is judged to be the current information ID is the same as the PID. The key is that the PID and ID are definitely not in the information data of an ID, the PID is for the ID

The code, that's what I wrote.


{/loop}


The results shown are
1-8-25
2-3-36
3-12-1
It's not wrong. Output correct

I want the result that the third PID is equal to the ID of the first one to show him below the first one.
How to write code, to be free


Reply to discussion (solution)

In fact, I wrote a message.
The ID is the message ID used for the deletion of information, the UID is the author ID of the message, as well as the message content, time and other fields will not say.

The most important is the PID, is automatically generated, is to give the first few information reply,

I'd like to leave a message with a message ID of 1 and let him display it under this message. Do not know how to operate. Hey

Two arrays, an array a (key value is ID) sorted by ID, and an array b sorted by PID (the key value is PID).
A array of key values: 1, 2, 3, 6, 8 ...
B Array Key value: 1, 3, 34, 35 ...
Each time the data is taken from the beginning of the two array, a pointer is taken to 1 output, then the first of B, and 1, output. The second one refers to the 2 output, B Gets the discovery is 3, does not output. Again take a 3 output, see B again, found also 3 output.

Array sorting is carried out using PHP's own method of complexity of about O (NLGN), traversing two array complexity O (n).

Two arrays, an array a (key value is ID) sorted by ID, and an array b sorted by PID (the key value is PID).
A array of key values: 1, 2, 3, 6, 8 ...
B Array Key value: 1, 3, 34, 35 ...
Each time the data is taken from the beginning of the two array, a pointer is taken to 1 output, then the first of B, and 1, output. The second one refers to the 2 output, B Gets the discovery is 3, does not output. Again take a 3 output, see B again, found also 3 output.

Array sorting is carried out using PHP's own method of complexity of about O (NLGN), traversing two array complexity O (n).




Each message contains ID and PID this loop is good but the PID is also read when the key is the ID

{loop $list $val} comment {$val [' id ']}{loop $list $val 1}{if $val [' id ']== $val 1[' pid '} reply comment {$val [' id '} ' comment {/if}{/loop}{/loop }

Not tested, you can see.

$SQLSTR = "SELECT * FROM table", $query = mysql_query ($sqlstr) or Die (Mysql_error ()), while ($thread =mysql_fetch_assoc ($ Query) {    $result [] = $thread;} foreach ($result as $key + $val) {    if (isset ($ret [$val [' pid]]) {Array_push ($ret [$val [        ' pid ']], $val);    } else{        $ret [$val [' pid ']] = array ($val);}    } Print_r ($ret);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.