Jump to content

doforumda

Members
  • Posts

    300
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

doforumda's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. I want to use the same code which I have in my original thread. I want to extend it.
  2. I have a javascript code and want to extend this code now. how can I write a makeAMessenger function in global scope so that it triggers when user clicks document and alert THIS. IS. SPART. currently I have following code. function initiateMadness() { var sparta = { name : "Sparta" }; function madness() { alert("THIS. IS. " + this.name.toUpperCase() + "."); } document.onclick = makeAMessenger(madness, sparta); } initiateMadness();
  3. I am trying to make json data in php using json_encode() function. Then I will use this data on the client side. I acheived some of the part. My current code displays json data in this format { "data": { "tag":"home", "success":1, "error":0, "uid":"4fc8f94f1a51c5.32653037", "name":"Zafar Saleem", "profile_photo":"http:\/\/example.info\/android\/profile_photos\/profile1.jpg", "places": { "place_photo":"http:\/\/example.info\/android\/places_photos\/place1.jpg", "created_at":"2012-06-02 00:00:00", "seeked":"0" } } } { "data": { "tag":"home", "success":1, "error":0, "uid":"4fc9c413554104.22444656", "name":"Name", "profile_photo":"http:\/\/example.info\/android\/profile_photos\/profile2.jpg", "places": { "place_photo":"http:\/\/example.info\/android\/places_photos\/place2.jpg", "created_at":"2012-06-03 00:00:00", "seeked":"0" } } } { "data": { "tag":"home", "success":1, "error":0, "uid":"4fc9c48c529675.45551665", "name":"Name", "profile_photo":"http:\/\/example.info\/android\/profile_photos\/profile3.jpg", "places": { "place_photo":"http:\/\/example.info\/android\/places_photos\/place3.jpg", "created_at":"2012-06-04 00:00:00", "seeked":"20" } } } what I want to show above data in this form { "data": [ { "tag":"home", "success":1, "error":0, "uid":"4fc8f94f1a51c5.32653037", "name":"Zafar Saleem", "profile_photo":"http:\/\/example.info\/android\/profile_photos\/profile1.jpg", "places": { "place_photo":"http:\/\/example.info\/android\/places_photos\/place1.jpg", "created_at":"2012-06-02 00:00:00", "seeked":"0" } }, { "tag":"home", "success":1, "error":0, "uid":"4fc9c413554104.22444656", "name":"Name", "profile_photo":"http:\/\/example.info\/android\/profile_photos\/profile2.jpg", "places": { "place_photo":"http:\/\/example.info\/android\/places_photos\/place2.jpg", "created_at":"2012-06-03 00:00:00", "seeked":"0" } }, { "tag":"home", "success":1, "error":0, "uid":"4fc9c48c529675.45551665", "name":"Name", "profile_photo":"http:\/\/example.info\/android\/profile_photos\/profile3.jpg", "places": { "place_photo":"http:\/\/example.info\/android\/places_photos\/place3.jpg", "created_at":"2012-06-04 00:00:00", "seeked":"20" } } ] } here is my php code that generates json data database function that gets data from database public function getHome() { $result = mysql_query("SELECT * FROM places") or die(mysql_error()); // check for result $no_of_rows = mysql_num_rows($result); if ($no_of_rows > 0) { while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $data[] = $row; } return $data; /* $result = mysql_fetch_array($result); return $result; */ } else { // user not found return false; } } here is where I make json on php if($db->getHome()) { $data = $db->getHome(); foreach($data as $r) { $response['success'] = 1; $response['uid'] = $r['uid']; $response['name'] = $r['name']; $response['profile_photo'] = $r['profile_photo_path']; $response['places']['place_photo'] = $r['place_photo_path']; $response['places']['latitude'] = $r['latitude']; $response['places']['longitude'] = $r['longitude']; $response['places']['created_at'] = $r['created_at']; $response['places']['seeked'] = $r['total_completed']; echo json_encode(array('data' => $response)); } } else { $response['error'] = 1; $response['error_msg'] = 'No data available'; echo json_encode($response); }
  4. When I directly run graph api link i.e. "https://graph.facebook.com/me/home?access_token=mytoken" adding my access_token, in the browser then it shows this error { "error": { "message": "(#606) Queries for multiple source_ids require a non-zero viewer that has granted read_stream permission", "type": "OAuthException" } } any solution please?
  5. I am trying to get json data using facebook graph api through jquery. I am using the code below. I am trying to get json data using $.getJSON function but it displays this error in firebug NetworkError: 400 Bad Request - https://graph.facebook.com/me/home?access_token=mytoken here is my code <!DOCTYPE HTML> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script> <script type="text/javascript" src="script/script.js"></script> <script> $(function(){ //$('fb').fbWall(); var url = "https://graph.facebook.com/me/home?access_token=mytoken"; var html = "<ul>"; $.getJSON(url, function(json){ //console.log(json); $.each(json.data, function(i,fb){ html += "<li>" + fb.id + "</li>"; }); }); html += "</ul>"; $('.fb').animate({opacity: 0}, 500, function() { $('.fb').html(html); }); $('.fb').animate({opacity:1}, 500); }); </script> <!-- <link type="text/css" rel="stylesheet" href="styles.css" /> --> <style> .fb { width: 400px; height: 400px; border:1px solid red; } </style> <title>title</title> </head> <body> <div class="fb"> </div> </body> </html> where am I making mistake?
  6. I am making a mobile web app. This app will get news from yahoo. I am currently using jquery plugin to get these news. I am also using jquery mobile for interface. On the index page I have listview and it contains all the titles such as Top News, World News, Sports News etc. Here is index page code <html> <head> <title>Title</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width = device-width, initial-scale = 1, user-scalable = no" /> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.css" /> <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script> <script src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script> </head> <body> <div data-role="page"> <header data-role="header"> <h1>Yahoo News</h1> </header> <div data-role="content"> <ul data-role="listview" data-inset="true"> <li><a href="topNews.php" data-transition="slidedown">Top Stories</a></li> <li><a href="worldNews.php" data-transition="slidedown">World News</a></li> <li><a href="techNews.php" data-transition="slidedown">Technology</a></li> <li><a href="scienceNews.php" data-transition="slidedown">Science</a></li> <li><a href="enterNews.php" data-transition="slidedown">Entertainment</a></li> <li><a href="sportsNews.php" data-transition="slidedown">Sports</a></li> </ul> </div> <footer data-role="footer"> <h4>Footer</h4> </footer> </div> </body> So when USer clicks lets say Top Stories then it will take user to appropriate page and display top news on that page. Now it does take user to top news page but when he gets there he does not see any news. That page is empty. But when user refresh this page by clicking refresh button of the browser then it does show all the news. So my problem is that it should display the news as top news page is displayed. here is top news page code <html> <head> <title>Title</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width = device-width, initial-scale = 1, user-scalable = no" /> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.css" /> <link href="styles.css" rel="stylesheet" type="text/css" /> <script src="http://code.jquery.com/jquery-latest.js"></script> <script src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script> <script language="javascript" type="text/javascript" src="jquery.jfeed.js"></script> <script language="javascript" type="text/javascript" src="jquery.aRSSFeed.js"></script> <script type="text/javascript"> $(document).ready( function() { $('div.RSSAggrCont').aRSSFeed(); }); </script> </head> <body> <div data-role="page"> <header data-role="header"> <a href="#" data-transition="slidedown" data-rel="back" data-icon="arrow-l">Back</a> <h1>Top News</h1> </header> <div data-role="content"> <div class="RSSAggrCont" rssnum="5" rss_url="http://rss.news.yahoo.com/rss/topstories"> </div> </div> <footer data-role="footer"> <h4>Footer</h4> </footer> </div> </body> Can someone tell me where am I making mistake? Any solution Please
  7. How can I get the comments from below json data? { "data": [ { "id":"123", "from":{"name":"name","id":"12"}, "message":"Message", "comments": { "data": [ { "id":"342", "from":{"name":"name","id":"32"}, "message":"comment message 1" }, { "id":"341", "from":{"name":"name","id":"21"}, "message":"comment message 2" } ], "count":2 } }, { "id":"143", "from":{"name":"name","id":"52"}, "message":"Message", "comments": { "data": [ { "id":"362", "from":{"name":"name","id":"72"}, "message":"comment message 1" }, { "id":"341", "from":{"name":"name","id":"41"}, "message":"comment message 2" } ], "count":2 } } ] } I know how to get id, from and message. but I do not know how can I get data inside comments. here is my jquery code $.getJSON(newsfeed_url,function(d) { $.each(d.data, function(i,res) { html += "<div class='container'>"; html += "<li>"+ res.from.name +"</li>"; html += "<li class='message'>" + res.message + "</li>"; html += "<li>Comments: " + res.comments.count + "</li>"; $.each(res.comments.data, function(i, comment) { html += "<li class=''>" + comment.message + "</li>"; }); html += "</div>"; }); html += "</ul>"; $("#contents").html(html); }); my current code does get res.from.name, res.comments.count but it does not get data inside comments i.e. res.comments.data. how can I achieve it?
  8. Now I changed my .js file to this code. I am using getJSON to get photos from the server $(function(){ $('.thumbs').click(function() { var thisid = $(this).attr('id'); var url = 'http://localhost/shirt/shirt/get_tshirt'; $.getJSON(url,{id: thisid},function(data){ alert(data.shurturl); $('#contents').append("<img src='" + data.shirturl + "' />"); }); }); }); I am using php with codeigniter on the servside. here is the code for my controller <?php class Shirt extends CI_Controller { public function index() { $this->shirt_thumbs(); } public function shirt_thumbs() { $data['rows'] = $this->Model_shirt_thumbs->get_thumbs(); //var_dump($data); $this->load->view('view_home',$data); } public function get_tshirt() { extract($_GET); $sql = "SELECT * FROM shirts WHERE shirtid=$id"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) { $rows[] = array( "shirtid" => $row['shirtid'], "shirt_thumb" => $row['shirt_thumburl'], "shirturl" => $row['shirturl'] ); } $json = json_encode($rows); //$callback = $_GET['callback']; echo $json; } } ?> here is what I am getting back from the as json data [{"shirtid":"5","shirt_thumb":"shirt_designs\/thumbs\/thumb_blue_one.png","shirturl":"shirt_designs\/blue_one.png"}] but when I alert shirturl then it displays "undefined" anyone who can help? Please
  9. I am using json to display images using php codeigniter. What I am trying to do is when I click a particular t shirt image then it should display on container div tag. Currently I am getting json code in this format [{"rows":[{"shirtid":"8","shirt_thumburl":"shirt_designs\/thumbs\/thumb_blue_four.png","shirturl":"shirt_designs\/blue_four.png"}]}] So Now how can I get the shirturl from this json data to display that particular image? here is my code here is my controller class Shirt extends CI_Controller { public function index() { $this->shirt_thumbs(); } public function shirt_thumbs() { $data['rows'] = $this->Model_shirt_thumbs->get_thumbs(); //var_dump($data); $this->load->view('view_home',$data); } public function get_tshirt() { extract($_POST); $data['rows'] = $this->Model_shirt_thumbs->get_tshirt($id); $JSON_array = array($data); $JSON_response = json_encode($JSON_array); header('Contents: type/json'); echo $JSON_response; } } here is my .js file $(function(){ $('.thumbs').click(function() { var thisid = $(this).attr('id'); var url = 'http://localhost/shirt_designer/shirt/get_tshirt/'; $.ajax({ type: 'POST', url: url, data: 'id=' + thisid, dataType: 'json', success: function(result) { $('#contents').html(result.shirtid); } }); }) });
  10. Hi all, I am making a t shirt website. I have about eight t-shirt thumbnails and these thumbnails are inside div tag with class 'thumbs'. Inside this thumbs div I have hidden input field as well. The value of thumbs div is the ID of the current thumbnail which taken from mysql database. Now what am I trying to do is when user clicks thumbs div tag then in javascript it should alert me the value of hidden input of this clicked thumbs div tag. Currently it displays only the first thumbnails hidden input value i.e. 1. SO How can I make this work so that when user clicks thumbs div tag, the value of that clicked thumbs' hidden input must be alerted? here is my code so far here is thumbs page <!DOCTYPE HTML> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="script/script.js"></script> <link type="text/css" rel="stylesheet" href="styles/styles.css" /> <title>title</title> </head> <body> <div id="left_menu"> <div id="tshirt_thumbs_container"> <?php if($rows) : ?> <?php foreach($rows as $r) : ?> <?php echo ""; ?> <?php echo "<div class='thumbs'>"; ?> <?php echo "<img src='" . $r->shirt_thumburl . "' />"; ?> <?php echo "<input type='hidden' id='thumbid' value='" . $r->shirtid . "' />"; ?> <?php echo "</div>"; ?> <!-- thumbs --> <?php endforeach; ?> <?php endif; ?> </div> </div><!-- left_menu --> <div id="contents"></div> </body> </html> here is .js file $(function(){ $('.thumbs').click(function() { var thisid = $(this + 'input[type="hidden"]').val(); //var thisid = $(this + " #thumbid").attr('id'); alert(thisid); }) }); please help
  11. Hi, I am trying to display text from database in proper format but it is not working the way I want. First here is how the data is stored in database table in "desc" column [p]Today we are going to learn how can we connect to mysql database using php. It is very important to know because connecting to database is the backbone of any web application.[p] [p]So here you go![p] [p]Below is the sample code for connecting to database. Explanation for this demo is below the code[p] [c] $connect = mysql_connect("localhost","username","password"); $database = mysql_select_database("database_name"); $query = mysql_query("SELECT * FROM table_name"); [c] [p]So the first two lines are enough for connecting to database. Whereas the third line is only for querying database table to get records from a table table_name[p] [p]This was today's tutorial. Hope you like it. If you like it then like us on facebook.[p] [c] $connect = mysql_connect("localhost","username","password"); $database = mysql_select_database("database_name"); $query = mysql_query("SELECT * FROM table_name"); [c] and here is how I am trying to display it <?php $p = string_between($desc,'[p]'); ?> <?php $c = string_between($desc,'[c]'); ?> <?php $total = count($p) + count($c); ?> <?php for($i = 0; $i < $total; $i++) : ?> <?php if(isset($p[$i]) && $p[$i] != "") { ?> <?php echo "<p>" . $p[$i] . "</p>" ?> <?php } ?> <?php if(isset($c[$i]) && $c[$i] != "") { ?> <?php echo "<p><pre class='prettyprint'>" . $c[$i] . "</pre></p>" ?> <?php } ?> <?php endfor; ?> so this code displays data in this format Today we are going to learn how can we connect to mysql database using php. It is very important to know because connecting to database is the backbone of any web application. $connect = mysql_connect("localhost","username","password"); $database = mysql_select_database("database_name"); $query = mysql_query("SELECT * FROM table_name"); So here you go! $connect = mysql_connect("localhost","username","password"); $database = mysql_select_database("database_name"); $query = mysql_query("SELECT * FROM table_name"); Below is the sample code for connecting to database. Explanation for this demo is below the code So the first two lines are enough for connecting to database. Whereas the third line is only for querying database table to get records from a table table_name This was today's tutorial. Hope you like it. If you like it then like us on facebook. As you can see the code is displaying in the wrong place. the first block of code should be displayed after third paragraph. And the second block of code should be displayed at the end because the blocks are stored in this way. How can I display it the way it is in database? help!
  12. ok but how can I get that particular code which I want to put it in code snipet. for example below is the whole blog Here is we can out put string in php echo "Hello world"; So in above example I want to display "Here is how we can output string in php" normally but when it reaches to 'echo "Hello world"' then it must be put in code snippet. So how can I manage this behavior?
  13. Hi, I am getting description column from mysql db. In that description I have codes such php code. and that code is surrounded by a code /code words. So how can I display that code in proper format? Please help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.