使用php在jquery autocorrect中显示存储在Mysql数据库中的url的图像

时间:2022-09-25 16:43:26

The title is a bit confusing I guess but this is what I need:

标题有点令人困惑,我想这是我需要的:

I have a jquery autocomplete textfield and it gets its data from a database. Everything works, I can type a part of a zipcode in the textfield and when that part exists in the database it shows all available options together with the city, state etc.

我有一个jquery自动完成文本字段,它从数据库中获取数据。一切正常,我可以在文本字段中键入邮政编码的一部分,当数据库中存在该部分时,它会显示所有可用选项以及城市,州等。

But what I want is to show the flag of the country (as an image) in the list of options. I made a new row: county (which contains the url to an image file of the flag)

但我想要的是在选项列表中显示国家的旗帜(作为图像)。我创建了一个新行:county(包含标志图像文件的url)

And this is where it goes wrong:

这就是出错的地方:


$rs = mysql_query('select zip, city, county, state from zipcode where zip like "'. mysql_real_escape_string($_REQUEST['term']) .'%" order by zip asc limit 0,10', $dblink);

$data = array();
if ( $rs && mysql_num_rows($rs) )
{
while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
{


    $data[] = array(
        'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .' '. <img src='http://www.colinch.com/fut/$row['county'].'' />  ,
        'value' => $row['zip']
    );
}
}

I'm not a php expert so I think it's just a simple thing that went wrong. When I remove the < img src="......." part it will just print the $row['county'] which looks like this: USA.png

我不是一个PHP专家所以我认为这只是一个简单的问题。当我删除使用php在jquery autocorrect中显示存储在Mysql数据库中的url的图像

I hope someone can help me!

我希望有一个人可以帮助我!

Thanks in advance

提前致谢

5 个解决方案

#1


2  

You Quotes are totally wrong:

你引用是完全错误的:

    'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .'<img src=\'http://www.colinch.com/fut/'.$row['county'].'\' />',

#2


0  

Try this :

试试这个 :

$data[] = array(
        'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .' <img src="http://www.colinch.com/fut/'.$row['county'].'" />'  ,
        'value' => $row['zip']
    );

#3


0  

Try this

  $data[] = array(
        'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .' '. '<img src="http://www.colinch.com/fut/'.$row['county'].'"'.'/>'  ,
        'value' => $row['zip']

#4


0  

You've put the quotes in a wrong way. That's why the syntax highlighters are so helpful. Take a look at the code you wrote in your question. It got marked by SO and dark red / brown colors mark where the text is. You want <img... to be put into a text! Or even better, if possible, echo the stuff directly into html like so:

你以错误的方式引用了引号。这就是语法荧光笔如此有用的原因。看看你在问题中写的代码。它标有SO和深红/棕色标记文本所在的位置。你想将使用php在jquery autocorrect中显示存储在Mysql数据库中的url的图像

foreach($countries as $code)
{
    ?><img src="<?php echo $flag; ?>.png/><?php
}

If you decide that you don't want to / cannot do it this way then your code should look like this:

如果您决定不想/不能这样做,那么您的代码应该如下所示:

'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .' <img src=\'http://www.colinch.com/fut/'.$row['county'].'\' />'

P.S. I would advise using " for html quotes and ' for php quotes. This way you will not need any escaping :)

附:我建议使用“for html quotes and'for php quotes。这样你就不需要任何转义:)

#5


0  

This may be easier to read

这可能更容易阅读

$data[] = array(
        'label' => "{$row['zip']}, {$row['city']} {$row['state']} <img src='http://www.colinch.com/fut/{$row['county']}' />"  ,
        'value' => $row['zip']
    );

The use of double quotes allows you to evaluate the variables used without escaping the string.

使用双引号可以在不转义字符串的情况下评估使用的变量。

Your issue lies with your quoting method

您的问题在于引用方法

.' '. <img src='http://www.colinch.com/fut/$row['county'].'' />
    ^--no start^--start                         ^--closed

You wanted to continue to build the string but did not include <img in the text. PHP then decided to continue again at 'http.... This is not correct.

您想继续构建字符串,但未在文本中包含 使用php在jquery autocorrect中显示存储在Mysql数据库中的url的图像。>

#1


2  

You Quotes are totally wrong:

你引用是完全错误的:

    'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .'<img src=\'http://www.colinch.com/fut/'.$row['county'].'\' />',

#2


0  

Try this :

试试这个 :

$data[] = array(
        'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .' <img src="http://www.colinch.com/fut/'.$row['county'].'" />'  ,
        'value' => $row['zip']
    );

#3


0  

Try this

  $data[] = array(
        'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .' '. '<img src="http://www.colinch.com/fut/'.$row['county'].'"'.'/>'  ,
        'value' => $row['zip']

#4


0  

You've put the quotes in a wrong way. That's why the syntax highlighters are so helpful. Take a look at the code you wrote in your question. It got marked by SO and dark red / brown colors mark where the text is. You want <img... to be put into a text! Or even better, if possible, echo the stuff directly into html like so:

你以错误的方式引用了引号。这就是语法荧光笔如此有用的原因。看看你在问题中写的代码。它标有SO和深红/棕色标记文本所在的位置。你想将使用php在jquery autocorrect中显示存储在Mysql数据库中的url的图像

foreach($countries as $code)
{
    ?><img src="<?php echo $flag; ?>.png/><?php
}

If you decide that you don't want to / cannot do it this way then your code should look like this:

如果您决定不想/不能这样做,那么您的代码应该如下所示:

'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] .' <img src=\'http://www.colinch.com/fut/'.$row['county'].'\' />'

P.S. I would advise using " for html quotes and ' for php quotes. This way you will not need any escaping :)

附:我建议使用“for html quotes and'for php quotes。这样你就不需要任何转义:)

#5


0  

This may be easier to read

这可能更容易阅读

$data[] = array(
        'label' => "{$row['zip']}, {$row['city']} {$row['state']} <img src='http://www.colinch.com/fut/{$row['county']}' />"  ,
        'value' => $row['zip']
    );

The use of double quotes allows you to evaluate the variables used without escaping the string.

使用双引号可以在不转义字符串的情况下评估使用的变量。

Your issue lies with your quoting method

您的问题在于引用方法

.' '. <img src='http://www.colinch.com/fut/$row['county'].'' />
    ^--no start^--start                         ^--closed

You wanted to continue to build the string but did not include <img in the text. PHP then decided to continue again at 'http.... This is not correct.

您想继续构建字符串,但未在文本中包含 使用php在jquery autocorrect中显示存储在Mysql数据库中的url的图像。>