It's all in the question really :)

这一切都在真正的问题:)

It's clearer when I put it in bullet points what I want to do, so here it goes:

当我把它放在我要做的项目中时,它更清楚了,所以它在这里:

  • I have two forms on a page, a search form, and an 'edit profile' form. Both are in working order, individually.
  • 我在页面上有两个表单,一个搜索表单和一个“编辑配置文件”表单。两者都处于正常工作状态。
  • The edit profile form paginates through the rows of my MySQL tbl, allowing my to edit the values for each column. Currently set up to include all rows (i.e. all stored profiles).
  • 编辑配置文件表格通过我的MySQL tbl的行分页,允许我编辑每列的值。当前设置为包括所有行(即所有存储的配置文件)。
  • the search form takes any of 17 different search variables and searches that same table to find a profile, or a group of profiles.
  • 搜索表单采用17个不同的搜索变量中的任何一个,并搜索同一个表以查找配置文件或一组配置文件。
  • I want to be able to enter a search term (e.g. Name: 'Bob'), query the tbl as I am doing, but use AJAX to return the unique ID's of the results as an an array stored within a variable. I then want to be able to asynchronously feed that variable to my edit profile form query (the search form would have a submit button...) so I can now page through all the rows in my table (e.g. where the Name includes 'Bob'), and only those rows.
  • 我希望能够输入一个搜索词(例如Name:'Bob'),按照我的意思查询tbl,但是使用AJAX将结果的唯一ID作为存储在变量中的数组返回。然后我希望能够异步地将该变量提供给我的编辑配置文件表单查询(搜索表单将有一个提交按钮...)所以我现在可以翻阅我表格中的所有行(例如,名称包含'Bob '),只有那些行。

Is the above possible with the languages in question? Can anyone help me piece them together?

以上是否可以使用相关语言?谁能帮我把它们拼凑起来?

I'm at an intermediate-ish stage with PHP and MySQL, but am an absolute novice with AJAX. I've only ever used it to display a text string in a defined area - as seen in demos everywhere :) Therefore, treating me like a five-year-old is greatly appreciated!

我正处于PHP和MySQL的中间阶段,但对于AJAX来说这绝对是新手。我只用过它来在一个定义的区域显示一个文本字符串 - 就像在各地的演示中看到的那样:)因此,对待我就像一个五岁的孩子非常感谢!

Here are my current search query, and the edit-profile form, if they help at all:

这是我当前的搜索查询和编辑配置文件表单,如果它们有帮助的话:

The Edit Profile form:

编辑个人资料表格:

//pagination base
if (isset($_GET['page'])) { $page = $_GET['page']; }
else { $page = 1; }
$max_results = 1;
$from = (($page * $max_results) - $max_results);

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM profiles"),0);
$total_pages = ceil($total_results / $max_results);

echo '<span id="pagination">' . 'Record ' . $page . ' of ' . $total_results . ' Records Returned. ';

if($total_results > $max_results)
{
    if($page > 1)
    { $prev = ($page - 1);
      echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><input type='submit' value='&lt;&lt;' /></a>";
    }
    if($page == 1)
    { echo "<input type='submit' value='&lt;&lt;' />"; }
    if($page < $total_pages)
    { $next = ($page + 1);
      echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"><input type='submit' value='&gt;&gt;' /></a>";
    }
    if($page == $total_pages)
    { echo "<input type='submit' value='&gt;&gt;' />";
    }
}
echo '</span></p>';
?>

// the query, currently selecting all but which I would have include a WHERE clause (WHERE ProfileID = $profileid...)

<?php
$sql = ("SELECT * FROM profiles 
    ORDER BY ProfileID 
    LIMIT $from, $max_results");

$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{

$profile = $row['ProfileID'];

?>

<form id="profile-form" action="profile-engine.php" method="post">
    <input type="hidden" name="formid" value="edit-profile">
    <input type="hidden" name="thisprofile" value="<?php echo $profile; ?>">

    <table id="profile-detail" class="profile-form">
    <tr>
        <td>        
    <label for="profile-name">Name:</label>
        <?php
            $nameresult = mysql_query("SELECT ProfileName 
                            FROM profiles 
                            WHERE ProfileID = '$profile'");
            $row = mysql_fetch_array($nameresult);
        ?>
    <input type="text" class="text" name="profile-name" id="profile-name" value="<?php echo $row['ProfileName']; ?>" />
        </td>

//goes on in this vein for another 16 inputs :)

The Search Query:

搜索查询:

//connection established        

$query = "SELECT * FROM profiles"; 

$postParameters = array("name","height","gender","class","death","appro","born","tobiano","modifier","adult","birth","sire","dam","breeder","owner","breed","location");
$whereClause = " WHERE 1 = 1";
foreach ($postParameters as $param) {
    if (isset($_POST[$param]) && !empty($_POST[$param])) {
        switch ($param) {
            case "name":
                $whereClause .= " AND ProfileName LIKE '%".$_POST[$param]."%' ";
                break;
            case "height":
                $whereClause .= " AND ProfileHeight='".$_POST[$param]."' ";
                break;
            case "gender":
                $whereClause .= " AND ProfileGenderID='".$_POST[$param]."' ";
                break;
//more cases....
        }
    }
}
$query .= $whereClause;

$result = mysql_query("$query");

$values = array();
while ($row = mysql_fetch_array($result)) {
$values[] =  $row['ProfileID'];
    }
/*  
//just me checking that it worked...
foreach( $values as $value => $id){
    echo "$id <br />";
}
*/


    mysql_close($con);

So, there you have it! Thanks in advance for any help!

所以你有它!在此先感谢您的帮助!

1 个解决方案

#1


0

what about: search copies search term to local variable, service returns an array of results that you hold, and then pagination uses JS to drop in the values into the appropriate fields. If you change one and save, it submits the edits, including the original search term, which is used to re-query the service, and returns the updated array...repeat as necessary

怎么样:搜索将搜索词复制到局部变量,服务返回你持有的结果数组,然后分页使用JS将值放入适当的字段。如果您更改并保存,则会提交编辑内容,包括用于重新查询服务的原始搜索词,并返回更新后的数组...必要时重复

here's some sample code (here there's just two search fields, I know you need more):

这里有一些示例代码(这里只有两个搜索字段,我知道您需要更多代码):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var query = new Object();
var resp;
var i;
function next(on){
    i=on+1;
    if(i==resp.results.length){i--;}
    fillForm(i);
}
function prior(on){
    i=on-1;
    if(i<0){i++;}
    fillForm(i);
}

function fillForm(i){   
    document.getElementById("paginate").innerHTML='<button onclick="prior('+i+')">&lt;</button>'+(i+1)+' of '+resp.results.length+'<button onclick="next('+i+')">&gt;</button>';
    document.getElementById("name").value=resp.results[i].name;
    document.getElementById("height").value=resp.results[i].height;
    document.getElementById("gender").value=resp.results[i].gender;
    document.getElementById("class").value=resp.results[i].class;
    document.getElementById("death").value=resp.results[i].death;
    document.getElementById("appro").value=resp.results[i].appro;
    document.getElementById("born").value=resp.results[i].born;
    document.getElementById("tobiano").value=resp.results[i].tobiano;
    document.getElementById("modifier").value=resp.results[i].modifier;
    document.getElementById("adult").value=resp.results[i].adult;
    document.getElementById("birth").value=resp.results[i].birth;
    document.getElementById("sire").value=resp.results[i].sire;
    document.getElementById("dam").value=resp.results[i].dam;
    document.getElementById("breeder").value=resp.results[i].breeder;
    document.getElementById("owner").value=resp.results[i].owner;
    document.getElementById("breed").value=resp.results[i].breed;
    document.getElementById("location").value=resp.results[i].location;
    document.getElementById("id").value=resp.results[i].id;
    document.getElementById("saveButton").innerHTML='<button onclick="save()">Save</button>';
}
function getData(){
    query.name=document.getElementById('query_name').value;
    query.gender=document.getElementById('query_gender').value;
    var variables='';
    variables+='name='+query.name;
    variables+='&gender='+query.gender;
    var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    resp = JSON.parse(xmlhttp.responseText);
    fillForm(0);
    }
  }
xmlhttp.open("GET","searchNav.php?"+variables,true);
xmlhttp.send(); 
}

function save(){
    var saving="";
    saving+='?q='+query;
    saving+='&name='+document.getElementById('name').value;
    saving+='&height='+document.getElementById('height').value;
    saving+='&gender='+document.getElementById('gender').value;
    saving+='&class='+document.getElementById('class').value;
    saving+='&death='+document.getElementById('death').value;
    saving+='&appro='+document.getElementById('appro').value;
    saving+='&born='+document.getElementById('born').value;
    saving+='&tobiano='+document.getElementById('tobiano').value;
    saving+='&modifier='+document.getElementById('modifier').value;
    saving+='&adult='+document.getElementById('adult').value;
    saving+='&birth='+document.getElementById('birth').value;
    saving+='&sire='+document.getElementById('sire').value;
    saving+='&dam='+document.getElementById('dam').value;
    saving+='&owner='+document.getElementById('owner').value;
    saving+='&breed='+document.getElementById('breed').value;
    saving+='&breeder='+document.getElementById('breeder').value;
    saving+='&location='+document.getElementById('location').value;
    saving+='&id='+document.getElementById('id').value;
        var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    resp = JSON.parse(xmlhttp.responseText);
    fillForm(0);
    }
  }
xmlhttp.open("GET","saveEdits.php"+saving,true);
xmlhttp.send(); 
}
</script>
</head>
<body>
<div id="search">
    <table>
    <tr><td>Name:</td><td><input type="text" id="query_name" /></td></tr>
    <tr><td>Gender:</td><td><input type="text" id="query_gender" /></td></tr></table>
    <button onclick="getData()">Search</button>   
</div>
<div id="results">
    <div id="paginate"></div>
    <input type="hidden" id="id" />
    <table>
    <tr><td>Name:</td><td><input type="text" id="name" /></td></tr>
    <tr><td>Height:</td><td><input type="text" id="height" /></td></tr>
    <tr><td>Gender:</td><td><input type="text" id="gender" /></td></tr>
    <tr><td>Class:</td><td><input type="text" id="class" /></td></tr>
    <tr><td>Death:</td><td><input type="text" id="death" /></td></tr>
    <tr><td>Appro:</td><td><input type="text" id="appro" /></td></tr>
    <tr><td>Born:</td><td><input type="text" id="born" /></td></tr>
    <tr><td>Tobiano:</td><td><input type="text" id="tobiano" /></td></tr>
    <tr><td>Modifier:</td><td><input type="text" id="modifier" /></td></tr>
    <tr><td>Adult:</td><td><input type="text" id="adult" /></td></tr>
    <tr><td>Birth:</td><td><input type="text" id="birth" /></td></tr>
    <tr><td>Sire:</td><td><input type="text" id="sire" /></td></tr>
    <tr><td>Dam:</td><td><input type="text" id="dam" /></td></tr>
    <tr><td>Breeder:</td><td><input type="text" id="breeder" /></td></tr>
    <tr><td>Owner:</td><td><input type="text" id="owner" /></td></tr>
    <tr><td>Breed:</td><td><input type="text" id="breed" /></td></tr>
    <tr><td>Location:</td><td><input type="text" id="location" /></td></tr>
    </table>
    <div id="saveButton"></div>
</div>
</body>
</html>

and the search:

和搜索:

<?php
//connection established        
$query = "SELECT * FROM profiles"; 
$postParameters = array("name","height","gender","class","death","appro","born","tobiano","modifier","adult","birth","sire","dam","breeder","owner","breed","location");
$whereClause = " WHERE 1 = 1";
foreach ($postParameters as $param) {
    if (isset($_POST[$param]) && !empty($_POST[$param])) {
       $whereClause .= " AND ".$param."='".$_POST[$param]."'";
    }
}
$query .= $whereClause;
$result = mysql_query("$query");
echo "{\"results\":";
if($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "[";
    echo "{\"name\":\"".$row["name"]."\",";
    echo "\"height\":\"".$row["height"]."\",";
    echo "\"gender\":\"".$row["gender"]."\",";
    echo "\"class\":\"".$row["class"]."\",";
    echo "\"death\":\"".$row["death"]."\",";
    echo "\"appro\":\"".$row["appro"]."\",";
    echo "\"born\":\"".$row["born"]."\"";
    echo "\"tobiano\":\"".$row["tobiano"]."\"";
    echo "\"modifier\":\"".$row["modifier"]."\"";
    echo "\"adult\":\"".$row["adult"]."\"";
    echo "\"birth\":\"".$row["birth"]."\"";
    echo "\"sire\":\"".$row["sire"]."\"";
    echo "\"dam\":\"".$row["dam"]."\"";
    echo "\"breeder\":\"".$row["breeder"]."\"";
    echo "\"owner\":\"".$row["owner"]."\"";
    echo "\"breed\":\"".$row["breed"]."\"";
    echo "\"location\":\"".$row["location"]."\"";
    //echo "\"id\":\"".$row["id"]."\"";
    echo "}";
}
else{
echo "\"no\"}";
exit;
}
while($row = mysql_fetch_array($data,MYSQL_ASSOC)){
    echo ",{\"name\":\"".$row["name"]."\",";
    echo "\"height\":\"".$row["height"]."\",";
    echo "\"gender\":\"".$row["gender"]."\",";
    echo "\"class\":\"".$row["class"]."\",";
    echo "\"death\":\"".$row["death"]."\",";
    echo "\"appro\":\"".$row["appro"]."\",";
    echo "\"born\":\"".$row["born"]."\"";
    echo "\"tobiano\":\"".$row["tobiano"]."\"";
    echo "\"modifier\":\"".$row["modifier"]."\"";
    echo "\"adult\":\"".$row["adult"]."\"";
    echo "\"birth\":\"".$row["birth"]."\"";
    echo "\"sire\":\"".$row["sire"]."\"";
    echo "\"dam\":\"".$row["dam"]."\"";
    echo "\"breeder\":\"".$row["breeder"]."\"";
    echo "\"owner\":\"".$row["owner"]."\"";
    echo "\"breed\":\"".$row["breed"]."\"";
    echo "\"location\":\"".$row["location"]."\"";
    //echo "\"id\":\"".$row["id"]."\"";
    echo "}";
}
echo "]}";
?>

更多相关文章

  1. 请问如何用php实现表单提交后以邮件的形式把表单内容发到邮箱中
  2. 如何在jQuery Mobile页面中提交表单?
  3. Symfony2 -从数据库中提取数据并以表单形式显示
  4. laravel 框架自带表单验证
  5. AJAX学习之提交表单
  6. 在提交注册表单时使用jQuery显示错误
  7. 如果改变输入值,jQuery提交表单
  8. 如何在表单操作中执行PHP函数?
  9. mysql dos命令 创建表单,选择数据库

随机推荐

  1. Android 仿3g体育门户客户端赛事图标浮出
  2. Android菜鸟日记14-对话框
  3. 【android】WebView缓存资料收集
  4. Android布局优化(一),Android渲染机制
  5. 2011.09.22——— android ViewStub的简
  6. Android监听来电和去电
  7. android 不自动弹出虚拟键盘
  8. Chrome V8 引擎移植到 Android
  9. Failed to sync vcpu reg
  10. android 数据库 备份还原