Skip to content

Instantly share code, notes, and snippets.

@sadeghmohebbi
Created July 27, 2016 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadeghmohebbi/ef6e1e7b5a529596396a7d58f462ef7e to your computer and use it in GitHub Desktop.
Save sadeghmohebbi/ef6e1e7b5a529596396a7d58f462ef7e to your computer and use it in GitHub Desktop.
<?php
$con=mysqli_connect("---","---","---","---");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$temp=array();
$result = mysqli_query($con,"SELECT * FROM user");
while($row = mysqli_fetch_array($result)){
$temp["name"]=$row["name"];
$temp["email"]=$row["email"];
$temp["pass"]=$row["pass"];
$temp["imageid"]=$row["imageid"];
$temp["credit"]=$row["credit"];
$temp["state"]=$row["state"];
$response["user"]=array();
array_push($response["user"],$temp);
$response["t"]=1;
echo json_encode($response);
}
mysqli_close($con);
?>
//----------------------------------------result
{"user":[{"name":"sadegh mohebbi","email":"mohebbi_sadegh@yahoo.com","pass":"2221689","imageid":"notset","credit":"notset","state":"notset"}],"t":1}
{"user":[{"name":"hadimohebbi","email":"h.mohebbi313@gmail.com","pass":"hahshahs","imageid":"notset","credit":"notset","state":"notset"}],"t":1}
@sadeghmohebbi
Copy link
Author

sadeghmohebbi commented Jul 28, 2016

$row[1]), array('email'=>$row[2]), array('pass'=>$row[3]), array('imageid'=>$row[4]), array('credit'=>$row[5]), array('state'=>$row[6])); } echo json_encode(array("user"=>$result)); mysqli_close($con); ?>

this is another php code that I try it.
result is fun:
{"user":[{"name":"sadegh mohebbi"},{"email":"mohebbi_sadegh@yahoo.com"},{"pass":"2221689"},{"imageid":"notset"},{"credit":"notset"},{"state":"notset"},{"name":"sina sinaee"},{"email":"sinson@hotmail.com"},{"pass":"123456"},{"imageid":"notset"},{"credit":"notset"},{"state":"notset"},{"name":"hadimohebbi"},{"email":"h.mohebbi313@gmail.com"},{"pass":"hahshahs"},{"imageid":"notset"},{"credit":"notset"},{"state":"notset"}]}

what shall I do? Its hard problem

@sadeghmohebbi
Copy link
Author

sadeghmohebbi commented Jul 28, 2016

solved!!!
I try this code:

0) { $response["user"] = array(); while ($row = mysql_fetch_array($result)) { $product = array(); $product["name"] = $row["name"]; $product["email"] = $row["email"]; $product["pass"] = $row["pass"]; $product["imageid"] = $row["imageid"]; $product["credit"] = $row["credit"]; $product["state"] = $row["state"]; array_push($response["user"], $product); } $response["success"] = 1; echo json_encode($response); } else { $response["success"] = 0; $response["message"] = "No products found"; echo json_encode($response); } ?>

happy coding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment