Bir php dosyasını çalıştırmak için bir JS scipt çağrılması ve ardından göreli satır html gönderebilir

0 Cevap php

Eğer bu izleyin ...

Temelde i (bir satır ile başlar) bir sipariş formu var.

<form id="orderform" name"orderForm" action="/secure/delivery-details.html" method="post">
<a  id="add">+</a>
 <table id="ordertable" width="533" border="0" cellspacing="0" cellpadding="2">
  <tbody>
    <tr>
      <td width="33%">Product Code (e.g 66203)</td>
      <td width="33%">Mtrs Required (e.g 10)</td>
      <td width="33%">Preview Image</td>
    </tr>
    <tr class="item">
      <td class="prodcode"><input type="text" name="prodcode[]" id="prodcode" /></td>
      <td class="meterage"><input type="text" name="meterage[]" id="meterage" /></td>
      <td class="imgsample"></td>
    </tr>
    </tbody>
  </table>
  <button>Submit</button>
</form>

"Add" bir kimliği ile bağlantısını dikkat edin. Seçildiğinde, bu aynı kimliği ile tabloya yeni bir satır ekler. Aşağıdaki kodu kullanarak.

    var counter = 0;
    //Order Form
    $("#add").click(function() {
        counter++;
        var cln = $('#ordertable tbody>tr:last').clone(true);
//        cln.find("[id^='prodcode']").each(function(i, val) {
//          val.id = val.id.match(/^([^0-9]+)[0-9]*$/)[1] + "" + counter;
//      });
        cln.insertAfter('#ordertable tbody>tr:last');
        $('#ordertable tbody>tr:last input').val('');
        $('td.imgsample:last a').remove();
        return false;
    });

    //Check for image preview
    $("#prodcode").blur(function() {
        var $this = $(this);
        $this
            .closest('tr') // find the parent tr
            .find('td.imgsample') // find the imgsample in the row
            .html( $(this).attr('id')) // update the contents
            //.animate({'opacity':1},200);

        var imgsample = $this.closest('tr').find('td.imgsample')

        $.post('/public/themes/lbd/js/searchimage.php', //this page reads the image code and gives you the image location
                 { action: 'searchimage', imgreference: $(this).val() },
                function(data) {imgsample.html(data);}
                );
    });

Searchimage Benim PHP ...

When i currently enter a product code if it is invalid it only puts the productID in td.imsample and i want it to say INVALID CODE

//Find image based on Product Code
function findimage($imageToFind) { 

  require '../../../../config.php';
  $dbh = new PDO(DB_DSN, DB_USER, DB_PASS);

  $sql = "SELECT * FROM isproducts WHERE prodCode = ".strtoupper($imageToFind).""; 
  $stmt = $dbh->query($sql);
  $obj = $stmt->fetch(PDO::FETCH_OBJ);
  $count = $stmt->rowCount();
  if($count > 0) {
      $sql2 = "SELECT * FROM imageindex WHERE filename LIKE '".strtoupper($imageToFind)."-%'"; 
      $stmt2 = $dbh->query($sql2);
      $obj2 = $stmt2->fetch(PDO::FETCH_OBJ);
      echo ($stmt2->rowCount() == 1 ? '<a href="'.URL_PUBLIC.$obj2->path.'/'.$obj2->filename.'" class="customGal imgfound"><span>'.$obj2->path.'/'.$obj2->filename.'</span></a>&nbsp;<a href="#" class="del">-</a>' : 'No Image Available');    
  } else { 
    echo 'Invalid Code';
  }

}

//Call Function
findimage($_POST['imgreference']);

0 Cevap