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.
4 1945
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... -
$query2 = "SELECT * from " . $result['fieldname'] . " any further query instructions here";
-
-
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]
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.
<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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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()
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |