mysql结果< - 上一行和下一行,显示下一个确定 [英] mysql results <-- previous row, and next row, showing next ok
问题描述
任何人都可以帮忙吗?
我查询数据库并在列引用上返回结果。
可能有7个列表。每行显示在一个表格中,
链接到详细信息页面。我正在制作一个之前的
记录和一个下一个记录。在详细信息页面上记录链接。
以下代码适用于下一个记录,通过在数组$ myarray中搜索变量$ ref的值
。然后它返回键值
值和键值,作为一个数字,扣除一个加上'
一个给我前一行和下一行。
返回下一行的值可以处理,但出于某种原因
前一行,扣除1,而它回显一个值屏幕,没有工作。
我会感激任何反馈,任何帮助。对于一个
的新手来说,这是一个挑战。
这是代码:
(查询数据库然后:)
// $ ref是一个进入页面的变量
$ num_rows = mysql_num_rows($ result2);
$ i = 0;
while($ i< $ num_rows){
$ next = mysql_result($ result2, $ i," reference");
++ $ i;
$ myarray = array(" $ i" => ;" $ next");
foreach($ myarray as $ key => $ value){
if($ value ==" $ ref") {
$ b =($ key);
$ c =($ key + 1);
$ a = ($ key-1);
}}
if($ a ==" 0"){
echoNo Preceding Record;
} else {
if($ key ==" $ a")echo"< ;
href = .. / detail / index.php?name = $ value>上一条记录< / a>";
}
if($ key ==" $ b")e cho这是当前的记录;
if($ num_rows< $ c){
echo" Records End" ;;
} else {
if($ key ==" $ c") echo"< a href = .. / detail / index.php?name = $ value> Next
Record< / a>" ;;
}
}
}其他{
echo"抱歉,未找到任何记录" ;;
}
?>
Can anyone help?
I query a database and return a result on the column "reference".
There might be 7 listings. Each row is displayed in a table, with
links through to a detail page. I am working on having a "previous"
record and a "next" record link on the detail page.
This code below works, for the "next" record, by searching the values
in the array $myarray for the variable $ref. It then returns the key
value and the key value, as a number, is deducted by one and plus''d by
one to give me the previous row and the next row.
Returning the value of the next row works a treat, but for some reason
the previous row, deduct 1, while it echoes a value to screen, doesn''t
work.
I''d appreciate any feedback, any help. It''s been a challenge for a
newbie to sort this out.
This is the code:
(query database and then:)
//$ref is a variable carried into the page
$num_rows = mysql_num_rows($result2);
$i=0;
while ($i < $num_rows) {
$next=mysql_result($result2,$i,"reference");
++$i;
$myarray = array("$i"=>"$next");
foreach($myarray as $key=>$value) {
if ($value == "$ref"){
$b=($key);
$c=($key+1);
$a=($key-1);
}}
if ($a == "0") {
echo "No Preceding Record";
} else {
if ($key == "$a") echo "<a
href=../detail/index.php?name=$value>Previous Record</a>";
}
if ($key == "$b") echo "This is the current Record";
if ($num_rows < $c) {
echo "Records End";
} else {
if ($key == "$c") echo "<a href=../detail/index.php?name=$value>Next
Record</a>";
}
}
} else {
echo "Sorry, no records were found";
}
?>
推荐答案
变量的myarray
myarray for the variable
REF。然后它返回键值
值和键值,作为一个数字,扣除一个加上'
一个给我前一行和下一行。
返回下一行的值可以处理,但出于某种原因
前一行,扣除1,而它回显一个值屏幕,没有工作。
我会感激任何反馈,任何帮助。对于一个
的新手来说,这是一个挑战。
这是代码:
(查询数据库然后:)
//
ref. It then returns the key
value and the key value, as a number, is deducted by one and plus''d by
one to give me the previous row and the next row.
Returning the value of the next row works a treat, but for some reason
the previous row, deduct 1, while it echoes a value to screen, doesn''t
work.
I''d appreciate any feedback, any help. It''s been a challenge for a
newbie to sort this out.
This is the code:
(query database and then:)
//
ref是一个载入页面的变量
ref is a variable carried into the page
这篇关于mysql结果< - 上一行和下一行,显示下一个确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!