Re: Beginner javascript newbie - wants to learn some basics - display results from php query
| From: | Stuart Dallas | Date: | Sun, 03 May 2015 11:11:38 +0000 |
| Subject: | Re: Beginner javascript newbie - wants to learn some basics - display results from php query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324855@lists.php.net to get a copy of this message | ||
Swap the print_r for an echo. Using print_r will not give you a valid JSON
object.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
On Sat, 2 May 2015 at 21:48 dealTek <dealtek@gmail.com> wrote:
> [OFF TOPIC]
>
> Hi all,
>
> I know this is not a javascript forum - but could use some basic
> javascript beginner help or URL's to get started...
>
>
> Beginner javascript newbie - wants to learn some basics - display results
> from php query
>
>
> example...
> Q: If I request just a single record result - like query ends with -
> print_r (json_encode($output));
> how can I display various fields at different areas of the page using
> javascript query result?
> With php I can display a field output like:
>
> html ...
> html ...
> <?php echo $record->getField('FirstName'); ?>
> html ....
> html ...
>
> Q: So how do I convert the PHP query result - print_r
> (json_encode($output)); - to place php field results randomly where I want
> mixed in with html?
>
>
> First Name is: <?php echo $record->getField('FirstName'); ?> <br />
>
> - ?CAN I JUST PUT FirstName here using javascript not php like ...
> <???JAVASCRIPT field ???> FirstName <???/JAVASCRIPT ???>
>
> Last Name is: <?php echo $record->getField('FirstName'); ?><br />
>
> Phone is: <?php echo $record->getField('Phone'); ?><br />
>
> Street is: <?php echo $record->getField('Street'); ?><br />
>
> etc.
>
>
>
> =================
>
>
>
> WHAT I HAVE in javascript - works but it forces me to put the html inside
> the script so whole thing inside ...........
>
>
> <script>
> $(document).ready(function(){
> $("button").click(function(){
> $.get("getstuff.php", function(data, status){
> // alert("Data: " + data + "\nStatus: " + status);
> console.log ('data', data);
> output = "";
>
> $.each(data, function(key, value) {
> console. log ('item', key, value);
> output += " Name is: " + value.FirstName + " " +
> value.LastName + "<br>";
> });
> $('#list').html( output );
> $('#list').listview( "refresh" );
> });
> });
> });
> </script>
>
>
>
>
>
>
>
>
> --
> Thanks,
> Dave - DealTek
> dealtek@gmail.com
> [db-15]
>
>