logo
down
shadow

PHP/MYSQLi SQL SELECT on multiple table and return the result as json object


PHP/MYSQLi SQL SELECT on multiple table and return the result as json object

By : user2948638
Date : November 14 2020, 04:51 PM
this one helps. You're generating a separate json object for each row, and returning them one by one.
Maybe you should do this instead to return a single json object encoding your whole result set as an array.
code :
$respondhs = array();
foreach ($sqlSelect as $row) {
     $respohnds[] = json_encode($row);
}
echo $respohnds;


Share : facebook icon twitter icon
Have a select query with multiple where clauses return multiple result rows in one result table?

Have a select query with multiple where clauses return multiple result rows in one result table?


By : Vincent Teo
Date : March 29 2020, 07:55 AM
Hope that helps As has been mentioned you can use a case and perform this all in one query, however you don't need to use a subquery, although I am not a massive fan of it, MySQL allows you to use column aliases in the group by, so the following will work:
code :
SELECT  CASE WHEN (enrolled = 1 AND age >=15 AND age < 20) THEN '15-19'
            WHEN (enrolled = 1 AND age >=20 AND age < 25) THEN '20-24'
            WHEN (enrolled = 1 AND age >=25 AND age < 30) THEN '25-29'
            WHEN (enrolled = 1 AND age >=30) THEN '30+'
            ELSE 'Other'
        END AS AgeRange 
        COUNT(id) AS user_list 
FROM    tbl_users
WHERE   Enrolled = 1
AND     Age >= 15
GROUP BY AgeRange;
AGERANGE    USER_LIST
15-19       0
20-24       0
25-29       0
30+         0
SELECT  t.Name AS Age_Range,
        COUNT(u.ID) AS User_List
FROM    (   SELECT  '15-19' AS Name, 15 AS LowerBound, 20 AS UpperBound, 1 AS Enrolled
            UNION ALL
            SELECT  '20-24' AS Name, 20 AS LowerBound, 25 AS UpperBound, 1 AS Enrolled
            UNION ALL
            SELECT  '25-29' AS Name, 25 AS LowerBound, 30 AS UpperBound, 1 AS Enrolled
            UNION ALL
            SELECT  '30+' AS Name, 30 AS LowerBound, 9999999 AS UpperBound, 1 AS Enrolled
        ) t
        LEFT JOIN tbl_Users u
            ON u.Enrolled = t.enrolled
            AND u.Age >= t.LowerBound
            AND u.Age < t.UpperBound
GROUP BY t.Name;
Multiple mysqli select with json

Multiple mysqli select with json


By : Plåtburken
Date : March 29 2020, 07:55 AM
seems to work fine You need to initialize the JSON array before the outer loop, and print it at the very end, not each time through.
code :
<?php
include"../database_conn.php";
$con=mysqli_connect("localhost","admin","123456","ayurveadic");

$query_pag_data = "SELECT id from diseases";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());

$rowss = array();
while ($row = mysql_fetch_array($result_pag_data)) {
    $diseases_id = $row['id'];

    $result = mysqli_query($con,"SELECT $diseases_id FROM treatment WHERE gender_id = '10' AND diseases_id = '$diseases_id'");
    $row_gid = mysqli_fetch_array($result);
    if ($row_gid == TRUE){

        $sl_dise = mysqli_query($con,"SELECT Diseases_type, id FROM diseases WHERE id = '$diseases_id'");

        while($r = mysqli_fetch_assoc($sl_dise)) {
            $rowss[] = $r;
        }
    }
}
print json_encode($rowss);
How to encode multiple MySQLi result into correct json format?

How to encode multiple MySQLi result into correct json format?


By : Darren Hiles
Date : March 29 2020, 07:55 AM
may help you . You are resetting the $post_data in every iteration. You should just append to it.
code :
if ($result->num_rows > 0) 
{
    while($row = $result->fetch_assoc()) 
    {
        $post_data[] = array(
            'item' => array(
                'ID' => $row["id"],
                'Name' => $row["name"],
                'Category' => $row["category"],
                'Saldo' => $row["saldo"],
                'Editor' => $row["editor"],
                'Edited' => $row["reg_date"]
            )
        );
    }

    echo json_encode($post_data);
}
how do i select from multiple table and return the result to the view mvc 5

how do i select from multiple table and return the result to the view mvc 5


By : Anagha Patil
Date : March 29 2020, 07:55 AM
To fix this issue You cant pass anonymous object to View because every property of anonymous object marked internal and Views are in a different namespace. Here is great explanation.
Use ViewModel - it's the best solution.
code :
public class UserViewModel
{
   public string Surname { get; set; }
   public string Firstname { get; set; }
   public string Othernames { get; set; }
   public string Email { get; set; }
   public string StateName { get; set; }
   public string LgaName { get; set; }
}
public ActionResult Index()
{           
   var users =
    (from u in db.Users
                 join s in db.States
                     on u.StateId
                     equals s.StateId

                 join l in db.Lgas
                     on u.LgaId
                     equals l.LgaId
                 select new UserViewModel
                 {
                    Surname =  u.Surname,
                    Firstname = u.Firstname,
                    Othernames = u.Othernames,
                    Email = u.Email,
                    StateName = s.StateName,
                    LgaName = l.LgaName
                 }).ToList();


    return View(users);
}
@model List<YourViewModelNamespase.UserViewModel>
How to use a $result variable with table object in SQL query using mySQLi

How to use a $result variable with table object in SQL query using mySQLi


By : DeniZ
Date : March 29 2020, 07:55 AM
will be helpful for those in need I think from your winery table you are fetching other table name???
If so you need to fetch row from the $result and then get appropriate column from winery table (i.e. column with other table name).
code :
$sql = "SELECT * FROM".$result."WHERE wine_type='".$_GET['wine_type']."'";
$sql = "SELECT * FROM ".$result." WHERE wine_type='".$_GET['wine_type']."'";
<select name="winary_id">
    <option value="Winary ID HERE">Winary Name Here</option> // you can generate your dynamic options like this which will return id instead of name
</select>
Related Posts Related Posts :
  • how to run wordpress php snippet mysql update command from ssh and/ultimately cron
  • how to get xml tag by name
  • ModSecurity maximum post limits (PCRE limit errors)
  • Call controller/action in event listener
  • How to improve performance of contacting WebService?
  • PHP nest variable in echoed string that contains a HTML tag in the end
  • Multiple Ajax request for PHP framework
  • Debug Info from Moodle Plugin
  • passing variables through page
  • Passing PHP $result data to Javascript
  • cakePHP File Download was not found or not readable
  • batch waiting until script finishes
  • PHP variables and anchors in URL
  • php eTag generation using php
  • How to check whether the array is an Integer or Not?
  • Is it possible to install Doctrine without PEAR or Composer? If so, how?
  • Call view script of (parent) Abstract controller Zend
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org