473,508 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

display one result from a set of db rows

18 New Member
Hi friends, I am working on two tables. one table(A) stores id of another table(B).

I store id's in the table. with that corresponding 'id' ,i have to get the value given in table B. [php]<?php
$query = 'SELECT * FROM jos_domain where userid='. $_SESSION['userid'];
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row)
{

$level= $row->lenglish_id;
$db->setQuery("SELECT * FROM jos_elevel where id= $level");
$rows = $db->loadObjectList();
foreach ($rows as $row) { echo $row->english;
echo ",";

}
?>
</td>
</tr>[/php]the ouput is displayed has 2,3,4

i want output to be displayed has only 2
and when i request for rows[1] i need to display its corresponding value.
then 3 has to displayed and then 4 has to be displayed.

can anybody tell how to get a single value i.e., only 2 has to be displayed .
when asked for it has to display value 3 . How ? plz. thanks in advance.

regards,
ramu
May 7 '08 #1
10 4692
ronverdonk
4,258 Recognized Expert Specialist
Please provide a meaningful title to a thread. The one you used until now will not arouse much curiosity and attract many members.

Thread Title changed to better describe the problem scenario.
Please read here: Use a Good Thread Title
ALSO:
Enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

MODERATOR
May 7 '08 #2
ronverdonk
4,258 Recognized Expert Specialist
Since you use a foreach on all of the rows in the result set[php]foreach ($rows as $row) {
echo $row->english;
echo ",";[/php] it will display all values of all these rows. If you want one row only, then just fetch one row and display its value.

If this does not help you with your problem, then re-state your question.

Ronald
May 7 '08 #3
Ramu528
18 New Member
Since you use a foreach on all of the rows in the result set[php]foreach ($rows as $row) {
echo $row->english;
echo ",";[/php] it will display all values of all these rows. If you want one row only, then just fetch one row and display its value.

If this does not help you with your problem, then re-state your question.

Ronald
Hi Ronald,

here , english is column in my table. the output is 2,4,5. it means 2 of from first row,4 from second row ,and 5 from third row. if i want to fetch only first row (english) column value , what should i change in code.echo $rows->english or echo $row->english is not working. can u help me out ? plz. thanks in advance.
Ramu
May 7 '08 #4
ronverdonk
4,258 Recognized Expert Specialist
The first row is index 0 in the $rows result set, so you have to get $rows[0], e.g.[php]$rows = $db->loadObjectList();
$row = $rows[0];
echo $row->english;[/php]shows column of row 1 only.

Ronald
May 7 '08 #5
Ramu528
18 New Member
The first row is index 0 in the $rows result set, so you have to get $rows[0], e.g.[php]$rows = $db->loadObjectList();
$row = $rows[0];
echo $row->english;[/php]shows column of row 1 only.

Ronald
Hi ronald,
with the below code i am still retrieving all values from table(2 3 5)[php]foreach ($rows as $row)
{
$level= $row->lenglish_id;
$db->setQuery("SELECT * FROM jos_level where id= $level");
$rows = $db->loadObjectList();
$row = $rows[0];
echo $row->english;
}[/php]here echo $row->english; is yielding same output . reading all values 2 , 3, 5. I am strucked here. plz any changes to be made. thanks ronald for the patience.
May 7 '08 #6
ronverdonk
4,258 Recognized Expert Specialist
THIS IS YOUR SECOND AND LAST WARNING:
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
May 7 '08 #7
ronverdonk
4,258 Recognized Expert Specialist
You cannot be that strucked. You use the variable $rows (and $row) twice in an nested foreach, so it gets all mixed up. Choose for the second SELECT different var names.

Ronald
May 7 '08 #8
Ramu528
18 New Member
You cannot be that strucked. You use the variable $rows (and $row) twice in an nested foreach, so it gets all mixed up. Choose for the second SELECT different var names.

Ronald
Problem With Nested Loop::::

Hi ronald, my code goes like this......[php]<?php
$query = 'SELECT * FROM jos_domain where userid='. $_SESSION['userid'];
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row)
{

$level= $row->lenglish_id;
$db->setQuery("SELECT * FROM jos_level where id= $level");
$rowtest = $db->loadObjectList();
$rowt = $rowtest[0];
echo $rowt->english;
}
?>[/php]
But i am getting same output. i am not getting desired output. plz help me out.I am getting all values from all rows..
May 7 '08 #9
Ramu528
18 New Member
Hi Friends, I didnt get the solution for nested loop. can anybody provide me with their code how to run a nested loop and retrieve particular column of a row in a table.plz.

thanks & regards,
ramu
May 7 '08 #10
ronverdonk
4,258 Recognized Expert Specialist
Since you keep ignoring all requests to follow the Posting Guidelines and enclose any code shown within appropriate code tags, this thread is closed.

moderator
May 7 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10231
by: shreddie | last post by:
Could anyone assist with the following problem? I'm using JavaScript to hide/show table rows depending on the option selected in radio buttons. The script works fine in IE but in Firefox the...
13
3610
by: Ennio-Sr | last post by:
Hi all! After a very long struggle I finally succeded in transferring my old *.dbf file and the relating *.dbt (alias memo fields) to a pg table. For the time being I put the memo field in a...
2
4350
by: ameshkin | last post by:
I know this is probably not too hard to do, but how do I display multiple rows of a mysql query/recordset. Im having trouble doing this. I don't just want to display them, but I want to make sure...
2
7035
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
2
11992
by: j.m.osterman | last post by:
I haven't found exactly what I've been trying to do. All I am trying to do for now is just display usernames from Active Directory into a ListBox control on a page. I have found some code...
0
1938
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
2
1505
by: assgar | last post by:
Hi Multiple rows of dynamically created data is retrived from the database and displayed properly. When I get 50 rows displayed scrolling is necessary. The problem is when I scroll to see the...
2
4312
by: vinceboy | last post by:
Hi anybody. I am newbie here and would like to know that how can I validate both drop down menu and radio button from a dynamic display form.Something went wrong with my script.The radio button is...
1
1489
by: vinceboy | last post by:
Hi..guys.I have a form below which consists of movie name as label and its screening time as radio button.What I intend to do when user selected a particular radio button,the corresponding movie name...
0
7229
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,...
0
7129
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...
1
7061
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...
0
7502
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
5637
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,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
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...

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.