如何通过id组织mysql输出? [英] How do I organize mysql output by id?

查看:86
本文介绍了如何通过id组织mysql输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个代码将显示我的数据库中的表中的信息,但它是随机的。我想要组织的两件事是问题和回应。我想使用每行的id基本上按顺序排列,以便显示问题,然后显示该行中该问题下的响应。如果有任何意义,请帮助我。

 <?php  
包括' config.php';

mysql_connect(localhost,$ username,$ password);
@mysql_select_db($ database) die( 无法选择数据库);
$ query = SELECT * FROM name;
$ result = mysql_query($ query);

$ num = mysql_numrows($ result);

mysql_close();

echo < center>数据库输出< / center> < br>< br>;

$ i = 0;
while ($ i< $ num){
$ responses = mysql_result($ result,$ i, Kiya_responses);
$ answers = preg_replace( /%你([0-9a-f] {3,4})/ i \ \1;,urldecode($响应));
$ questions = mysql_result($ result,$ i, Kiya_questions);
$ questions = preg_replace( /%你([0-9a-f] {3,4})/ i \ \1;,urldecode($问题));

echo < BR> $问题< / BR>中;
echo < br> $ answers< ; / BR>中;


$ i ++;
}

?>

解决方案

用户名,

密码);
@mysql_select_db(


数据库) die( 无法选择数据库);


so i have this code that will display the information from a table in my database but it does it randomly. the two things that i want to be organized are the question and response. i want to use the id for each row to basically put it in order so it shows the question and then the response under that question in that row. if any of this makes sense please help me.

<?php
include 'config.php';

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM name";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<center>Database Output</center><br><br>";

$i=0;
while ($i < $num) {
$responses=mysql_result($result,$i,"Kiya_responses");
$responses = preg_replace("/%u([0-9a-f]{3,4})/i","\\1;",urldecode($responses));
$questions=mysql_result($result,$i,"Kiya_questions");
$questions = preg_replace("/%u([0-9a-f]{3,4})/i","\\1;",urldecode($questions));

echo "<br>$questions</br>";
echo "<br>$responses</br>";


$i++;
}

?>

解决方案

username,


password); @mysql_select_db(


database) or die( "Unable to select database");


这篇关于如何通过id组织mysql输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆