Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 17th, 2005, 03:43 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default comma problem!

hey,

ok, my problem is when im obtaining data from a database. I need it in this format :- "0","23","45","56"

With the code at the bottom of the page i get very close to this:-

"0","23","45","56",

the only problem is with the comma at the end. I dont want it to display a comma at the end of the list of numbers. So really i need to know when the last record has been pulled from the DB, then not add a comma to the end, does that make sense?

Could anyone throw me a hand or any ideas where i should head, it has to be in the exact fromat shown at the top of the page!

cheers
ASH

//CODE SECTION
$username = $_SESSION['username'];
$testID = 1;
//$HTTP_SERVER_VARS['QUERY_STRING'];
$query1 = "SELECT * FROM Results WHERE Username = '$username' AND TestID = '$testID' ORDER BY ResultsID DESC LIMIT 10";
$result1 = mysql_query($query1);

if($row1 = mysql_fetch_array($result1,MYSQL_ASSOC))
    {
    $result222 = $row1[TestScore];
    $comma = ",";
    $result333 = '"'.$result222.'"'.$comma;
    echo $result333;
    }
?>

My new web design domain
www.askmultimedia.co.uk
__________________
My new web design domain
www.askmultimedia.co.uk
 
Old April 17th, 2005, 04:13 PM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Simple look at this function mysql_num_rows() it will tell you how many rows that were returned. That should get you started.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
 
Old April 17th, 2005, 04:14 PM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also I was looking at your code and it is not good practice to select all fields when doing a select statment. by the looks of it you only need to select the TestScore field.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent





Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting comma in the field issaq SQL Language 0 February 20th, 2008 08:41 AM
Formatting string with comma arnabghosh SQL Server 2005 1 October 16th, 2007 01:38 AM
Problem of inverted comma indikalk PHP FAQs 0 December 19th, 2006 11:47 PM
How do I get rid of this comma?!?!?!?! tsindos Classic ASP Databases 10 February 16th, 2006 12:55 AM
How to get rid of this comma!!?! gilgalbiblewheel Classic ASP Databases 15 August 8th, 2005 06:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.