Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从MySQL(使用ajax)检索的数据超过了目标元素定义的宽度_Php_Mysql_Ajax_Database - Fatal编程技术网

Php 从MySQL(使用ajax)检索的数据超过了目标元素定义的宽度

Php 从MySQL(使用ajax)检索的数据超过了目标元素定义的宽度,php,mysql,ajax,database,Php,Mysql,Ajax,Database,我正在使用ajax调用从Mysql检索数据 这是Javascript文件: var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("txt").innerHTML = this.responseText;

我正在使用ajax调用从Mysql检索数据

这是Javascript文件:

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        document.getElementById("txt").innerHTML = this.responseText;
     }
};
xmlhttp.open("GET", "sample.php?id=" + id, true);
xmlhttp.send();
这是sample.php文件

$id = $_GET['id'];
$query = "SELECT `description` FROM `products` WHERE `id`='$id'";
$query_run = mysql_query($query);
$description = mysql_result(query_run,0);
echo $description;

我已将目标“div”元素的宽度定义为500px。但从数据库生成的结果超过了500px。我希望每次宽度达到500px时,它都取下一行。请帮助我发生这种情况,因为描述中没有空格,我认为在真实描述中,word的大小永远不会超过500px。您可以尝试在DIV中添加一些CSS样式,例如,
单词break:always
空白:wrap
溢出wrap:break-word
。在找到完美的组合之前,你必须玩一点。