先声明俺真是php菜鸟,所以才深夜来求个代码,希望能遇到个明白人指点一二这里谢过了
假设:对数据库里的两组数据A B C D E F ……和1 2 3 4 5……进行交替排列结果为A 1 B 2 C 3 D 4 E 5 F 6……
不知php的代码该如何写,主要是数组交替排列,俺有asp的可以参考
<% function hope_marque()
strs=""
mqrerr=1
Set Rs_Cate=Conn.ExeCute("select showname,infoenddate,sortid,typeid,typeid_2,info_id from info where type='买' and Flag=1 order by info_id desc")
if not Rs_Cate.eof then
calArray1=Rs_Cate.GetRows
else
mqrerr=0
end if
Set Rs_Cate=Nothing
Set Rs_qg=Conn.ExeCute("select showname,infoenddate,sortid,typeid,typeid_2,info_id from info where type='卖' and Flag=1 order by info_id desc")
if not Rs_qg.eof then
calArray2=Rs_qg.GetRows
else
mqrerr=0
end if
Set Rs_qg=Nothing
if mqrerr then
strs=strs&"<div class=""row3"" style=""padding:5px 1px 1px 1px;"">"
strs=strs&" "
strs=strs&"<DIV id=b2b style=""VERTICAL-ALIGN: middle; OVERFLOW: hidden"">"
strs=strs&"<TABLE style=""MARGIN-TOP: 3px"" cellSpacing=0 cellPadding=0 width=""100%"" align=center border=0><TBODY>"&vcrlf
if ubound(calArray1,2)+1<ubound(calArray2,2)+1 then
i=0
do while ubound(calArray1,2)+1>i
strs=strs&" <TR><TD height=25><A href="trade/"&calArray2(2,i)&"-"&calArray2(3,i)&"-"&calArray2(4,i)&"-"&calArray2(5,i)&".html target=_blank>" &left(calArray2(0,i),10)&"</A> </TD><TD>" &calArray2(1,i)&"</TD></TR>"&vbcrlf
strs=strs&" <TR><TD height=25><A href="seller/"&calArray1(2,i)&"-"&calArray1(3,i)&"-"&calArray1(4,i)&"-"&calArray1(5,i)&".html target=_blank>" &left(calArray1(0,i),10)&"</A> </TD><TD>" &calArray1(1,i)&"</TD></TR>"&vbcrlf
i=i+1
loop
else
i=0
do while ubound(calArray2,2)+1>i strs=strs&" <TR><TD height=25><A href="tradeinfo/"&calArray2(2,i)&"-"&calArray2(3,i)&"-"&calArray2(4,i)&"-"&calArray2(5,i)&".html target=_blank>" &left(calArray2(0,i),10)&"</A> </TD><TD>" &calArray2(1,i)&"</TD></TR>"&vbcrlf
strs=strs&" <TR><TD height=25><A href="seller/"&calArray1(2,i)&"-"&calArray1(3,i)&"-"&calArray1(4,i)&"-"&calArray1(5,i)&".html target=_blank>" &left(calArray1(0,i),10)&"</A> </TD><TD>" &calArray1(1,i)&"</TD></TR>"&vbcrlf
i=i+1
loop
end if
strs=strs&"</TBODY></TABLE></DIV>
else
strs="暂无信息" end if
hope_marque=strs
end function
%>
假设:对数据库里的两组数据A B C D E F ……和1 2 3 4 5……进行交替排列结果为A 1 B 2 C 3 D 4 E 5 F 6……
不知php的代码该如何写,主要是数组交替排列,俺有asp的可以参考
<% function hope_marque()
strs=""
mqrerr=1
Set Rs_Cate=Conn.ExeCute("select showname,infoenddate,sortid,typeid,typeid_2,info_id from info where type='买' and Flag=1 order by info_id desc")
if not Rs_Cate.eof then
calArray1=Rs_Cate.GetRows
else
mqrerr=0
end if
Set Rs_Cate=Nothing
Set Rs_qg=Conn.ExeCute("select showname,infoenddate,sortid,typeid,typeid_2,info_id from info where type='卖' and Flag=1 order by info_id desc")
if not Rs_qg.eof then
calArray2=Rs_qg.GetRows
else
mqrerr=0
end if
Set Rs_qg=Nothing
if mqrerr then
strs=strs&"<div class=""row3"" style=""padding:5px 1px 1px 1px;"">"
strs=strs&" "
strs=strs&"<DIV id=b2b style=""VERTICAL-ALIGN: middle; OVERFLOW: hidden"">"
strs=strs&"<TABLE style=""MARGIN-TOP: 3px"" cellSpacing=0 cellPadding=0 width=""100%"" align=center border=0><TBODY>"&vcrlf
if ubound(calArray1,2)+1<ubound(calArray2,2)+1 then
i=0
do while ubound(calArray1,2)+1>i
strs=strs&" <TR><TD height=25><A href="trade/"&calArray2(2,i)&"-"&calArray2(3,i)&"-"&calArray2(4,i)&"-"&calArray2(5,i)&".html target=_blank>" &left(calArray2(0,i),10)&"</A> </TD><TD>" &calArray2(1,i)&"</TD></TR>"&vbcrlf
strs=strs&" <TR><TD height=25><A href="seller/"&calArray1(2,i)&"-"&calArray1(3,i)&"-"&calArray1(4,i)&"-"&calArray1(5,i)&".html target=_blank>" &left(calArray1(0,i),10)&"</A> </TD><TD>" &calArray1(1,i)&"</TD></TR>"&vbcrlf
i=i+1
loop
else
i=0
do while ubound(calArray2,2)+1>i strs=strs&" <TR><TD height=25><A href="tradeinfo/"&calArray2(2,i)&"-"&calArray2(3,i)&"-"&calArray2(4,i)&"-"&calArray2(5,i)&".html target=_blank>" &left(calArray2(0,i),10)&"</A> </TD><TD>" &calArray2(1,i)&"</TD></TR>"&vbcrlf
strs=strs&" <TR><TD height=25><A href="seller/"&calArray1(2,i)&"-"&calArray1(3,i)&"-"&calArray1(4,i)&"-"&calArray1(5,i)&".html target=_blank>" &left(calArray1(0,i),10)&"</A> </TD><TD>" &calArray1(1,i)&"</TD></TR>"&vbcrlf
i=i+1
loop
end if
strs=strs&"</TBODY></TABLE></DIV>
else
strs="暂无信息" end if
hope_marque=strs
end function
%>
$arr='';
$i=0;
$sql="select zm from tt";
$res=mysql_query($sql);
$sql2="select sz from tt";
$rs=mysql_query($sql2);
while($row=$mysql_fetch_row($res)){
while($rw=mysql_fetch_row($rs)){
$arr[i]=$row[0]." ".$rw[0];
}
$i++;
}提供下思路!
$str1="A B C D E F";//假如每个数据是按空格排列
$str2="1 2 3 4 5";
$array1=explode(" ",$str1);
$array2=explode(" ",$str2);
for($i=0;$i<6;$i++)
{
echo $array1[$i]." ".$array2[$i]." ";
}
?>
$re1 = mysql_query($sql);
$sql = "select showname,infoenddate,sortid,typeid,typeid_2,info_id from info where type='卖' and Flag=1 order by info_id desc";
$rs2 = mysql_query($sql);
$arr=array();
while($row1 = mysql_fetch_row($re1) && $row2 = mysql_fetch_row($rs2)){
$arr[]=$row1;
$arr[]=$row2;
}