Collecting data from a table

Posted on 2005-03-28
Medium Priority
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  

        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
Question by:megakingbob
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

Expert Comment

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;


Author Comment

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

I am an absolute beginner :-)
LVL 53

Expert Comment

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

Accepted Solution

alexhogan earned 2000 total points
ID: 13654299

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

' A new string to hold the returned value
Dim myNewString

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


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

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