Jump to content

Justafriend

Members
  • Content Count

    101
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Justafriend

  • Rank
    Advanced Member

Profile Information

  • Gender
    Not Telling
  1. $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT PlayerName, floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 )*3) + floor(((SUM(ScoreDiffAlt) + SUM(PdiffS)) /500)*2) + floor(SUM(PScoreReg /1500))*3 + floor(Sum(scoredifreg /1500))*2 + SUM(prereg) + SUM(st) + SUM(hb) + SUM(Sbonus) AS BB, floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 )*3) + floor(((SUM(ScoreDiffAlt) + SUM(PdiffS)) /500)*2) + floor(SUM(PScoreReg /1500))*3 + floor(Sum(scoredifreg /1500))*2 + SUM(prereg) + SUM(st) + SUM(hb) + SUM(Sbonus) + SUM(Ballots) AS TB, SUM(Ballots) AS PB FROM spplayer Group by PlayerName ') as $row) { $total4 = $row['PB']; $total5 = $row['BB']; $total6 = $row['TB']; Ok from the above code is used to generate a total of ballots awarded based on the conditions Now the catch is if i add a group by and echo it the total doesn't match what is there now and i have figured out why BUT i need a way to get the totals to match, The flaw is if i use just this part for an example floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 ) ​if the totals are jane 1100 the floor would be 1 joe 1400 the floor would be 1 sam 1500 the floor would be 1 moe 1300 the floor would be 1 ​but the issue is even though the total is 4 it is giving me a floor of 5 as the sum of the four totals is 5300 with a floor of 5 ​What i am trying to do is figure out a way of getting a correct total of all the people so it would be floor(1100/1000)+floor(1400/1000)+floor(1500/1000)+floor(1300/1000) any help would be greatly appreciated
  2. I have tried to see if i can get it to output to a webpage so i can bring it into excel before importing it to avoid dangerous results with the code below i am getting Parse error: syntax error, unexpected 'str_repeat' (T_STRING) in /home2/whambamg/public_html/teststuff/pawn/test.php on line 20 <!DOCTYPE html> <html> <?php include("config.php"); $sql = "SELECT PlayerName, floor(SUM(PlayerScore /500)) + floor(SUM(PPlayerScore /1000)) + floor(SUM(S4 /5)) + floor(Sum(P7 /3)) + SUM(PlayerBallots) + SUM(prereg) AS TB, SUM(PlayerBallots) AS PB FROM player GROUP BY PlayerName "; if($result = mysqli_query($con, $sql)){ $input = $row['PlayerName']; $multiplier = $row['TB']; string str_repeat ( string $input , int $multiplier ); // Close connection mysqli_close($con); ?> </html> I believe this will give you a better idea of what i am trying to do
  3. Just thinking about it further even if i could get it to echo out into html text where it would show it i could then put into a excel sheet then save it as a csv and import the select statement i have in my php is $sql = "SELECT PlayerName, COUNT(*) AS TG, SUM(sg) AS SG, SUM(pg) AS PG, SUM(PlayerPawn) AS PP, SUM(PlayerScore) AS PS, SUM(PPlayerPawn) AS PPP, SUM(PPlayerScore) AS PPS, SUM(PPlayerPawn + PlayerPawn) AS TP, SUM(PPlayerScore + PlayerScore) AS TS, SUM(S4) AS SS4, SUM(P7) AS PP7, floor(SUM(PlayerScore /500)) + floor(SUM(PPlayerScore /1000)) + floor(SUM(S4 /5)) + floor(Sum(P7 /3)) + SUM(prereg) AS BB, floor(SUM(PlayerScore /500)) + floor(SUM(PPlayerScore /1000)) + floor(SUM(S4 /5)) + floor(Sum(P7 /3)) + SUM(PlayerBallots) + SUM(prereg) AS TB, SUM(PlayerBallots) AS PB FROM player GROUP BY PlayerName "; what i need is that whatever Tb is to echo out the player name that many times so if TB is 5 for player woman it would echo on a page woman woman woman woman woman
  4. yes i am i need to do a final and will be done on a page i upload or in a sql script i run once The reason to be more clear is i need one entry for each ballot in ballot table The regular ballots i could do easily but the bonus Ballots gets a little more trickier They are calculated by 1 Ballot for Every 5 Games in Singles with a 4 score 1 Ballot for every 3 Games in Pards with a team score of 7 1 Ballot for Every 500 pts Combined in Single games 1 Ballot for Every 1000 pts Combined team score in Pards Games if i did a insert for every 5 games where score = 4 at game 5 6 7 8 9 it would insert a total of 5 when it should be 1 i included a link to the table its based on so you can see a better idea of what i am doing http://whambamgames.com/teststuff/pawn/players.php the issue with writing code to start is i have no clue where to even start if its even possible
  5. the table screwed up when i copied it the relevant info is xtaz2002x 3 woman 2
  6. Player Name Total Ballots Regular Ballots Bonus Ballots Singles Games Pards Games Single's Pawns Single's Scores Pards Pawns Pards Scores Singles 4s Pards 7s Total Games Total Pawns Total Score xtaz2002x 2 2 0 0 0 2 220 3 291 0 0 2 5 511 Woman 3 3 0 0 0 4 288 4 405 1 0 2 8 693 the ballot numbers will be generated at end of event but what i need to know if there is anyway that with this data i can either in a php page or a mysql query set it up so that for each player will insert the number of ballots on multiple rows in my ballot table which will have id playername BallotNumber what my desired output is from the data above 1 xtaz2002x 10000 2 xtaz2002x 10001 3 xtaz2002x 10002 4 Woman 10003 5 Woman 10004 Just need to know where i can start with if this is even possible
  7. Ok i got a code to link the edit and that part works i have almost got it all working but the inputs to populate the form are all populating with errors and I get an error on top of pages I have counted many times and everything matches up The only thing that might be the difference is do I need to have a spot for each column from db even though those columns aren't going to be ever updated here is the code I have <?php /* Allows the user to both create new records and edit existing records */ // connect to the database include("connect-db.php"); // creates the new/edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($first = '', $last ='', $error = '', $id = '') { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title> <?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1><?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1> <?php if ($error != '') { echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>"; } ?> <form action="" method="post"> <div> <?php if ($id != '') { ?> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <p>ID: <?php echo $id; ?></p> <?php } ?> Your SHG Player Name(required):<input type="text" name="commentfrom" required="required" value="<?php echo $commentfrom; ?>"/> /></br> Your Email Address(required): <input type="text" name="email" required="required" value="<?php echo $email; ?>"/> /></br> Player Or Host this is about: <input type="text" name="about" value="<?php echo $about; ?>"/> /></br> Do you Require a Director to contact you?:<p> <input type="text" name="reply" value="<?php echo $reply; ?>"/> <br/> Please include your comments here:</br><textarea name="comments" rows="10" cols="25"value="<?php echo $comments; ?>"/>></textarea></br> NNN Read <input id="NNNread" type="text" value="<?php echo $NNNread; ?>"/>></br> Habs Read <input id="HabsRead" type="text" value="<?php echo $HabsRead; ?>"/>></br> Category :</br><textarea name="category " rows="10" cols="25">value="<?php echo $category; ?>"/></textarea></br> <p>* required</p> <input type="submit" name="submit" value="Submit" /> </div> </form> </body> </html> <?php } /* EDIT RECORD */ // if the 'id' variable is set in the URL, we know that we need to edit a record if (isset($_GET['id'])) { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // make sure the 'id' in the URL is valid if (is_numeric($_POST['id'])) { // get variables from the URL/form $id = $_POST['id']; $commentfrom = htmlentities($_POST['commentfrom'], ENT_QUOTES); $email = htmlentities($_POST['email'], ENT_QUOTES); $about = htmlentities($_POST['about'], ENT_QUOTES); $reply = htmlentities($_POST['reply'], ENT_QUOTES); $comments = htmlentities($_POST['comments'], ENT_QUOTES); $NNNread = htmlentities($_POST['NNNread'], ENT_QUOTES); $HabsRead = htmlentities($_POST['HabsRead'], ENT_QUOTES); $Directorscomments = htmlentities($_POST['Directorscomments'], ENT_QUOTES); $category = htmlentities($_POST['category '], ENT_QUOTES); // check that commentfrom and email are both not empty //if ($commentfrom == '' || $email == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($id, $commentfrom, $email, $about, $reply, $comments, $NNNread, $HabsRead, $Directorscomments, $category); } { // if everything is fine, update the record in the database if ($stmt = $mysqli->prepare("UPDATE comments SET commentfrom = ?, email = ?, about = ?, reply = ?, comments = ?, NNNread = ?, HabsRead = ?, Directorscomments = ?, category = ? WHERE id=?")) { $stmt->bind_param("ssi", $commentfrom, $email, $about, $reply, $comments, $NNNread, $HabsRead, $Directorscomments, $category, $id); $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } // redirect the user once the form is updated header("Location: view.php"); } } // if the 'id' variable is not valid, show an error message else { echo "Error!"; } } // if the form hasn't been submitted yet, get the info from the database and show the form else { // make sure the 'id' value is valid if (is_numeric($_GET['id']) && $_GET['id'] > 0) { // get 'id' from URL $id = $_GET['id']; // get the recod from the database if($stmt = $mysqli->prepare("SELECT * FROM comments WHERE id=?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($id, $commentfrom, $email, $about, $reply, $comments, $NNNread, $HabsRead, $Directorscomments, $category); $stmt->fetch(); // show the form renderForm($commentfrom, $email, $about, $reply, $comments, $NNNread, $HabsRead, $Directorscomments, $category, $id); $stmt->close(); } // show an error if the query has an error else { echo "Error: could not prepare SQL statement"; } } // if the 'id' value is not valid, redirect the user back to the view.php page else { header("Location: view.php"); } } } $mysqli->close(); ?>
  8. i never even thought of that i appreciate your idea and yes that would be a lot better to work with the select code I had used from a script to quickly solve an issue till I had more time to write it
  9. I just figured out where I could put it I put it on the line above the 2nd piece of code but the issue is that this code isn't updating it just on submits acts like its posting but doesn't update the id row
  10. I am having a hard time updating a entry rather then me just pasting my whole script ill break it up so you understand where it is coming from I just don't know where to put <form action="" method="POST" enctype="multipart/form-data"> to include the data from the select box Step one a simple echo form to post all the results of the query which works perfectly <html> <?php try { $dbh = new PDO("mysql:dbname=directors;host=localhost","root",""); }catch(PDOException $e) { die('Error'); } $tableheader = false; $query = "SELECT * FROM `comments` ORDER BY `id` ASC"; $sth = $dbh->prepare($query); if(!$sth->execute()) { die('Error'); } echo "<table>"; while($row = $sth->fetch(PDO::FETCH_ASSOC)) { if($tableheader == false) { echo '<tr>'; foreach($row as $key=>$value) { echo "<th>{$key}</th>"; } echo '</tr>'; $tableheader = true; } echo "<tr>"; foreach($row as $value) { echo "<td>{$value}</td>"; } echo "</tr>"; } echo "</table>"; ?> Step 2 is to use the info from the database to create a drop down menu for the id numbers which are listed and this works fine // To get the id numbers currently in the db to update the records which need to be looked at <?php mysql_connect('localhost', 'root', ''); mysql_select_db('directors'); $sql = "SELECT id FROM comments"; $result = mysql_query($sql); echo "UPDATE RECOED NUMBER" . "<select name='id'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['id'] ."'>" . $row['id'] ."</option>"; } echo "</select>"; ?> // rest of form to use to update remaining columns </br> NNN Read <input id="NNNread" type="checkbox" value="yes"></br> Habs Read <input id="HabsRead" type="checkbox"value="yes"></br> Directors Comments:</br><textarea name="Directorscomments" rows="10" cols="25"></textarea></br> <input type="submit" value="Submit" name="submit"> </form> <?php include("config.php"); if(isset($_POST['submit'])) { $Directorscomments = $_POST['Directorscomments']; $NNNread = $_POST['NNNread']; $HabsRead = $_POST['HabsRead']; $id = $_SESSION['id']; // updating blank entrys for NNNread and HabsRead as well as to concat directors comments to one entry $sql = "UPDATE comments SET NNNread=:NNNread, HabsRead=:HabsRead, SET Directorscomments = CONCAT(Directorscomments, 'Directorscomments') WHERE id=:id"; $stmt = $db->prepare($sql); $stmt->bindValue(":Directorscomments", $Directorscomments, PDO::PARAM_STR); $stmt->bindValue(":NNNread", $NNNread, PDO::PARAM_STR); $stmt->bindValue(":HabsRead", $HabsRead, PDO::PARAM_STR); $stmt->bindValue(":id", $id, PDO::PARAM_STR); $stmt->execute(); } ?> </select> </html> and the bottom part is the rest of the form
  11. thank you for your general pointing out where to look I have it solved
  12. ok i am still working on adding a file upload size limit but have added an extension check yes I am trying to use that to post the file name to later link it back in a comments section I am now having an issue with an error replying Notice: Undefined index: TR-2_Wham_Bam_-09042017_190057.rtf in C:\xampp\htdocs\form.php on line 51 where TR-2_Wham_Bam_-09042017_190057.rtf is the file name and its still not uploading here is the updated code <!DOCTYPE html> <html> <body> <form action="" method="POST" enctype="multipart/form-data"> Your SHG Player Name(required):<input type="text" name="commentfrom" required="required" /></br> Your Email Address(required): <input type="text" name="email" required="required" /></br> Player Or Host this is about: <input type="text" name="about" /></br> Do you Require a Director to contact you?:<p> <input type="radio" name="reply" value="yes">Yes <br/> <input type="radio" name="reply" value="no">No <br/> </p> Please include your comments here:</br><textarea name="comments" rows="10" cols="25"></textarea></br> Select Chatlog to upload:<input type="file" name="chatlog" id="chatlog"></br> Select Screenshot to upload:<input type="file" name="screenshot" id="screenshot"></br> <input type="submit" value="Submit" name="submit"> </form> </body> </html> <?php if(isset($_POST["submit"])){ $hostname='localhost'; $username='root'; $password=''; $dbh = new PDO("mysql:host=$hostname;dbname=Directors",$username,$password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line $chatlog= $_FILES['chatlog']['name']; $target_dir = "upload/"; $target_file = $target_dir . basename($_FILES["chatlog"]["name"]); // Select file type $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Valid file extensions $extensions_arr = array("rtf","doc","docx","txt"); // Check extension if( in_array($imageFileType,$extensions_arr) ) $screenshot= $_FILES['screenshot']['name']; $target_dir = "upload/"; $target_file = $target_dir . basename($_FILES["screenshot"]["name"]); // Select file type $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Valid file extensions $extensions_arr = array("jpg","jpeg","png","gif"); // Check extension $sql = "INSERT INTO comments (commentfrom, email, about, reply, comments, chatlog, screenshot ) VALUES ('".$_POST["commentfrom"]."','".$_POST["email"]."','".$_POST["about"]."','".$_POST["reply"]."','".$_POST["comments"]."','".$_POST["$chatlog"]."','".$_POST["$screenshot"]."')"; } $dbh = null; ?> </body> </html>
  13. i have read through the page where you pointed me but am still it is about arrays which wont work as these are 2 diff file types and going into one entry into db or am i missing something i appreciate all your help
  14. I have a code that takes multiple text fields and 2 file uploads. First before people say i need to limit file types and images that i am working on once i get the problems i have now fixed My issues 1. I am getting an undefined variable on line 31 even though all the names match with my db 2. The files arent uploading to server which i am testing on a private pc 3 I think this has to do with issue of the undefined variable problem but I want the image links to go into the db under chat log and screenshot headings the php code <!DOCTYPE html> <html> <body> <form action="" method="POST" enctype="multipart/form-data"> Your SHG Player Name(required):<input type="text" name="commentfrom" required="required" /></br> Your Email Address(required): <input type="text" name="email" required="required" /></br> Player Or Host this is about: <input type="text" name="about" /></br> Do you Require a Director to contact you?:<p> <input type="radio" name="reply" value="yes">Yes <br/> <input type="radio" name="reply" value="no">No <br/> </p> Please include your comments here:</br><textarea name="comments" rows="10" cols="25"></textarea></br> Select Chatlog to upload:<input type="file" name="chatlog" id="chatlog"></br> Select Screenshot to upload:<input type="file" name="screenShot" id="screenShot"></br> <input type="submit" value="Submit" name="submit"> </form> </body> </html> <?php if(isset($_POST["submit"])){ $hostname='localhost'; $username='root'; $password=''; try { $dbh = new PDO("mysql:host=$hostname;dbname=Directors",$username,$password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line $folder = "upload/"; $chatlog = $folder . basename($_FILES["chatlog"]["name"]); $screenShot = $folder . basename($_FILES["screenShot"]["name"]); $sql = "INSERT INTO comments (commentfrom, email, about, reply, comments, chatlog, screenShot ) VALUES ('".$_POST["commentfrom"]."','".$_POST["email"]."','".$_POST["about"]."','".$_POST["reply"]."','".$_POST["comments"]."','".$_POST["chatlog"]."','".$_POST["screenShot"]."')"; if ($dbh->query($sql)) { echo "New Record Inserted Successfully'"; } else{ echo "Data not successfully Inserted."; } $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } } ?> </body> </html> Here is the table structure ID commentfrom email about Reply Date Submitted comments chatlog screenshot NNN read Habs Read Directors comments ID commentfrom email about Reply Date Submitted comments chatlog screenshot NNN read Habs Read Directors comments
  15. when i tried that with all the code it give me an Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pawn\listtest.php on line 59 but if i i remove the having it works no problem here is the updated code $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT username,COUNT(*) as total, FROM games GROUP BY username HAVING total > 5') as $row) { echo "<tr>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['COUNT(*)'] . "</td>"; echo "</tr>"; } ?>
×
×
  • 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.