473,465 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Create 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 1940
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='sausages'";
$result=mysql_query($query1);

$search_for = mysql_result($result,0,'column_name');//take the first result from query1

$query2 = "SELECT * FROM other_table WHERE other_column_name='". $search_for ."'";
$result2 = mysql_query($query2);

$final_result = mysql_result($result2,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_query($query);
$num=mysql_numrows($result);
echo $num;
$i=0;
while ($i < $num)
{
$name=mysql_result($result,$i,"name");
$rollno=mysql_result($result,$i,"rollno");
echo"<p><b>$rollno $name</b></p>";
$i++;
}

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

$res=mysql_query($query2);
$num2=mysql_numrows($res);

echo $num2;
echo "something";
$i=0;
while ($i < $num2)
{
$name=mysql_result($res,$i,"name");
$rollno=mysql_result($res,$i,"rollno");
echo"<p><b>$rollno $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
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...
3
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...
4
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...
3
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...
0
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...
3
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,...
4
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...
4
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...
4
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.