Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

PHP AJAX to get an editable list.

max_file_size ajax

  • Please log in to reply
No replies to this topic

#1 deb


    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 29 June 2011 - 04:42 AM

Please use [noparse]
, [code] and [quote][/noparse] when appropriate | [URL="http://forum.codecall.net/members/john.html"]John[/URL][/B][/COLOR]

Greetings to All forum members. I am having the following problem , which I am sure some of you must have faced in the early years of development. I am very new to this.
I would like to get list of rows returned from aPHP - SQL select. This should be displayed in the browser with a button at the end of each row to provide the option to edit the row.
When you click on this button , the user should be able to read the full details of the row in a form.
My problem is I am getting the button correctly , but when I click on the 3rd or 4th button in the row , it always displays me the 1st row details

Here is the javascript snippet
when the section highlighted in pink is getting executed , the value is wrongly selected
by the function in highlighted in red in ajax_search.

The query is initiated after the category (in the form in div topadd) is selected.

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="ashoplayout.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.keyframesandcode.com/resources/javascript/jQuery/populate/jquery.populate.pack.js"></script>
<script type="text/javascript" src="http://dev.iceburg.net/jquery/tableEditor/jquery.tableEditor.js"></script>
<script type="text/javascript" src="http://dev.iceburg.net/jquery/tableEditor/jquery.tablesorter.js"></script>
<title>Select Category form</title>

<script type="text/javascript">


function ajax_cat_search(){
var search_val=$("#cat_select").val();
$.post("./findcat.php", {"cat_select": search_val}, function(data){
if (data.length>0){



$("#rightmidtop").click(function(e) {
alert('Handler for .click() called.');
var edit_val=$("#edit_button").val();


function ajax_search(){
var edit_val=$("#edit_button").val();
$.post("./editcat.php", {"edit_button": edit_val}, function(data){
if (data.length>0){
var johnny = JSON.parse(data);
//Now, the variable 'johnny' is an object that contains all of the properties
//from the above code snippet (the json example)
alert(johnny.category + ' ' + johnny.file_ID); //Will alert 'John Smith'
document.getElementById('file_ID').value = johnny.file_ID;
document.getElementById('category').value = johnny.category ;
document.getElementById('price').value = johnny.price ;
document.getElementsByName('present').value = johnny.present;
document.getElementById('filedesc').value = johnny.filedesc;


<div style="color: white; width: 100%; border-bottom: 1px solid white; text-align: center; font-size: 14px; background-color: #1B50E0; font-weight: bolder;">
<a href="http://a.lakequincy.com/c.ashx?channel=1&publisher=629&placement=10054&creative=10083" target="_blank" style="color: white;text-decoration:none;vertical-align:middle"><img src="/images/adobe_logo_88x25.png" height="25" width="88" /> Adobe Flash Builder 4.5 – Build applications for multiple mobile platforms. Download today</a><img height="1" width="1" src="https://a.lakequincy.com/i.ashx?channel=1&publisher=629&placement=10054&creative=10083" />
<div id ="header">
<div id="topadd">

<select name="category" id = "cat_select">
<option value="">Select a Category:</option>
<option value="19th Century">19th Century</option>
<option value="20th Century">20th Century</option>
<option value="18th Century">18th Century</option>
<option value="17th Century">17th Century</option>
<div id = "content">

<form id="Upload" enctype="multipart/form-data">

Upload form
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">


<label for="Category">Category:</label>
<input id="category" type="text" name="category">
<label for="fileID">Image Name:</label>
<input id="file_ID" type="text" name="file_ID">

<label for="price">Price:</label>
<input id="price" type="text" name="price">

<label for="filedesc">Item Description:</label>
<textarea id="filedesc" rows = "3" cols = "30">

<label for="submit">Press to...</label>
<input id="submit" type="submit" name="submit" value="Upload me!">


<div id="rightmidtop"><b>Item info will be listed here.</b></div>


The PHP code is listed here


$q = strip_tags(substr($_POST['edit_button'],0, 100));
$q = mysql_escape_string($q);

//data connection information //

mysql_select_db("test", $con);
echo $q;
$sql="SELECT * FROM ashop_data WHERE m_category = '".$q."'";
echo $sql;
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0 )

echo "<table border='0'>
<th>Image </th>
while($row = mysql_fetch_array($result))

echo "<tr>";
echo "<td>" . $row['m_image'] . "</td>";
echo "<td>" . $row['m_category'] . "</td>";
echo "<td>" . $row['m_name'] . "</td>";
echo "<td>" . $row['m_price'] . "</td>";
echo "<td>" ."<img src="."http://forum.codecall.net/images/".$row['m_image'].".jpg>"."</td>";
echo "<td>"."<input type="."button". " value =".$row['m_image']." ID="."edit_button"." Edit />"."</td>";
echo "</tr>";
echo "</table>";

else { echo "No Items Found ";

Can any kind soul guide me on this where I am going wrong ?

[COLOR="red"][B]Please use [noparse][php], [code=auto:0] and [quote][/noparse] when appropriate | John

Edited by John, 29 June 2011 - 02:13 PM.

  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download