Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Why is this PHPscript not working???
Closed Thread
Old 02-02-2008, 01:21 PM   #1 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Why is this PHPscript not working???

I am trying to view table data from a MYSQL db. I want the script to total the "votes" field and display the total votes. Also, I want the percent field (percent of votes) to be calculated by automatically.

Table structure - Name: Caucus
Fields:

Field_id - primary (auto incr)
candidate (varchar)
votes (int)
percent (int)
<php>

<?php

require_once ('mysql.php');

$sql = "select `votes` from `caucus` while 1 ";
$list = mysql_query($sql) or die ( " Query failed : " .
mysql_error());
$total = 0;
while ( $lst = mysql_fetch_array ( $list ) )
{
$total += $lst [ 0 ] ;
}
mysql_free_result($list);
echo ( "Total votes: " . $totval . "<br>");
// again, now to show %:
// I assume field 0 is candidate, field 1 is votes
$sql = "select * from `caucus` while 1 ";
$list = mysql_query($sql) or die ( " Query failed : " .
mysql_error());
while ( $lst = mysql_fetch_array ( $list ) )
{
$perc = $lst [ 1 ] * 100 / $total ;
echo ("Candidate: " . $lst [ 0 ] . ", Percentage: " .
$perc . "<br>" ) ;
}
mysql_free_result($list);

?>
</php>
I want the script to display the total number of votes received, then output the percents for each candidate.
I'm stuck on this and it's driving me nuts.

It says: "Query failed : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'while 1' at line 1"

Thanks in advance.
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
Old 02-02-2008, 01:26 PM   #2 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Re: Why is this PHPscript not working???

Also, how do I post code?
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
Old 02-02-2008, 04:18 PM   #3 (permalink)
Yek
 
T.F's Resident Cool Guy...

Join Date: Aug 2006

Posts: 1,625

Yek is on a distinguished road

Send a message via AIM to Yek Send a message via MSN to Yek Send a message via Yahoo to Yek Send a message via Skype™ to Yek
Default Re: Why is this PHPscript not working???

To post code contain it within "[code]" tags. Send a PM to user CrazeD, he may be able to help
Yek is offline  
Old 02-02-2008, 09:26 PM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,682

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Why is this PHPscript not working???

'while' is not a MySQL parameter (to the best of my knowledge). I think what you want is WHERE. What are you trying to do with the query?
__________________

Need website help? PM me!
CrazeD is offline  
Old 02-03-2008, 10:45 AM   #5 (permalink)
 
True Techie

Join Date: Nov 2003

Location: Minneapolis, MN

Posts: 157

kizzeith is on a distinguished road

Send a message via Yahoo to kizzeith
Default Re: Why is this PHPscript not working???

I want it to count up the total in the votes field for all records and echo that...also, I want it to calculate the percentage of total votes for each candidate...
__________________
Gateway Machine - I know...I sold out...if I could do it over I'd have built like I used to
MS Vista Premium 32-bit
AMD Phenom (9500) Quad-core Processor 2.20 ghz
500GB hard drive
3GB DDR2 RAM
2 Free PCI-E slots x1
1 Free PCI-E x16
kizzeith is offline  
Old 02-03-2008, 04:50 PM   #6 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,682

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Why is this PHPscript not working???

Right, but what were you trying to do with 'while 1' in the query?
__________________

Need website help? PM me!
CrazeD is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
x800gto no longer working. Erich K Hardware Troubleshooting 2 10-06-2007 01:19 PM
headset mic isnt working rebell07 Hardware Troubleshooting 1 08-29-2007 02:40 PM
Network connection stopped working!? farmboy1984 Hardware Troubleshooting 4 04-28-2007 05:31 PM
Sound not working techn00bie Computer Audio & Multimedia 0 04-11-2007 09:33 AM
Cable connection not working. lalala123 Computer Networking & Internet Access 6 04-10-2007 01:25 PM