Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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 18th, 2005, 02:58 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

while($row1 = mysql_fetch_array($result1,MYSQL_ASSOC))
            {
            $values[] = $row1[TestScore];
            }

i think it returns nothing, as i get an error message:-

Warning: Division by zero in /home/fhlinux196/a/askmultimedia.co.uk/user/htdocs/FW/website/example1.php on line 30

line 30 is:-

$column_width = $width / $columns ;

which means that $columns has nothing in it! which is set by line 17:-

$columns = count($values);

which in turn is set by the array, is there a way i could check if there is anything in the array?




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

Add
print_r($values);
to check the value of $values.

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

Everything looks ok from here. If $values is not returning anything I would put an echo $row1['TestScore']; in the while loop just to be sure the sql statment is returning what you expect. If it does not I would print_r($result1); to see what you are really getting back.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
 
Old April 18th, 2005, 03:11 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

while($row1 = mysql_fetch_array($result1,MYSQL_ASSOC))
            {
            $values[] = $row1[TestScore];
            }
        print_r($values);

That shows me nothing! so im guessing the array is blank, do i need to create the array?

Sorry if im messing with your brain!lol

thanks

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

We posted at about the same time. Read my post above. "If $values is not returning anything I would put an echo $row1['TestScore']; in the while loop just to be sure the sql statment is returning what you expect. If it does not I would print_r($result1); to see what you are really getting back."

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

also it is good practice to enclose TestScore with a single quote such as $row1['TestScore']; Without the single quote php first looks for a defined constant of TestScore.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
 
Old April 18th, 2005, 03:31 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

lol,

yeah its finally worked, it wasnt my code that was wrong, it was the querystring at the top of the code, which was blank, because i hadnt passed the value accross sucessfully!

Only by chance did i notice that! really been making me think i was a failure, in life in general!lol

Thanks for your help mate, its all fixed and working now!

cheers,
Ash

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

Glad I could help. I once spent five hours to find out I had a dollar sign in the wrong place. Talk about feeling like a failure. Now if I could only fix my CSS problem that I have been working on for a week.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
 
Old April 18th, 2005, 03:41 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

hey, thanks, it works now, it wasnt the code that was the problem, it was my querystring $testID variable that was blank, in turn returning a blank SQL query!lol, fixed it now tho!

Oh, one more thing, i need one value in this array to be 100, without the DB is there a way in which i could do this?

while($row1 = mysql_fetch_array($result1,MYSQL_ASSOC))
            {
            $values[] = $row1[TestScore];
        $values[0] = 100;
            }

ive tried this but it overwrights the first value from the database!

cheers
Ash

My new web design domain
www.askmultimedia.co.uk
 
Old April 18th, 2005, 03:46 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

$i = 0;
             while($row1 = mysql_fetch_array($result1,MYSQL_ASSOC))
             {
            $i++;
            $values[$i] = $row1[TestScore];
            $values[0] = 100;
            }

there we go, that works, thanks again, and if i could help you with CSS i would, but trust me im terrible at that too!!

My new web design domain
www.askmultimedia.co.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
conditionally setting variable ewel Beginning PHP 2 December 13th, 2007 07:39 PM
problem setting a variable jtrifts Javascript 4 August 9th, 2007 08:36 AM
Newbie : How do you .. without setting a variable rqaran XSLT 2 August 6th, 2005 04:09 AM
declare a variable without setting a value to it crmpicco Javascript How-To 1 July 18th, 2005 07:25 PM
Setting a variable using Select Case Adam ASP.NET 1.0 and 1.1 Basics 2 September 4th, 2004 02:09 PM





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