473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to extract mysql data into json using php?

semanticnotion
i have retrieved mysql data from one table in json using the following script

Expand|Select|Wrap|Line Numbers
  1. $table_first = 'abc';
  2. $query = "SELECT * FROM $table_first";
  3. $resouter = mysql_query($query, $conn);
  4.  
  5. $set = array();
  6.  
  7. $total_records = mysql_numrows($resouter);
  8. if($total_records >= 1){
  9.  
  10.   while ($link = mysql_fetch_array($resouter, MYSQL_ASSOC)){
  11.     $set[] = $link;
  12.   }
  13. }
  14.  
  15. echo json_encode($set);
how can i retrieved data from two other tables in which there is a foreign key of this table in both of those tables. OR simply how can i retrieved data from 3 mysql tables in php.
Dec 3 '10 #1
5 2370
code green
1,726 Expert 1GB
I don't know what json does but the query will need two joins.
Maybe it is a question better asked on the MySQL forum.
I doubt you will want SELECT * when joining three tables
Dec 3 '10 #2
the join query returns all the data at once what i want to do is that to retrieved the relevant records. i.e for id 1 of first table there are 5 relevant records in second table and 3 records relevant to this in third table.
i want to print the id 1 of table one than all the relevant records of table 2 and table 3.
And same for id 2 of table 1......
Dec 3 '10 #3
code green
1,726 Expert 1GB
the join query returns all the data at once what i want to do is that to retrieved the relevant records
Which is why I suggested not to use SELECT *.
Your SELECT string should detail which fields you require.
I can't help anymore without the table structures and the required output in tabular form
Dec 3 '10 #4
my table structure is

recipe{rec_id,name,overview,category,time,image}
ingredients{ingredient_id,ingredient_name,ammount, rec_id}
instructions{instruction_id,instruction_text,rec_i d}

look at rec_id which is foreign key in both tables.

so queries should be
Expand|Select|Wrap|Line Numbers
  1. $query1="select * from recipe";
  2.  
than it should iterate in table2 against the relevant id from table1;
e.g
Expand|Select|Wrap|Line Numbers
  1. $query2="select specific_field from ingredients where rec_id='rec_id from table1';
Dec 3 '10 #5
code green
1,726 Expert 1GB
I suggest putting the query question on MySQL forum.
But MySQL won't do what you are expecting it to do.
You will need an explicit JOIN, primary-foreign keys are ignored.
Dec 3 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AMD | last post by:
Hi, I would like to have MySQL use a mapped network drive. I'd like to do this in case there is a failure of the mysql machine, I can just replace it with a new machine pointing to the same...
3
by: jonas | last post by:
Guys was wondering has any done this I need to get a heads up as i need to grab data from a databasemake some changes and then put it back in place I'm guessing the MySqlDB Module be it seems...
1
by: im2kul2 | last post by:
I'd be GREATLY APRECIATED if someone could bail me out of this one! I logged into my server an hour ago just to find that the root partition is 100% filled: /dev/mapper/VolGroup00-LogVol00...
2
by: Bill | last post by:
Hi, I try to connect to Mysql using the Mysql Connector 1.0.7. with asp.net 2.O. In "mysql.aspx", i put: <%@ import namespace="System.Data"%> <%@ Import Namespace = "MySql.Data.MySqlClient"...
10
by: Elric02 | last post by:
I'm currently trying to get access to the Python source code, however whenever I try to extract the files using the latest version of WinZip (version 10) I get the following error "error reading...
4
by: Brian Huether | last post by:
My webhost does not give me shell access. Normally, I use this sort of command on my local machine: c:\datac:\mysql\bin\mysql -uroot -pxxxxx db < file.sql My webhost gives me PhpMyAdmin...
1
by: maverickx | last post by:
Hi everyone, this is about my one project, i was planning to do like this: Firstly i printed out the source code of one html page on the DOS window, and then use PERL Regular Expression to extract...
1
by: Carmine [www.thetotalsite.it] | last post by:
Hi, I am using ASP.Net 2.0 with the MySQL Connector .Net 5.1.2.2. I added these lines to the web.config to make the connector.net able to handle the SqlConnection object (and so to bind it to a...
3
by: crocodilu2008 | last post by:
Why this not working ? Our SQL table. username email tommy tommy@example.com jane jane@example.com jack jack@example.com
0
by: Zack00000 | last post by:
Hi Guys, I have a problem with the dll of MySql connector for .NET. To illustrate the problem, I have 3 projects: First one is a wrapper for log4net (it's a logging api), it is using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.