Jump to content

jasper1106

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by jasper1106

  1. Hello all, I am a beginner at PHP and trying to form an IF statement, I'm running into a problem which I cannot seem to solve. Due to my lack of syntax knowledge I would appreciate if someone could point me in the right direction. The combo variables are sent to this page through a form and defined as these variables at the top of the page. e.g $combo0 = $_POST["combo0"]; When the results are displayed any form field which was left blank or empty I want to show "N/A" if data is detected in being sent through the form I then want the "Else" statement to take affect. Currently when I run the below statement N/A is echoed despite if data was sent through the form fields or not.... if (empty($scrap)) { echo "<h3>Submitted Scrap Results</h3> No scrap parts were booked off"; } elseif (empty($combo0) || empty($combo1) || empty($combo2) || empty($combo3) || empty($combo4)) { echo "N/A"; } else { echo "<h3>Submitted Scrap Results</h3> <b>Reason:</b> " .$combo0." - ".$combo1." - ".$combo2." - ".$combo3." - ".$combo4." <br /> <b>on machine</b> " .$mid. " - <b>No. Scrap</b> " .$noscrap. ""; } Anyone any ideas?
  2. Hi fellas, Can anyone show me why my script is still rounding up / down? printf ("<tr> %s Avg gun Ahit %%</td> %s %.2f %%</td></tr>\n",$tdo,$tdor,number_format($ahit/$fired*100, 3, '.', '')); Do I have a syntax error as I cannot get my math equation to display more than 2 decimal places even though it's set to 3? Any help or advice would be really great.
  3. Ah I never thought about converting it so the array counts it, thank you jc!
  4. Hi guys, New to PHP but learning every day. This is probably a really newbie error but I've tried multiple different ways and can't get it to work. $tableData = ''; if(mysql_num_rows($result)==0) { $tableData = "<tr><td colspan=\"4\">No results returned.</td></tr>\n"; } else { while($row = mysql_fetch_assoc($result)) { $tableData .= " <tr bgcolor='#FFFFFF' align='center'>\n"; $tableData .= " <td>{$rank}</td>\n"; $tableData .= " </tr>\n"; $rank = ($row['rank']); if ($rank == 0) { print "Cadet"; } if ($rank == 1) { print "Sergeant"; } if ($rank == 2) { print "2nd Lieutenant"; } if ($rank == 3) { print "1st Lieutenant"; } if ($rank == 4) { print "Captain"; } if ($rank == 5) { print "Major"; } if ($rank == 6) { print "Lt. Colonel"; } if ($rank == 7) { print "Colonel"; } } } ?> <table class="tables" cellspacing="0" cellpadding="0"> <tr> <th>Rank</th> </tr> <?php echo $tableData; ?> </table> When this script is run the $rank variable shows the numbers 1,2,3,4,5,6,7 instead of the textual translations for example if 0 is displayed then "cadet" should be shown instead. The current script shows the numbers in the table but prints the accurate translations at the top outside the table tag..... Can anyone show me what I've done wrong here? Thank you in advance.
  5. Pikachu thank you for your reply again. The server did flag an error when I tested this earlier however I thought this was part of the debugging and the "No results returned" also displayed. Noob error I apologize, been looking at this script way too long today. I have now corrected the variable. The "debugging" version now pulls results from the database but mjdamato's original script does not populate the table. Any ideas why this might be as I am really confused as to why this is.... it's a darn sight further than I've managed to get over the past few days, thank you so much for your help guys.
  6. Thank you for your continued help, this is basically the problem I've been battling with. It cannot be a conincidence that both scripts are failing at this point. I have directly copied your scripting mjdamato the only thing I've added is an include file at the top of the script containing the database connection details. I can confirm when echoing the values within the loop I get results. When viewing the source of the page this is all that displays: <html> <head> <style> td { padding-right: 5px; padding-left: 5px; } </style> </head> <body> <br /><br /><br /> <table border="1" style="align:center;"> <tr> <th>Host Name</th> <th>Hosted</th> <th>Reported</th> <th>Ratio H/R</th> </tr> </table> </body> </html>
  7. Thanks for your input Pikachu. The query executes and returns results through phpmyadmin.
  8. Well... I am truely puzzled now. Thank you once more for your help. You are correct in saying that no results are being returned. Double checked the connection details, table and column names are correct. If I simply just echo your alias on the page the data is read.... so I guess this proves the connections are working? echo "Host: ".$row['total_hosted']; echo " Reported: ".$row['reported'];
  9. Wow, thank you mjdamato, I really do appreciate your time. I was over complicating it as well by the looks of your suggestion, I had joins and unions and all sorts of stuff. I've tested your script, surprisingly it produces the same as the poorly written version. The table displays, no data is populated and no errors, script connects to the database and table ok... very strange indeed. Any ideas what could be causing this?
  10. Hi mjdamato, Well in someways I am glad someone else thinks this is a complete mess! I get half way through the script and my head explodes. I am a beginner at PHP and trying to teach myself, I did attempt to rewrite this with a table JOIN but again I couldn't get the results to display. In plain English this is what the script tries to do: Connects to the table: badc_mis_prog Counts the "host" column only if the reported column =1 and groups the result by the host name. For example. John John Paul Tim Tim Would display: John - 2 | Paul - 1 | Tim - 2 The rest of the script then works out percentages and report numbers. This is the stuff I just cannot get to work, I am looking to display these results in a table like: Host Name | Games Hosted (number of times reported=0 and 1) | Games Reported (number of times reported=1 appears for each host) | Ratio (percentage of successful reports, Games reported divided by Games hosted multiply by 100). All these columns must relate to each Host name. The database information is there, I am really struggling to put together the correct queries though. Any help or advice would be greatly received. Thanks a lot.
  11. anyone any ideas or could advise how to debug this page?
  12. Hi guys, I am working with an old script at the moment, there is one page which just will not populate the table results. I have tried running multiple debugging commands but the only one it flags is the line displaying saying it's not a used function. If I comment out this line, no errors are produced but the results do not enter the table. Can anyone shed some light on this please, I've spent hours and hours and banging my head against a brick wall would probably be more constructive right now. Many thanks indeed for any help or advice. <?php mysql_connect("localhost", "$db_user","$db_upwd") or die ("Error - Could not connect: " . mysql_error()); mysql_select_db("$database"); $query="select host,count(*) from badc_mis_prog group by host"; $result = mysql_query($query) or die ("Error - Query: $query" . mysql_error()); $count=0; $hosts=array(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $html_hlname=$row[0]; $html_hlname=preg_replace("/</","<",$html_hlname); $html_hlname=preg_replace("/>/",">",$html_hlname); array_push($hosts, $html_hlname,$row[1],0); $count++; } $query="select host,count(*) from badc_mis_prog where reported=1 group by host"; $result = mysql_query($query) or die ("Error - Query: $query" . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $html_hlname=$row[0]; $html_hlname=preg_replace("/</","<",$html_hlname); $html_hlname=preg_replace("/>/",">",$html_hlname); for ($i=0; $i<($count*3); $i+=3) { if ($hosts[$i] == $html_hlname) { $hosts[($i+2)]=$row[1]; last; } } } for ($i=0 ; $i<(($count-1)*3); $i+=3){ for ($j=$i+3 ; $j<($count*3); $j+=3){ if ($hosts[($i+1)] < $hosts[($j+1)]){ $temp=array(); $temp[0]=$hosts[$i]; $temp[1]=$hosts[($i+1)]; $temp[2]=$hosts[($i+2)]; $hosts[$i]=$hosts[$j]; $hosts[($i+1)]=$hosts[($j+1)]; $hosts[($i+2)]=$hosts[($j+2)]; $hosts[$j]=$temp[0]; $hosts[($j+1)]=$temp[1]; $hosts[($j+2)]=$temp[2]; } } } print "<br><br><br><center><table border=\"1\">\n"; print "<tr><td>Host Name</td><td>Hosted</td><td>Reported</td><td>Ratio H/R</td></tr>\n"; for ($i=0; $i<($count*3); $i+=3) { if ($hosts[($i+1)]<15){ break;} printf ("<tr><td> %s </td><td> %d </td><td> %d </td><td>%.1f %%</td></tr>\n",$hosts[$i],$hosts[($i+1)],$hosts[($i+2)],(($hosts[($i+2)]/$hosts[($i+1)])*100)); } print "</table></center>\n"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.