2016-07-31 26 views
0

mein Projekt ist Web-Bild Re-Ranking. Ich versuche zu versuchen, welches Bild in der HTML-Seite ausgewählt wurde, um den Rang des Bildes in Mysql zu aktualisieren. Mein Code istWie zu definieren, welches Bild in HTML-Seite angeklickt und speichern Sie den Bildnamen in MySQL mit PHP

index.php

<?php 


include './search_image.php'; 

$obj_image = new Image(); 

if(@$_POST['Submit']) 
{ 
$obj_image->image_name=str_replace("'", "''", $_POST['txt_image_name']); 

$obj_image->Insert_into_image(); 

$data_image=$obj_image->get_all_image_list(); 
$row=mysql_num_rows($data_image); 
} 

?> 



    <!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN"> 
    <html> 
    <head> 
    <title>Home</title> 
    </head> 
    <body bgcolor=cyan> 
    <script> 
    window.location.hash="no-back-button"; 
    window.location.hash="Again-No-back-button";//again because google chrome   don't insert first hash into history 
    window.onhashchange=function(){window.location.hash="no-back-button";} 
    </script> 
    <center><h1>WEB IMAGE RERANKING</H1></CENTER> 
    <center> 
    <table border=0 cellspacing=10> 
    <th><a href="index.php" target="right">HOME</th> 
    <th><a href="admin.php" target"=right">ADMIN</th> 
    <form method="post" enctype="multipart/form-data"> 
    <tr> 
    <th width="50%">Enter Image name for search</th> 
    <td width="50%"><input type="text" name="txt_image_name"></input></td> 
    </tr> 
    <td width="50%"><input type="submit" name="Submit" value="Submit"></input>  </td> 
    </tr> 
    </table> 
    </form> 
    </CENTER> 




    <?php 
    if($row!=0) 
    { 
    ?> 
    <center> 
    <form method="post" enctype="multipart/form-data"> 

    <table width="30%" border="0"> 
    <?php 

    while($data= mysql_fetch_assoc($data_image)) 
    { 
    ?> 
    <tr> 

    <a href=# onclick="loadImage(String $data['image'])"> <img src="images/<?php echo $data['image']; ?>" width="400px" height="200px" ></a> 
    </tr> 
    <?php 
    } 
    ?> 
    </table> 
    </form> 
    </center> 
    <?php 
    } 

    ?> 
    <?php 
    echo" <script language='javascript' type='text/javascript'> 
function loadImage(String a) { 

     alert('1 %s',a); 
    } 
    </script>" 
    ?> 
    </body> 
    </html> 

search_image.php

<?php 
     include 'db_connection.php' ; 

     class Image{ 

    var 
    $image_id, 
     $image_name, 
     $image; 

     function Insert_into_image(){ 

     } 

     function get_all_image_list(){ 
     $query = "select *from stor_image where img_name='$this->image_name'"; 
     $result = mysql_query($query); 
     return $result; 
     } 

     } 
     ?> 

wenn Klick auf bestimmtes Bild den Rang des Bildes aktualisieren. Also brauche ich Hilfe, um Bildname oder src zu finden, um die Daten in mysql Datenbank zu aktualisieren. Danke

Antwort

0
HTML: 
<a href="javascript:void(0);" class="gallery" id="<?php echo $data['image']; ?>" onClick="reply_click(this.id)"><img src="images/<?php echo $data['image']; ?>" width="400px" height="200px" ></a> 
<script> 
function reply_click(clicked_id) 
{ 
    $imagename=clicked_id; 
    alert($imagename); 
} 
</script> 
0

Try this:

HTML: 
<a href="javascript:void(0);" class="gallery" id="<?php echo $data['image']; ?>"><img src="images/<?php echo $data['image']; ?>" width="400px" height="200px" ></a> 

JS: 
$('.gallery').click(function(){ 
var image_name = $(this).attr('name'); 

// make an ajax call with this image name and do what ever you want to do 
}); 
+0

Dank sehr viel. –