English 中文(简体)
虽然在休息和生产期间休息时间,但地点和产出如何?
原标题:While loops within while loops and output php?

在我网站上张贴一个职位的答复时,我有一席之地。

查询中使用的括号内数字是员额(ID)的数值,这是所观察员额的一系列细节。

如下文所示,产出如下(每个主题都与职位全数挂钩)。

$q = $dbc -> prepare("SELECT * FROM boardposts WHERE parentID = ?");
$q -> execute(array($post[ postID ]));
while ($postReply = $q -> fetch(PDO::FETCH_ASSOC)) {
     echo  <p><a href="http://www.example.com/boards?topic=  . $_GET[ topic ] .  &amp;view=  . $postReply[ postID ] .  ">  . $postReply[ subject ] .  </a> ;
}

目前的产出大致如下:

Replies To This Message:

subject 1
subject 2
subject 3
subject 4

我也可在名单上列入对答复的答复,内容大致如下:

Replies To This Message:

subject 1
         subject 1 reply
         subject 1 reply
                 subject 1 reply reply
subject 2
subject 3
         subject 3 reply
         subject 3 reply
                 subject 3 reply reply
subject 4
         subject 4 reply
subject 5
subject 6
         subject 6 reply
                 subject 4 reply reply

I understand all the indenting can be with css, but am stuck as to how to pull the data from the mysql database and in the correct order, I tried while loops within while loops, but that involved queries inside while loops, which is bad!

感谢你们的投入!

问题回答

我怀疑你需要做些什么是重新设计你的数据库,以储存一个领域的深层/重要关系,以便你能够把所有线子从一个电线上拉开,然后将其从方案上划入一个站点。 如果你有一个亲爱的领域,每个答复人都知道其父母是谁,其命令是什么(一般说来,命令是粗略的,以前是过错),那么,按照你们的需要,组织起来非常简单。

然后,你可以去做答复清单,把所有物品扔到JSON(y)。 您在正确命令/关系中作出的所有答复。

为了减少不想要的血压,你可能还要储存最高级的母子,以便你能够轻松地把那些属于特定顶层线的read子拉开。 这样,你就能够轻松地 gr掉最后20个顶层层的read子(从而减少在无人需要的古老read子上的不必要的计算,并建造某种ag子)。

EDIT... some pseudo code...

select* fromrow order by high_level_id desc limit 0,20 这将使你拥有20个最高层的镜子,因此,你不再把整个 d子拉开。 归根结底,0应为你从PHP中转出的页数,因此,第2页和第3页第4020页。

现在,你做的是这样的事情(显然,这是假装的法典,但你应该能够根据这一模式这样做......)。

$sortedRows; //this will be a JSON object, or hash array

for($row in result){
   addToThreadObj($row);
}

function addToThreadObj($row){
    if( containsParent($row.parent_id))
         addChildToParent($row.parent_id, $row);
    else
         createNewParent($row);
}




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签