473,587 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query select as input to next query

devikacs
96 New Member
I wanted to use the select of a mysql query as the input to the next mysql query.
The output of the first query is stored in $result.
Can I do select * from $result.
If not is there any other way.
Oct 28 '07 #1
4 1945
Lumpy
69 New Member
I wanted to use the select of a mysql query as the input to the next mysql query.
The output of the first query is stored in $result.
Can I do select * from $result.
If not is there any other way.
To tell you for sure, I would need to see the code your working with for the first query, but it should work. Most likely you would set up your second query something like...

Expand|Select|Wrap|Line Numbers
  1. $query2 = "SELECT * from " . $result['fieldname'] . " any further query instructions here";
  2.  
  3.  
Oct 28 '07 #2
adamalton
93 New Member
Yeah that should be possible...[PHP]$query1="SELECT column_name FROM my_table WHERE column_name='sa usages'";
$result=mysql_q uery($query1);

$search_for = mysql_result($r esult,0,'column _name');//take the first result from query1

$query2 = "SELECT * FROM other_table WHERE other_column_na me='". $search_for ."'";
$result2 = mysql_query($qu ery2);

$final_result = mysql_result($r esult2,0,'other _column_name');[/PHP]
Oct 28 '07 #3
Lumpy
69 New Member
From looking at your code, I think you got it. I read through it a couple of times and I think it should work for you.
Oct 28 '07 #4
devikacs
96 New Member
<code=php>

$query="select * from search";
$result=mysql_q uery($query);
$num=mysql_numr ows($result);
echo $num;
$i=0;
while ($i < $num)
{
$name=mysql_res ult($result,$i, "name");
$rollno=mysql_r esult($result,$ i,"rollno");
echo"<p><b>$rol lno $name</b></p>";
$i++;
}

$year=3;
$query2="select * from ".$result."wher e year = ". $year;

$res=mysql_quer y($query2);
$num2=mysql_num rows($res);

echo $num2;
echo "something" ;
$i=0;
while ($i < $num2)
{
$name=mysql_res ult($res,$i,"na me");
$rollno=mysql_r esult($res,$i," rollno");
echo"<p><b>$rol lno $name</b></p>";
$i++;
}
</code>

This is what i have done. The first query gives proper output. But the second one doesnt print anything. The $num2 is also null. I do have values with year =3.
The php script is not generating any error.
What could possibly be wrong?
Oct 29 '07 #5

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

Similar topics

3
3953
by: Mike Cocker | last post by:
Hello, I'm quite weak at PHP, so I was hoping to get some help understanding the below code. First off, I'm trying to create a "query form" that will allow me to display the results on my screen. I grabbed this code from the net hoping that I could tweak it for my needs. I'm using MySQL, PHP and IIS and they all are running fine. As the...
3
5378
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says there is a sample file called Ixtrasp.asp, but I could not find it in my system although I installed indexing service. I followed the steps in MSDN...
4
2854
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table query. I'm having trouble doing it. Help! Here is my code so far: Sub OldRegionQuery()
3
1395
by: Rob | last post by:
I have a problem I can't seem to solve although it should be easy. I've done these many times before. But I keep getting an exception, "Line 1: Incorrect syntax near 'GetFinancialData'." This query works fine through Query Analyzer or if I do not set SQLParameter for the query. I hope someone spots what I overlooked. Please let me know...
0
2436
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in the whole. I really need MySQL wizz to give me a hand (and maybe refer me to books to get me to the wizz level myself). First off, english is a...
3
4934
by: mukeshhtrivedi | last post by:
Hi Gurus, I have created simple query as SELECT QUOTES.DATE, QUOTES.QUOTENO, QUOTES.SALESREP, QuoteItem.ITEM, QUOTES., QUOTES.CUSTOMER, QUOTES.AMOUNT, QUOTES., QUOTES.DivisionID, QUOTES.STATUS FROM QUOTES INNER JOIN QuoteItem ON QUOTES.QUOTENO = QuoteItem.QUOTENO WHERE (((QUOTES.DATE) Between And ) AND ((QUOTES.SALESREP)=) AND...
4
2037
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice with MS Access and VBA. I desperately need help with 2 queries that I am trying to put together. I want to thank anyone that can help me out with...
4
6489
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be retrieved using list/menu box. When i check only a single checkbox to insert the checked category ,selecting that category through list box gives out the...
4
4567
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The...
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.