473,320 Members | 1,896 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,320 software developers and data experts.

Query inside another query

HI all, how are you ? i need help from you people. This time my problem is that i m running a query inside another query. But, the result that i got is something not exactly what i want. and one problem its only showing the result that is affected by the inside query.

syntaxt is some thing like this

[PHP]$sql = "run some query";
$result = mysql_query($sql);
while($rows= mysql_fetch_array($result))
{
// inside query i access one field name to accesss from other table
$sql2 = query ..
// the problem is the result is showing only those pages which is affected by $sql2 query.
}[/PHP]
i m giving the code below and plz find out the problem [PHP]$sql = "SELECT * FROM telnumbertable";
$result = mysql_query($sql) or die(mysql_error());
//$num_rows = mysql_num_rows($result) or die(mysql_error());

if(mysql_affected_rows()>0)
{
echo "<table width=\"100%\" border=\"0\" cellpadding=\"1\">";
echo "<tr><td>SL No</td><td>Telephone No</td><td>Service Provider</td><td>Authorized Amount</td><td>No. of User</td><td> Detailed</td><td>Update</td><td>Delete</td></tr>";
$i=1;
$no = 1;
while($row = mysql_fetch_array($result))
{
$telNumber = $row['telNumber'];
f$sql3 = mysql_query("SELECT * from userdetails where telNumber = '$telNumber' ") or die (mysql_error());
$rows = mysql_num_rows($sql3) or die(mysql_error());
if($rows>0)
{
$total = $rows;
}
else
{
$total = "No user";
}
if($i%2=="0")
{
$bg = "#808080";
}
else
{
$bg = "#C0C0C0";
}
$id = $row['id'];
echo "<tr bgcolor=$bg>";
echo "<td>00".$no."</td>";
echo "<td>".$row['telNumber']."</td>";
echo "<td>".$row['serProvider']."</td>";
echo "<td>Rs.".$row['authAmount']."/-</td>";
echo "<td><a href=\"user_detailed_by_number.php?mobileID=$id\"> ".$total."</a></td>";
echo "<td><a href=\"view2.php?mobileID=$id\">Detail</a></td>";
echo "<td><a href=\"update.php?id=$id\">Update</a></td>";
echo "<td><a href=\"delete.php?id=$id\">Delete</a></td>";
echo "</tr>";
$i++;
$no++;
}

echo "</table>";
}[/PHP]

please help me
Jan 18 '08 #1
3 2045
rpnew
188 100+
hi,
Can you explain what is your exact problem ? I mean from first go your code seems ok so let me know what do you want in output and what are you getting instead. So that we can find the problem in code.

Regards,
RP
Jan 18 '08 #2
Actually, in my database, i have two table one is "telnumberdetail" to store all the
availble number and other tabel userdetails where the detail each user is stored.
you can see in the first line
$sql = "select * from telnumber" i retrieved all the details.

now i want is that i want to show how many user where assigned to this particular telephone number. but this inforamtion is availble only in userdetails table.
so, using the $sql3 i count the no of rows affrected ,

Now the problem is that, while show the result in the pages, its showing only only those number / row of telnumberdetail where i assigned some user but those no which i dont assigned are not showing. But when i remove the code from line number 13 to 23, its working fine, but i canot show the no of users.
So please help me in finding out the solution. I hope u got what i want to show. ok waiting for your reply
hi,
Can you explain what is your exact problem ? I mean from first go your code seems ok so let me know what do you want in output and what are you getting instead. So that we can find the problem in code.
Regards,
RP
Jan 18 '08 #3
rpnew
188 100+
Actually, in my database, i have two table one is "telnumberdetail" to store all the
availble number and other tabel userdetails where the detail each user is stored.
you can see in the first line
$sql = "select * from telnumber" i retrieved all the details.

now i want is that i want to show how many user where assigned to this particular telephone number. but this inforamtion is availble only in userdetails table.
so, using the $sql3 i count the no of rows affrected ,

Now the problem is that, while show the result in the pages, its showing only only those number / row of telnumberdetail where i assigned some user but those no which i dont assigned are not showing. But when i remove the code from line number 13 to 23, its working fine, but i canot show the no of users.
So please help me in finding out the solution. I hope u got what i want to show. ok waiting for your reply
Hi,
If you are still facing the same problem.. then try following.....
In your code line no 15 is like this.
[php]
$rows = mysql_num_rows($sql3) or die(mysql_error());
[/php]
Change it to this
[php]
$rows = mysql_num_rows($sql3);
[/php]

And try....
Well even i'm not expert of PHP/MySql but what i got after trying your code is... whenever mysql_num_rows() is getting null as output of query its throwing error and dying. So your code is not giving output wherever it is null and in my case it has just stopped showing output wherever it got the first NULL...... Some experts here can throw some light on what exactly happening here... but till then try what i told you and get back here with result.....

Regards,
RP
Jan 21 '08 #4

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

Similar topics

14
by: Bruce W...1 | last post by:
I do a query to MySQL using PHP. Well actually I do too many of them which is the problem, it's too slow. I think maybe an inner join or something would be better but I can't figure this out. ...
3
by: Thomas R. Hummel | last post by:
Hi, I was just helping a coworker optimize a query. He had two versions: one which used UNION for each value for which he was tallying results and another query which used GROUP BY. Here is an...
3
by: Stefan Goerres | last post by:
Hello, I have put a function myfunc(val1, val2) which I call in a query. So far I only have arguments from the actual row there is no problem. But I can't make it working that i use a value from...
12
by: Irene | last post by:
Hi all again, Well, I have my Athletics database with Athletes, Competitions, Scores tables. I have a ranking query where I get back the list of the competitions-athletes and scores...
4
by: Richard Hollenbeck | last post by:
The following query takes about one second to execute with less than 1,000 records, but the report that's based on it takes from 15-30 seconds to format and display. That's frustrating for both me...
12
by: strict9 | last post by:
Hello all, I'm writing several queries which need to do various string formating, including changing a phone number from (123) 456-7890. After some problem with data mismatches, I finally got it...
9
by: David Horowitz | last post by:
Hi. I have a query named Query1. Let's say it looks like this: Select * from Table1 where Field1= So whenever you run the query, it prompts for "Enter Value". So now, I have Report1, whose...
2
by: Zlatko Matiæ | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
1
by: Stephen D Cook | last post by:
I have a form with txtSN text box, btnShow button, and a subform. The form is bound to a Table. The button is bound to a lookup query. The query is bound to the text box. I want to be able to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.