我是php的新手,但我似乎无法在php手册中找到直接的答案,或者真的在这个论坛的任何地方寻求帮助。我想要做的是将sql_query结果拉入多维数组,然后为结果的每一行添加一个单选按钮。通过这种方式,我可以将值提交到cookie和/或会话到下一页,以提取数据并提供有关该主题的更多详细信息。
这是我到目前为止的代码:
<?php
mysqli_connect('$db', 'user', 'abc123')
//connect to database
//query mining ops where active = 1 and type = alliance or donate
//if result = 0, echo "no current ops open"
//else, continue ->
$qresult = mysql_query("SELECT mineopnum,location,optype,starttime,playercount,isk,completed FROM mining ops WHERE completed='0' AND optype='alliance' OR optype='donate'ORDER BY mineopnum,starttime DESC")
while($info = mysql_fetch_array($qresult))
IF mysql_num_rows($qresult == '0'{
echo "no current ops open"}
//Table results:
//mineopnum //location //optype //starttime //playercount // isk // completed
//database structure layout:
//0 - mineopnum //10 - OREdenseveld //20 - OREkernite //30 - OREgleamspod //40 - OREprismaticgneiss //50 - OREark
//1 - location //11 - OREscord //21 - OREluminouskern //31 - OREbrightspod //41 - OREdarko //51 - OREcrimsonark
//2 - op type //12 - OREcondscord //22 - OREfierykern //32 - OREhemor //42 - OREobsidiano //52 - OREprimeark
//3 - starttime //13 - OREmassivescord //23 - OREomber //33 - OREvividhemor //43 - OREonyxo //53 - OREmerc
//4 - playercount //14 - OREplag //24 - OREsilveromber //34 - OREradianthemor //44 - OREcrok //54 - OREvitmerc
//5 - players //15 - ORErichplag //25 - OREgoldenomber //35 - OREhedb //45 - OREcrystalcrok //55 - OREmagmamerc
//6 - isk //16 - OREazureplag //26 - OREjaspet //36 - OREglazedhedb //46 - OREsharpcrok //56 - ICEclearicicle
//7 - completed //17 - OREpyrox //27 - OREpristinejaspet //37 - OREvitrichedb //47 - OREbistot //57 - ICEenrichedclearice
//8 - OREveld //18 - OREsolidpyrox //28 - OREpurejaspet //38 - OREgneiss //48 - OREmonobist //58 - ICEglacialmass
//9 - OREcondveld //19 - OREviscouspyrox //29 - OREspod //39 - OREiridescentgneiss //49 - OREtribist //59 - ICEsmoothglacial
$value = '0'
$radio = <input type="radio" name="openops" value="$value++">
//form into array
//add radio button at beginning of each row in array
//print array
print_r($qresult)
//private op
// query mining
// when submit is pressed, push selected radio to cookie/session
// redirect to joinminingop.php
//pulls posted data and creates cookie data which will in turn be sent to the mining op page
?>
如php注释中所述,我想创建一个单选按钮,以便我可以选择整行返回的数据并将其转发到下一页以获取更多详细信息,并根据从中选择的按钮选择其他代码。顶部菜单。这必须在每一行都完成,但在添加&#34; advanced&#34;功能没有看到好的直接例子。
提前感谢您的帮助
答案 0 :(得分:1)
第一个问题:你必须结束几乎所有代码;字符,例如:
mysqli_connect('$db', 'user', 'abc123');
然后:while必须有一个开始和一个endign标签:{和},如果它没有以其他方式声明。 我不知道你想怎么做,所以我只给你指示:
<?php
mysqli_connect('$db', 'user', 'abc123');
$qresult = mysql_query("SELECT mineopnum,location,optype,starttime,playercount,isk,completed FROM mining ops WHERE completed='0' AND optype='alliance' OR optype='donate'ORDER BY mineopnum,starttime DESC");
if(mysql_num_rows($qresult == "0")){
echo("no current ops open");}
while($info = mysql_fetch_array($qresult)){
$value = '0';
$radio = "<input type='radio' name='openops' value='$value++'>";
print("".$radio."").print_r($qresult);}
?>
我没有解决这个问题:$ value =&#39; 0&#39 ;; $ radio =&#34;&#34 ;; ,因为它不是识别的好方法,你按下了哪个按钮。 你应该找到另一种方法,例如为sql命名id添加一个额外的行,并给它们PRIMARY索引,这样你就可以在其他代码中处理它。 我知道,我的代码并不完美,但对于教学来说这很好。你应该注意; &#39;而对于&#34; -s