Jump to content

Search the Community

Showing results for tags 'json_encode'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 3 results

  1. Hi, i have an array with five values. I want to encode the array using json_encode in format: {"value1":"val","data":["name", "email"]} where value 1 is a paremeter in php and data is an array. But if i use json_encode it gives me different output here is my code: $arr['value1'] = 'val';$arr['data'] = $data //arrayjson_encode($arr); it gives me {"value1":"val1","data":{"name", "email"}} can any one tell men how to encode the array in above format?? thanks
  2. This is my script: I'm trying to save the contents of a database to json I've getting the database contents to echo out but can get it encoded into json. How can I do this or what am I doing wrong here? <?php echo '<link rel="stylesheet" href="css/styles.css" />'; // Create connection //$connection = mysqli_connect("localhost","root","","finalprojectapp"); //Localhost Connection //Check Connection if(mysqli_connect_errno($connection)){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); }else{ echo "Success, Connection Achieved"; } $result = mysqli_query($connection,"SELECT * FROM member"); while($row = mysqli_fetch_array($result)) { echo "<br/><br/>ID: <p>" . $row['id'] . "</p> Phone Number: <p>" . $row["phoneNumber"] . "</p> First Name: <p>" . $row["firstName"] . "</p> Last Name: <p>" . $row["lastName"] . "</p> Profile Picture: <p>" . $row["profilePicture"] . "</p> Photo: <p>" . $row["photo"] . "</p> Video: <p>" . $row["video"] . "</p> Text: <p>" . $row["text"] . "</p> Call: <p>" . $row["call"] . "</p> Activity: <p>" . $row["activity"] . "</p> Latitude: <p>" . $row["latitude"] . "</p> Longitude: <p>" . $row ["longitude"] . "</p> Date: <p>" . $row["date"] . "</p> Time: <p>" . $row["time"] . "</p><br/>"; } $a = array($row["id"],$row['phoneNumber'],$row['firstName'], "\xc3\xa9"); echo "Normal: ", json_encode($a), ""; mysqli_close($connection);
  3. So i am trying to get a list of items out of my MySql database but my loop is not creating the array correctly, its dropping multiple rows when the key is the same name. <?php $search = 'item1'; $con = require_once('./dbconnect.php'); mysql_select_db("packages", $con); $package = mysql_query("SELECT * FROM $search", $con); while($item = mysql_fetch_row($package)){ $arr[$item[1]] = array('description' => $item[2], 'image' => $item[3]); } echo json_encode($arr); mysql_close($con); ?> So the loop works and does actually create the array with the various 'packages' in their respective array. The issue that i am having is that mysql_fetch_row($package)) can and will contain multiple keys that are the same name but with different things in the array. For example, the database will be something like this: PACK LEV DESCRIPTION IMAGES item1 A1 description for stuff1 image1 item1 A2 description for more stuff image2 item1 B1 more stuff here image3 item2 A1 description here for item2 image1 item2 B1 description contents here image2 --------------------------------------------------------------------------------- My Above code will produce an array like this: Array ( [item1] => Array ( [description] => more stuff here [image] => image3 ) [item2] => Array ( [description] => description contents here [image] => image2 ) ) What i want the array to be is: Array ( [item1] => Array ( [A1] => Array ( [description] => description for stuff1 [image] => image1 ) [A2] => Array ( [description] => description for more stuff [image] => image2 ) [b1] => Array ( [description] => more stuff here [image] => image3 ) [item2] => Array ( [A1] => Array ( [description] => description here for item2 [image] => image1 ) [b1] => Array ( [description] => description contents here [image] => image2 ) ) ) I hope this makes sense..Thanks for looking
×
×
  • 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.