简体   繁体   English

获取<image> src php以在html中显示

[英]get < image> src php to display in html

This is my javascript code : 这是我的JavaScript代码:

$(document).ready(function() {

    $('.aire-force,.army').click(function() {  
                var storedData;                             
                var qString = 'categorie=' +$(this).text();
                $.post('getimage.php', qString, processResponse);
    });

    function processResponse(data) {
                $('.results').html(data);
                storedData = data;
                alert(storedData);
                document.getElementById('test').innerHTML = test;
    }


});

and this my file PHP (getimage.php): 这是我的文件PHP(getimage.php):

<?php

$con = mysql_connect("localhost","root","");
if(!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("DB", $con);
$categorie = $_POST['categorie'];

$q = "SELECT title from designs  WHERE  categorie='$categorie'";

$r = mysql_query($q);

while( $array = mysql_fetch_array($r)){

      echo $array['title'];
} 
?>

and i need to get the tile of image in my code HTML : 而且我需要在代码HTML中获取图像切片:

require_once('getimage.php');
<img  src="images/ echo $array['title']; /> 
require_once('getimage.php');
< img  src="images/ echo $array['title']; />

Should be replaced by: 应替换为:

<?php include('getimage.php'); ?>
<img src="images/<?php echo $array['title']; ?>" />

This should work.. Save this html file also as a .php ;) 这应该可以工作。将该HTML文件另存为.php;)

document.getElementById('test').innerHTML = test;

您从未设置测试变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM