开发者

jquery php json example [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

How do I populate several text input fields with corresponding data, executing php-mysql query script once only? e.g.

<form name="video" action="mysql.php" method="post" enctype="multipart/form-data" target="videofrm">
                <p>
                    <label for="url">url/gallery:</label><input class="text" type="text" id="url" name="url"/>
                    <input id="favorite" class="text" type="checkbox" name="favorite" value="true"/>
                    <label for="favorite" class="noneFloat">favorite</label>
                </p>
                <p>
                    <input id="thumb" type="file" name="thumb"/>
   开发者_JAVA百科             </p>
                <p>
                    <label for="title">title:</label><input class="text" type="text" id="title" name="title"/>
                </p>
                <p>
                    <label for="desc">description:</label><input class="text" type="text" id="desc" name="description"/>
                </p>
                <p>
                    <label for="country">country:</label><input class="text" type="text" id="country" name="country"/>
                </p>
                <p>
                    <label for="categories">categories:</label><input class="text" type="text" id="categories" name="category"/>
                </p>
                <input type="button" value="fetch" id="fetch"/>
                <input type="reset" value="clear"/>
            </form>

I need to populate input text fields with:

select url,title,desc,country,category
from video where url='something';

First I need to know how to write this kind of php script so it returns json datatype, and afterwards how to populate text input fields, using jquery, with returned data.

`many thanks


Your question is very broad, and looks a bit like a "please write my code" request (although it wasn't necessarily one). Try to avoid that impression, and mention what you have already tried/researched to avoid downvoting.

Some pointers:

  • Use json_encode() to get mySQL result data into JSON form on PHP side

  • Send the correct content-type header to go with it: header("content-type: application/json");

  • Use jQuery's getJSON() shorthand (or .ajax() with a json dataType) to fetch the script

  • Populating the input fields with the data is trivial using .val().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜