drscmd1 Posted May 22, 2013 Share Posted May 22, 2013 Hello...I'm new to this site and to html/php coding...As you can tell I'm trying to connect to and query my DB and return the results...Here is my search_percentage.php...Can someone please look this over and point me in the right direction... //Here is my HTML part <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Search Contacts</title> <style type="text/css" media="screen"> ul li{ list-style-type:none; } </style> </head> <p><body> //I'm not sure my action part is correct <center> <form method="post" action="search_percentage.php?go" id="searchform"> <table width="80%" border="1" cellpadding="10" cellspacing="0"> <tr><td>Work tickets evaluation percentages <select name="summary"> <option>summary</option> <option>High</option> <option>Medium</option> <option>Low</option> </select> <select name="status"> <option>status</option> <option>Completed</option> <option>Not Completed</option> </select> <div align="right"><input type="submit" value="Search"></div> </td></tr> </table> </form> </center> </body> </p> </html> //Here is my php part. <?php if(isset($_POST['submit']) && !empty($_POST['query'])){ $db=mysql_connect (" ", " ") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb=mysql_select_db(" "); if ((summary==High) && (status==Completed)){ $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'High')" . $priority);} elseif ((summary==High) && (status==Not_Completed)){ $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Low')" . $priority);} elseif ((summary==Medium) && (status==Completed)){ $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'Medium')" . $priority);} elseif ((summary==Medium) && (status==Not_Completed)){ $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Medium')" . $priority);} elseif ((summary==Low) && (status==Completed)){ $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'Low')" . $priority);} elseif ((summary==Low) && (status==Not_Completed)){ $result_two = mysql_query("(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Low')" . $priority);} while($row = mysql_fetch_array($result_two)) { echo $Not_Completed=$row['Not_Completed']; echo $Completed=$row['Completed']; echo $High=$row['High']; echo $Medium=$row['Medium']; echo $Low=$row['Low']; } } ?> Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 what is your perceived problem? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 24, 2013 Share Posted May 24, 2013 I think the problem is bad html. <p> tag does not precede the <body> tag (that I know of. The first td tag contains two select tags and a div and an input tag - an awful lot of stuff in one table element for some reason. I think having the div in the middle of the form creates problems sometimes. I know it's confounded me in the past. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 24, 2013 Share Posted May 24, 2013 You need to: A. Describe your desired outcome. B. Describe the existing outcome. C. Use code tags (the <> button) D. Include only relevant code. Quote Link to comment Share on other sites More sharing options...
drscmd1 Posted May 25, 2013 Author Share Posted May 25, 2013 @ Jessica...A)To query my database...B) ( ! ) Notice: Undefined variable: sql in C:\wamp\www\search1.php on line 32 Call Stack # Time Memory Function Location 1 0.0010 147528 {main}( ) ..\search1.php:0 ( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\search1.php on line 34 Call Stack # Time Memory Function Location 1 0.0010 147528 {main}( ) ..\search1.php:0 2 0.0129 154376 mysql_fetch_array ( ) ..\search1.php:34 C)I changed my code again will post... Quote Link to comment Share on other sites More sharing options...
drscmd1 Posted May 25, 2013 Author Share Posted May 25, 2013 <?php if(isset($_POST['summary']) && !empty($_POST['status'])){ $db=mysql_connect (" ", " ") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb=mysql_select_db(" "); if (('summary'=='High') && ('status'=='Completed')){ $sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'High')";} elseif (('summary'=='High') && ('status'=='Not_Completed')){ $sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Low')";} elseif (('summary'=='Medium') && ('status'=='Completed')){ $sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'Medium')";} elseif (('summary'=='Medium') && ('status'=='Not_Completed')){ $sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Medium')";} elseif (('summary'=='Low') && ('status'=='Completed')){ $sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='completed') AS T WHERE status = 'completed' AND priority = 'Low')";} elseif (('summary'=='Low') && ('status'=='Not_Completed')){ $sql="(SELECT I.priority AS priority, COUNT(*) AS items, ROUND(COUNT(*) / T.total * 100) AS percent FROM project as I, (SELECT COUNT(*) AS total FROM project WHERE status='not completed') AS T WHERE status = 'not completed' AND priority = 'Low')";} $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { echo $Not_Completed=$row['Not_Completed']; echo $Completed=$row['Completed']; echo $High=$row['High']; echo $Medium=$row['Medium']; echo $Low=$row['Low']; } } ?> Quote Link to comment Share on other sites More sharing options...
drscmd1 Posted May 25, 2013 Author Share Posted May 25, 2013 I'm trying to query my DB in the previous post with this php file but I get still the above 2 errors...Is there a better way for me to do this type of query??? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 25, 2013 Share Posted May 25, 2013 your first code has this - if ((summary==High). how are you expecting the defined constant summary to be equal to the defined constant High? then you changed it to - if (('summary'=='High'). how are you expecting the string 'summary' to be equal to the string 'High'? summery is from your form field, which you correctly used $_POST['summery'] in one place. you would need to use $_POST['summery'] every time you want to reference the submitted form field, same for $_POST['status']. Quote Link to comment Share on other sites More sharing options...
drscmd1 Posted May 25, 2013 Author Share Posted May 25, 2013 @mac_gyver I did as you said and now I get these notices: ( ! ) Notice: Undefined index: Not_Completed in C:\wamp\www\search1.php on line 36 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0 ( ! ) Notice: Undefined index: Completed in C:\wamp\www\search1.php on line 37 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0 ( ! ) Notice: Undefined index: High in C:\wamp\www\search1.php on line 38 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0 ( ! ) Notice: Undefined index: Medium in C:\wamp\www\search1.php on line 39 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0 ( ! ) Notice: Undefined index: Low in C:\wamp\www\search1.php on line 40 Call Stack # Time Memory Function Location 1 0.0043 148904 {main}( ) ..\search1.php:0 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 25, 2013 Share Posted May 25, 2013 only summery and statues were post variables from the form - $_POST['summery'], $_POST['status'] the other things were strings that you were testing if the $_POST variables were equal to. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.