Front End Design

FrontEnd Design


Warning: Undefined variable $JSONstring in /var/www/u3315689/data/www/snip_php/_str28.php on line 85

Warning: Undefined variable $dataFromMySql in /var/www/u3315689/data/www/snip_php/_str28.php on line 85

Retrieve data from MySql table, using JSON, depending on the selected value

Example implements JSON. JSON is collection of name/value pairs in text format. Virtually all modern programming languages support them in one form or another.
1) Quiery string (default-"all") is sent to server php file
xmlhttp.send("x="+quiery string);
2) Php file addresses MySql database and fetches corresponding data.
Data ,received from database would be encoded as JSON
= json_encode();
3) XMLHttpRequest parses received data
JSON.parse(this.responseText);
4) Table would be built in a loop


function change_myselect(sel) {
  const dbParam = JSON.stringify({table:sel,limit:20});
  const xmlhttp = new XMLHttpRequest();
  xmlhttp.onload = function() {
    myObj = JSON.parse(this.responseText);
    text = "< table border='1'>"

	for(var y=0;y< myObj.name[y].length;y++){
      if(sel=='all'){
	  if(y==0){text += "<tr style='font-weight: bold;'><td>Product</td>
	  <td>Calories</td><td>Carbohydrates</td><td>Sugar</td>
	  <td>Protein</td><td>Fat</td><td>Fiber</td><td>Cholesterol</td></tr>";}
	  text += "<tr><td>" + myObj.name[y] + "</td><td>" + myObj.Calories[y] + "</td>
	  <td>" + myObj.Carbohydrates[y] + "</td><td>" + myObj.Sugar[y] + "</td>
	  <td>" + myObj.Protein[y] + "</td><td>" + myObj.Fat[y] + "</td>
	  <td>" + myObj.Fiber[y] + "</td><td>" + myObj.Cholesterol[y] + "</td></tr>";}
	  else{
	  if(y==0){text += "<tr style='font-weight: bold;'><td>Product</td><td>"+sel+" (g)</td></tr>";}
	  text += "<tr><td>" + myObj.name[y] + "</td><td>" + myObj[sel][y] + "</td></tr>";}
	  }

    text += "</table>"    
    document.getElementById("demo").innerHTML = text;
  }
  xmlhttp.open("POST", "json_encode.php", true);
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

  xmlhttp.send("x=" + sel);
}

Custom Code

  • Image Training Vocabulary
    Training new vocabulary online
  • Image Images carousel
    Carousel with parallax
  • Image Info Cards
    Profile and product cards
  • Image Rounded Corners
    Add rounded corners to layers
  • Image Compare Images
    Compare two images
  • Image Images slideshow
    Scalable Images slideshow
  • Image Clip-path
    Animation with clip-paths
  • Image Rotating Heading
    Heading moving in a circle
  • Image Simple Charts
    Simplest Charts Ever
  • Image Curved Divs
    Custom curved divs
  • Image Niper sticks
    Niper Sticks
  • Image Google Charts
    Using Google charts
  • Image Log In Form
    MySQL/PHP authenication
  • Image HTML Post
    Send HTML in you email
  • Image Google Sheets
    Embed Google sheets into web site
  • Image Flip Card
    Flip person or product card
  • Image Banner ads
    Clickable banner ads
  • Image Json+MySql
    Retrieve Data with Json and MySql
  • Image Calculate Route
    Calculate Route Length on Map
  • Image Online quest
    Online language quest
  • Image Scattered text
    Online language quest
  • Image Map with regions
    Interactive map with regions
  • Image Splitted SVG
    Splitted SVG heading
  • Image Translate Page
    Translate page into user language
  • Image Math on Page
    Display math in html