Jump to content

pquinn

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by pquinn

  1. Thanks dude really appreciate the help and another lesson learnt Thanks again, P Quinn
  2. Hello, I have a slight issue with some of my code; basically I have used an array_sum to calculate all entries made to users UPNs (a unique identifier). The array is adding or subtracting points where appropriate, but is displaying at the top of my webpage; 'Warning: array_sum() [function.array-sum]: The argument should be an array in /home/pquinn/public_html/demo/index.php on line 74' code on line 72 - 74: foreach($users as $row => $value){ $content .= "<tr>"; $current_points = array_sum($total_rewards[$row]) - array_sum($total_sanctions[$row]); But where I have the php code the code is working and displays: Surname - User Forename - Demo Form Class - 8de Points - 535 So the array is working in some way. The code I am using is, <?php $starting_points = 0; /* Connecting, selecting database */ include_once '/home/pquinn/public_html/demo/includes/db.php'; dbConnect("pquinn_demo"); //$result = mysql_query($sql) or die("Query failed : " . mysql_error()); $sql = "SELECT * FROM users ORDER BY formclass"; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); while($row = mysql_fetch_array($result)){ $id = $row[upn]; $users[$id][surname] = "<a href=\"user.php?id=$row[username]\"><u>$row[surname]</u></a>"; $users[$id][forename] = $row[forename]; $yeargroup = $row[yeargroup]; switch($yeargroup){ case ($yeargroup == date('Y')): $stryeargroup = '8'; break; case ($yeargroup == date('Y')+1): $stryeargroup = '9'; break; case ($yeargroup == date('Y')+2): $stryeargroup = '10'; break; case ($yeargroup == date('Y')+3): $stryeargroup = '11'; break; case ($yeargroup == date('Y')+4): $stryeargroup = '12'; break; case ($yeargroup == date('Y')+5): $stryeargroup = '13'; break; case ($yeargroup == date('Y')+6): $stryeargroup = '14'; break; } $users[$id][fomclass] = $stryeargroup.$row[formclass]; } $sql = "SELECT upn, points FROM rewards"; $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_NUM)){ $id = $row[0]; $total_rewards[$id][] = $row[1]; } $sql = "SELECT upn, points FROM sanctions"; $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_NUM)){ $id = $row[0]; $total_sanctions[$id][] = $row[1]; } // Get points $current_points = array_sum($total_rewards) - array_sum($total_sanctions); $points = $current_points + $starting_points; // Print out the rewards $content .= "<tr>\n"; $content .= "<th align=\"left\">Surname</th>\t\n"; $content .= "<th>Forename</th>\t\n"; $content .= "<th>Form Class</th>\t\n"; $content .= "<th>Points</th>\t\n"; $content .= "</tr>\n"; foreach($users as $row => $value){ $content .= "<tr>"; $current_points = array_sum($total_rewards[$row]) - array_sum($total_sanctions[$row]); $points = $current_points + $starting_points; foreach($value as $var => $value){ $content .= "<td>$value</td>\t\n"; } $users[$row][points] = $points; $content .= "<td>$points</td>\t\n"; $content .= "</tr>"; } ?> Any help would be greatly appreciated, Many Thanks and Kindest Regards, PQ
  3. Got it was missing something, but you know i cant see the difference from whatever I just did lol Thanks again to all who helped
  4. hmmmm The value will now update correctly but I have three columns: Rewards, Sanctions and TotalPoints The values for Rewards and Sanctions will update correctly but the Total Points will not. On page subtract_points.php the code I have updated to look like: <?php $subtract = $_POST['subtract']; $subtractvalue = $_POST['subtractvalue ']; // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Update Total Points query $sql = mysql_query("UPDATE UserList SET TotalPoints = (TotalPoints - $subtractvalue) WHERE Username LIKE '%$subtract%'"); ?> Basically as I reward or sanction I want the total points to reflect only the points removed so if I had picked 30 rewards and rewards the Rewards to be at 30 and TotalPoints to be at 30, but if i remove 40 I want the TotalPoints to show -10. It was working before I used the list menu that is working fine now for adding and subtracting. So close any help would be great Many Thanks, P Quinn
  5. Hi sasa, Thank you so much it is working perfectly now I will cease smacking my head off the wall hehe
  6. Hi, Thanks I have adjusted my code to be; <?php $add = $_POST['add']; ?> <?php $addvalue = $_POST['addvalue']?> <?php // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Add query $sql = mysql_query("UPDATE UserList SET Rewards = (Rewards + '%$addvaule%') WHERE Username LIKE '%$add%'"); ?> And the action is processed but the value does not update, any advice would be great. Many thanks, P Quinn
  7. Hello, Hope I am in the right part of the forum for this I have been teaching my self php for a few weeks now and I have hit a brick wall Using the following code I have been able to add or subtract values within a column in my SQL table: // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Add query $sql = mysql_query("UPDATE UserList SET Rewards = (Rewards + 10) WHERE Username LIKE '%$add%'"); But for the life me I can not figure out how to use a List/Menu with values of 10, 20, 30 & 40 to be the amount added rather than having a default amount in the query. I tried: // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Add query $sql = mysql_query("UPDATE UserList SET Rewards = (Rewards + '%$addvalue%') WHERE Username LIKE '%$add%'"); Where 'addvaule' was the id for the value: <form action="add_points.php" method="post" class="style13"> <input name="add" type="text" id="add" /> </label><label> <select name="addvalue" id="addvalue"> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> </select> <input type="submit" name="submit" value=" Reward " /> </form> Hope I am making sense head is going to explode lol,. Any help and advice would be very much appreciated. P Quinn
  8. Hello, First time posting here, my MYSQL version is 5.1.52 and I have a created a search function to find a user record and if the name is typed correctly the name and details are displayed on the search page, but if the name is typed incorrectly nothing is appearing. Basically I would like to be able to say if no record found and redirect back to the previous page. Code: <?php add = $_POST['add']; // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="Rewards"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Add query $sql = mysql_query("UPDATE Rewards SET Rewards = (Rewards + 10) WHERE Name '%$add%'"); // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Update Total Points query $sql = mysql_query("UPDATE UserList SET TotalPoints = (TotalPoints + 10) WHERE Name '%$add%'"); // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Search Query $sql = mysql_query("SELECT * FROM UserList WHERE Name '%$add%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/><img src="images/line1.jpg" alt="" width="200" height="2" />'; echo '<br/> Username: '.$row['Username']; echo '<br/>'; echo '<br/><img src="images/line2.jpg" alt="" width="200" height="2" />'; echo '<br/> Name: '.$row['Name']; echo '<br/> Year Group: '.$row['YearGroup']; echo '<br/> Form Class: '.$row['FormClass']; echo '<br/>'; echo '<br/><img src="images/line3.jpg" alt="" width="200" height="2" />'; } // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="Rewards"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); $sql = mysql_query("SELECT * FROM Rewards WHERE Name '%$add%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Rewards: '.$row['Rewards']; } // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="Sanctions"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); $sql = mysql_query("SELECT * FROM Sanctions WHERE Name '%$add%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Sanctions: '.$row['Sanctions']; } // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); $sql = mysql_query("SELECT * FROM UserList WHERE Name '%$add%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Total Points: '.$row['TotalPoints']; echo '<br/>'; echo '<br/><img src="images/line4.jpg" alt="" width="200" height="2" />'; } Any help would be greatly appreciated. Many Thanks P Quinn MOD EDIT: . . . tags added.
×
×
  • 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.