?
Solved

Collecting data from a table

Posted on 2005-03-28
4
Medium Priority
?
138 Views
Last Modified: 2010-04-25
I have some data in a table, i would like to collect all the data in one column so that the data can be copied else where  

e.g.
        name weight
        fish     400
        cow    40000
        man    8000

i would like the 400, 40000 and 8000 collected and copied elsewhere (such as a textbox in the same page) as text as well as a + sign between them  "400+40000+8000"

Any advice please
0
Comment
Question by:megakingbob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:alexhogan
ID: 13647647
Rreturning the contents of a field is easy.  You would set your query to get that information.

Depending on what server side language you're using taking that data and formatting it is pretty easy and straight forward as well.  You will want to put the results in an array and then parse the array, replacing the commas with your plus sign.

Using PHP lets query the database and get the returned results, parse the data and print out to the screen.

$query   =   "SELECT myField
                   FROM myTable";

$result   =   mysql_query($query) or die;

while($row     =   mysql_fetch_assoc($result)){
    $myArray[] =   $row['myField'];
}

echo implode('+', $myArray);

This will return and print to the screen something like;
400+40000+8000

0
 

Author Comment

by:megakingbob
ID: 13651239
i should have said i'm using ASP JavaScript and where would i put this code

I am an absolute beginner :-)
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 13653563
Do you have any existing scripts where you can post here?
0
 
LVL 8

Accepted Solution

by:
alexhogan earned 2000 total points
ID: 13654299
OK..,

In ASP....

'Assign Database Connection String And Location
dbString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/foldername/cars.mdb")

'Creating A Connection Object
Set conn = CreateObject("ADODB.Connection")
sConn.Open dbString

'Assign Variable To Store Database Results
sResult = CreateObject("ADODB.Recordset")
sResult.Open "SELECT myField FROM myTable, sConn

'Dimension an array and a counter variable
Dim myArray()
Dim i

i  =  1

Do While Not result.EOF
  myArray(i)  =  sResult.Field("myField").Value
  i  =  i + 1
  sResult.MoveNext
Loop

' A new string to hold the returned value
Dim myNewString

myNewString  =  Replace(myArray, ",","+")

Response.Write(myNewString)

I haven't tried this code but it should work.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question