Problem Displaying Query Result

I have been working through David's book 'Dreamweaver CS5 Training from the Source' and am attempting to adapt the tutorials for my own ideas.
My problem, I believe is in displaying the results of a database query. I want to display to the user a list of group names they are associated with.
The query looks like this:
$id = "$identity->user_id"; //logged in user
$sql = mysql_query("SELECT name
                               FROM groups
                               INNER JOIN user2group USING (group_id) // reference table contains user_id and group_id
                               WHERE user_id = $id
                               ORDER BY name")or trigger_error ( mysql_error ( ) );
while($row = mysql_fetch_array($sql)){
          $groups = $row['name'];
I attempt to display the results with:
<?php echo "$groups"; ?>
I have also tried:
$sql = mysql_query("SELECT name
                               FROM groups
                               INNER JOIN user2group USING (group_id) // reference table contains user_id and group_id
                               WHERE user_id = $id
                               ORDER BY name")or trigger_error ( mysql_error ( ) );
while($row = mysql_fetch_array($sql)){
          $groups = array();
          $groups[] = $row['name'];
and display with:
<?php echo implode('<br />', $groups); ?>
In both scenarios I get only one record displayed. (there is more than one record). The records seem to be available to display because if I change the ORDER command I get a different result.
Any help is much appreciated.
Thank you

Thank you so much for the explanation of the while loop it was extremely helpful. I was able to get my results to display correctly by including the echo statement in the while loop.
I spent several hours trying to use the array_push command with no success. I did explore the link you provided, but found many of the examples people gave to be very complicated. I would really like to start working with this command, if you would be able to provide me with an example based on my query and I can see it working I can start varying it to some of the more complicated methods given in the link.
Thank you again for your help.

Similar Messages

  • How to display query result in seperated page.

    How to display query result in seperated page, if the results are very big (more than 5000 records) and there are so many concurrent users (about 500 - 1000 users).
    Are there any solutions or frameworks?
    Plese help me .........
    thanks,
    --bhasin

    Hi,
    How to display query result in seperated page?I think RowSet will be the better technology to use in this
    situation.For more information on this please visit http://developer.java.sun.com/developer/Books/JDBCTutorial/chapter5.html
    which explains in detail about RowSets.
    Hope this helps.
    Good Luck.
    Gayam.Srinivasa Reddy
    Developer Technical Support
    Sun Microsystems
    http://www.sun.com/developers/support/

  • Many to Many - display query result?

    Greetings
    In a help desk app, the manager can assingn more than one technician to a project.
    Whe he or she assigns a project, the tech ID & project ID are inserted in a junction table. This works fine.
    The description, assigned date & due date field are static- the resolution (textarea) needs to be added to as the project progesses, as well as hours spent by each tech.
    I am running into problems displaying what the technician sees on their "contol panel".
    When the tech views the details of an ongoing project, I am getting cartesian product results.
    The tech needs to add to the resolution (textarea),  view who else is working on the project, and how many hours each has contributed.
    The project display page query:
    SELECT DISTINCT project_ID, project_num, project_desc, project_res, assign_date, assign_time, due_date, complete_dte, complete_time, assigned,
    tech_1_hours, tech_2_hours, tech_3_hours, tech_4_hours, tech_ID, junc_tech_ID, junc_project_ID
    FROM main_projects, lookup_tech, junction_project_tech
    WHERE tech_ID = #Session.user_id#
    AND project_ID = #URL.project_ID#
    AND project_ID = junc_project_ID
    AND tech_ID = junc_tech_ID
    And the math;
    <cfset 'total' = (#tech_1_hours#+#tech_2_hours#+#tech_3_hours#+#tech_4_hours#)>
    The project display repeats itself for every technicain-
    Any help with this would be greatly apprecaited.
    24 month to retirement!
    Norman

    Hi,
    Will all Students have exactly two Teachers?
    If not picture your sample with two more Students.
    One having 1 Teacher
    One having N Teachers
    Think about N, what will it be? - How would you create a table with N columns?
    If you can't easily answer above, re-consider what you are trying.
    That said, it could still be done - even if all Students do not have exactly two Teachers - and is called Pivot a dynamic number of columns.
    Examples are in FAQ
    SQL and PL/SQL FAQ
    Still a bad idea, with or without known number of teachers
    Regards
    Peter

  • 2.1 EA2 does not display query results, query works fine in sqlplus

    2.1 EA2/Windows XP 32-bit
    The following query does not show any results for Total(GB) and Free(GB) columns. The diskgroup name shows correctly.
    SELECT
    DG.name ,
    ROUND(SUM(DSK.TOTAL_MB)/1024,2) "Total (GB)",
    round(SUM(DSK.FREE_MB)/1024,2) "Free (GB)"
    FROM
    V$ASM_DISK DSK,
    V$ASM_DISKGROUP DG
    WHERE
    DSK.GROUP_NUMBER=DG.GROUP_NUMBER
    group by DG.name;
    The query works fine when run from SQL*Plus:
    SQL> SELECT
    2 DG.name ,
    3 ROUND(SUM(DSK.TOTAL_MB)/1024,2) "Total (GB)",
    4 round(SUM(DSK.FREE_MB)/1024,2) "Free (GB)"
    5 FROM
    6 V$ASM_DISK DSK,
    7 V$ASM_DISKGROUP DG
    8 WHERE
    9 DSK.GROUP_NUMBER=DG.GROUP_NUMBER
    10 GROUP BY DG.name;
    NAME Total (GB) Free (GB)
    DG1 707.98 162.32
    DG2 134.84 122.68
    SQL>
    This must be something unique to SQLDeveloper. I tested in 2.1 EA1 and 1.5.5.59.69 and the query does not show results for the Total (GB) and Free (GB) columns.

    I would like to update the problem. It seems like when SQLDeveloper is connected to ASM instance, it has trouble using the divide operator (/). For example, the following query works fine:
    SELECT
    name,
    TOTAL_MB
    FROM
    V$ASM_DISKGROUP;
    But if I try to divide the TOTAL_MB by any number, the column shows blank (the column is blank, not NULL). So, if I try to run the following query, the output will just display diskgroup names. The TOTAL_MB/1024 column shows blank.
    SELECT
    name,
    TOTAL_MB/1024
    FROM
    V$ASM_DISKGROUP;
    If I run the same query in SQL*Plus from the same desktop using the same TNS alias, it works just fine which tells me that it is a SQLDeveloper problem.
    When I am connected to a regular database, then the problem does not show up and SQLDeveloper is able to display the results even when I am using the divide operator (/).

  • Problem viewing Query Result

    Hi- I occasionally come across this issue when I run any query in SQL Developer (3.0.02), the Query Result tab shows a bold red Exclamation point and the display grid is blank. It says "Fetched 50 rows in 0.235 seconds" but the results aren't displayed. There is nothing wrong with the queries so it seems like some type of display problem but I can't figure out how to fix it. Like I said, it doesn't happen all the time and I run the same saved queries so I know it's not a problem with the actual queries. Has anyone ever seen or heard of this before?

    Hi,
    Sounds like you are using an early adopter version of 3.0. Why not upgrade to the latest production release (3.1.07.42)?
    A similar situation is described in this old thread:
    Re: Randomly not getting query results
    Regards,
    SQL Developer Team

  • Problems exporting query results to Excel

    Hi!
    I hope you can help me
    We have a web template that uses the class ZVIG_ART that we created in the transaction SE24, this class display some label in the query
    results, the problem is when we export this report to excel the label disappear. The numbers indicates the stock of the item and the label N/V indicates that the item is not in the  store's catalog. Another case is that we can have N/V items but with stock, for example the ITEM2 of the STORE3 with the label N/V-1piece.  How can we export this label to EXCEL?
               |  STORE1     |    STORE2   |  STORE3
    ITEM1      |  10 PIECES  |    N/V      |  20 PIECES
    ITEM2      |  11         |    20       | N/V-1PIECE
    Thanks in advanced.
    Veronica B.

    Hi Mari,
    Thanks for the reply.
    I can understand the resason for not being able to change the Posting Date. But what are the reasons for not being able to change the Document Date? What is the fiscal reason for not being able to change the Document Date? Please provide an example. Reversing the document doesn't work in this case as the SQ01 report would still include the incorrect date.
    Regards,
    Gary

  • Create SP that returns value and at the same time displays query result in output window

    I would like create an SP which will return the records from the table and also return value to my c# client application.
    For Example:
    Select * from employee returns all the query results in output window.
    Now I want to create an SP
    Create procedure Test
    As
    Declare @ret int,
    Select * from employee
    set @ret = Select count(*) from employee
    if @ret > 0
    return 1
    else
    return 0
    The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
    Can u pls help in this regard.

    The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
    Why?  and No!
    Why?  Your procedure generates a resultset of some number of rows.  You check the resultset for the presence of rows to determine if "anything is there".  You don't need a separate value to tell you this.  Note that it helps
    to post tsql that is syntactically correct.   While we're at it, if you just need to know that rows exist there is no need to count them since that does more work than required.  Simply test for existence using the appropriately-named function
    "exists".  E.g., if exists (select * from dbo.employee). 
    No!  A stored procedure does not display anything anywhere.  The application which executes the procedures is responsible for the consumption of the resultset; it chooses what to do and what to display. 
    Lastly, do not get into the lazy habit of using the asterisk in your tsql code.  That is not best practice.  Along with that, you should also get into the following best practice habits:
    schema-qualify your objects (i.e., dbo.employee)
    terminate every statement - it will eventually be required.

  • How to display query result like this

    I got a query...gives list of names.
    i want to display
    11.  Peter
    12. Jessica
    32. Leo
    15. Jamie
    36. Edward
    how i get static number infront of my query result.
    static number is not in order.

    Amm85 wrote:
    I got a query...gives list of names.
    i want to display
    11.  Peter
    12. Jessica
    32. Leo
    15. Jamie
    36. Edward
    how i get static number infront of my query result.
    static number is not in order.
    You could use the function queryAddColumn to add the numbers as a separate column to the query.
    Let us suppose the name of the query is "myQuery". Then you could proceed as follows
    <!---Define your "static" list of numbers --->
    <cfset staticList = "11,12,32,15,36,13,23,14,33,16,44,31,17,34,18">
    <!--- Create an array from the static list. --->
    <cfset staticNrArray = ArrayNew(1)>
    <cfset staticNrArray = listToArray(staticList)>
    <!--- Add the array as a column to the query. --->
    <cfset nColumnNumber = QueryAddColumn(myQuery, "staticNr", "integer", staticNrArray)>
    <!--- Verify whether it works as expected--->
    <cfdump var="#myQuery#">
    The list I have given here has 15 numbers. This will naturally instruct ColdFusion to add a new column named staticNr, having 15 rows. You might like to know that the queryAddColumn function enables padding.
    Here is how it works. Suppose that the query originally had only 8 rows before you added the column(of 15 rows). Then, in the new query, ColdFusion would pad the last 7 rows of the other columns with null values. If the original query  had 20 rows instead, then Coldfusion would pad the last 5 rows corresponding to the staticNr-column with null values.

  • Trying to display query results in 2 columns

    I am trying modify someone elses existing code to display the
    results of a query in 2 columns on a web page.
    The result of the existing code can be seen
    here
    Below is the code that I am trying to modify
    <table width="95%" border="0" align="center"
    cellpadding="4" cellspacing="2">
    <cfoutput query="News" startrow="#StartRow_News#"
    maxrows="#MaxRows_News#">
    <tr align="center" class="TEXTnormal">
    <td nowrap class="TEXTnormal
    style1">................................................................................. ...................................</td>
    </tr>
    <tr class="TEXTnormal">
    <td><table width="100%" border="0" cellpadding="0"
    cellspacing="0" class="TEXTnormal">
    <tr>
    <td><cfif News.ImageNameThumb gt 0>
    <a href="news_view.cfm?recordID=#News.ID#"><img
    src="uploadedimages/#News.ImageNameThumb#"
    alt="#News.ImageCaption#" hspace="8" vspace="0" border="0"
    align="left"></a>
    <cfelse>
    </cfif></td>
    <td><a href="news_view.cfm?recordID=#News.ID#"
    class="TEXThighlight">#News.Title#</a> -
    #News.Day#.#News.Month#.#News.Year# <br>
    #News.Summary#</td>
    </tr>
    </table></td>
    </tr>
    </cfoutput>
    </table>
    I have changed the above code to
    <table width="95%" border="0" align="center"
    cellpadding="4" cellspacing="2">
    <cfset LoopEndRow = CEILING(#EndRow_News#/2)>
    <cfloop
    index = "row"
    from = "#StartRow_News#"
    to = "#LoopEndRow#"
    step = "1">
    <tr class="TEXTnormal">
    <cfset breaker = 0>
    <cfloop
    index = "column"
    from = "0"
    to = "2"
    step = "1">
    <cfoutput query="News1" startrow="#StartRow_News#"
    maxrows="#MaxRows_News#">
    <td width="50%">
    <table width="100%" border="0" cellpadding="0"
    cellspacing="0" class="TEXTnormal">
    <tr>
    <td><cfif News1.ImageNameThumb gt 0>
    <a href="news_view.cfm?recordID=#News1.ID#"><img
    src="uploadedimages/#News1.ImageNameThumb#"
    alt="#News1.ImageCaption#" hspace="8" vspace="0" border="0"
    align="left"></a>
    <cfelse>
    </cfif></td>
    <td><a href="news_view.cfm?recordID=#News1.ID#"
    class="TEXThighlight">#News1.Title#</a> -
    #News1.Day#.#News1.Month#.#News1.Year# <br>
    #News1.Summary#</td>
    </tr>
    </table></td>
    <cfset breaker = breaker+1>
    <cfif breaker EQUAL 2>
    <cfbreak>
    </cfif>
    </cfoutput>
    </cfloop>
    </tr>
    </cfloop>
    </table>
    The results of this modified code can be see
    Here
    as you can see what I have done gives the correct number of
    columns (2)
    and the correct number of rows for the quantity of data (3)
    however each row shows only the first 2 pieces of data
    returned by the query
    Can I modify the query output so that it returns pieces of
    data off set by the amount of data already output?
    if so how?

    Right off the bat, you have 2 loops and I cant see why...
    So what is happening, is the outer loop is going 3 times...
    for 3 rows, then your inside loop is showing the first record, the
    Breaker var is breakign out of this loop after one row is shown.
    Then the main loop says do it again...
    You don't need nested loops to accomplish this, I dont
    understand why you would think of needing that...
    Looking at your code, just get rid of the outer loop... there
    is no need for it. You are already looping around the query object
    in the inner loop, thats all you need...
    Heres some psudeo code to help you out...
    loop around query maximum of 6 rows
    -- display data
    -- if recordcount EQ 2 or recordcount EQ 4 then
    ----- </tr><tr> <!--- this will make the new
    row --->
    end loop

  • Display Query results in excel on the Web

    Hello,
    I am trying to display data from a query in excel on the web without creating an actual file. I know that I can create a CSV file using UTL_FILE and display it but I was hoping there was a way to do it without actually creating the file. I have a procedure that looks similar to
    PROCEDURE displayAsCSV is
    cursor STUD_CURS is
    select * from students;
    BEGIN
    for STUD_REC in STUD_CURS loop
    htp.print(' " '||STUD_REC.FIRST_NAME||' " , " '||STUD_REC.LAST_NAME||' " ');
    end loop;
    END;
    Does anyone know if it is possible to display these results in excel in the browser by altering the MIME types or something similar?
    Thanks

    Check Tom's owa_sylk utility together with the appropriate mime-type.

  • Problem display query in web

    Hi experts
    We trying to see query  to the web, from query designer we are klicking to display query to web, but that open only balnk page.
    Also need a detail or step by step help link for WAD
    Please help me and get points
    Thanks in advance

    Hi,
    http://help.sap.com/saphelp_nw04s/helpdata/en/1a/456a3badc1b315e10000000a114084/frameset.htm
    Web Application Designer
    urgent help on WAD(web application designer
    WEB APPLICATION DESIGNER
    WAD(Web Application Designer)
    Check these link's on Web application Desining:
    Web Application Designer for Beginners
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/749a4622-0a01-0010-36bf-b6b30a2a3a22
    http://service.sap.com/bi -> SAP BW InfoIndex -> Web Application Design (3.x)
    http://help.sap.com/saphelp_nw04/helpdata/en/1a/456a3badc1b315e10000000a114084/frameset.htm
    Have a look at these links
    http://help.sap.com/saphelp_nw04/helpdata/en/1a/456a3badc1b315e10000000a114084/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/47/d4fed1c60a9743ade3b4cf306d5d48/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/40/8b174082fe1961e10000000a155106/content.htm
    Gothrough the how to guide "How to enhanace the standard web template" for step by step procedure with the screen shots.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/dc1d9990-0201-0010-16aa-db3c4eb8b642
    cheers
    sunil

  • Problem in query result

    Hi All,
    I have created a query and there is a keyfigure "Amount"  and characteristics are company code and calender day (key date).
    In result it should display total amount on keydate(user input)...it is displaying result if there is only single entry for amount but if there are many entries for amount on a particular day then it is showing * in amount not the total of amount.
    Please suggest what can be the problem ...
    Regards
    shweta

    You have chosen a currency field which has multiple currencies ie 1000GBP and 2000 EUR - hence * for the total
    Include the unit of currency in your query and supress result rows for the user - then you will get a total per currency code
    Or of course you coudl nodim the result and add that up (ie in the exampel above you will get 3000
    edit: sorry double post with Praveen above
    Edited by: Simon Turnbull on Dec 30, 2008 2:10 PM

  • Problems in query result with infoset and timedep infoobject

    Hi,
    I have the following situation:
    infoobject ZEMPLOYEE timedep
    Infocube 0C0_CCA_C11 (standard cost center/cost element postings)
    -> infoset with infoobject and infocube linked with outer join
    My query should show all active employees in one month without any posting in the infocube.
    My testdata looks like this:
    pernr date from    date to         cost center
    4711  01.01.1000 31.12.2002
    4711  01.01.2003 31.01.2009   400000
    4711  01.02.2009 31.12.9999
    That means the employee is only active between 01.01.2003 and 31.01.2009.
    I expect the following result in the query with key-date 31.01.2009:
    4711  01.01.2003 31.01.2009   400000
    I expect the following result in the query with key-date 01.02.2009:
    no result
    -> because the employee is not active anymore, I don't want to see him in the query.
    My query delivers the following result:
    4711  01.02.2009 31.12.9999
    The first and the last entry in master data is automatically created by the system.
    I tried to exclude the not active employees by selection over cost center in the filter (like cost center between 1 and 9999999, or exclude cost center #). But unfortunately the filter selection does not work, because obviously the attributes are not filled in the last entry.
    Is there anyone who can tell me how I can exclude the last entry in the master data in the query?
    Any help is much appreciated! Points will be assigned!
    best regards
    Chris

    HI,
    problem is that I can't use employe status in this case, beacuse for any reason the people don't use it.
    I have also tried with exceptions and conditions, but the attributes ar enot filled, so it seems that nothing works.
    Do you have any other suggestions?
    Thanks!
    best tregards
    Chris

  • How to Display Query Results in a Max Width Formatted Way?

    Hi,
    I want to run a query to show the columns within headers to be formatted in a way that looks equal in width. I just want to get the max width for each column and display each item in a max width format in a query. Thanks.
    Ex.
    First Name Last Name City
    John Sumi New York
    Jay Heely Texas

    if you are spooling a file on sql*plus use the column formatting method.
    syntax:
      COL <column_name> FORMAT a<integer>example:
      COL emp_name FORMAT a40

  • How to display query results in windows side by side in Access 2010

    In Access 2010 - when I open a query the result is desplayed in a tab.
    When I open a new query - a new tab is created - now in front of the other tab.
    I would like to see both queries at the same time.
    How is that done?

    Select File > Options.
    Click 'Current Database' in the navigation pane on the left.
    Under 'Document window options', select 'Overlapping Windows'.
    Click OK, then close and reopen the database.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

Maybe you are looking for