Jump to content

Maggan

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Maggan's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It's a member id. numeric. I'll post code in full with some tweaks, I've done to help.. recognise variables that had misleading names <?php /****************************** * EQdkp * Copyright 2002-2003 * Licensed under the GNU GPL. See COPYING for full terms. * ------------------ * rules.php * Began: Wed October 12 2005 * * $Id: poll.php,v 1.3 2005/10/12 21:09:08 Dyfrin Exp $ * ******************************/ define('EQDKP_INC', true); $eqdkp_root_path = './'; include_once($eqdkp_root_path . 'common.php'); if ($_GET[uRI_PAGE] =='viewpoll') { $user->check_auth('u_member_list'); $s_viewpoll = true; $curmli= $user->data['user_id']; $curmemberloggedin= mysql_fetch_assoc(mysql_query("SELECT * FROM " . MEMBER_USER_TABLE . " WHERE user_id='$curmli'")); $curnamememli= $curmemberloggedin['member_id']; $findcurmemlogin= mysql_fetch_assoc(mysql_query("SELECT * FROM " . MEMBERS_TABLE . " WHERE member_id='$curnamememli'")); $curnamememli2= $findcurmemlogin['member_name']; $findcurmemlogin2= mysql_fetch_assoc(mysql_query("SELECT * FROM " . W_PLAYER_TABLE . " WHERE pname='$curnamememli2'")); $pid= $findcurmemlogin2['pid']; $pname= $findcurmemlogin2['pname']; } if ($_GET[uRI_PAGE] =='addvote') { $user->check_auth('u_member_list'); $sql = "SELECT pid FROM poll WHERE pid=". $addpid; $result = mysql_query($sql) or trigger_error(mysql_error()."<PRE>".$query."</PRE>", E_USER_ERROR); $num = mysql_num_rows($result); if ( empty($pname) ) { $messagevote = "You are not logged in"; unset($addvote); $s_addpolldo = true; } if ( $num > 0) { $messagevote = "You have already voted!"; unset($addvote); $s_addpolldo = true; } if(($sea == $sky) or ($sea == $limbus) or ($sea == $salvage) or ($sea == $einherjar) or ($sea == $wyrm) or ($sky == $limbus) or ($sky == $salvage) or ($sky == $einherjar) or ($sky == $wyrm) or ($limbus == $salvage) or ($limbus == $einherjar) or ($limbus == $wyrm) or ($salvage == $einherjar) or ($salvage == $wyrm) or ($einherjar == $wyrm)) { $messagevote = "You can only give one give 5 points to one option, 4 to another, 3 to a third etc. This is to rank your priorities. Giving same value to more than one event is not allowed."; unset($addvote); $s_addpolldo = true; } else { $updac = "INSERT INTO poll VALUES ('','$addpid','$sea','$sky','$limbus','$salvage','$einherjar','$wyrm','$hnmpriority','$tuesday') "; mysql_query($updac); $s_addpolldo = true; $messagevote = "Successfully added your vote"; } } if ($_GET[uRI_PAGE] =='viewresult') { $user->check_auth('u_member_list'); $s_viewresult = true; $sqla = 'SELECT SUM(sea) AS seatotal, SUM(sky) AS skytotal, SUM(limbus) AS limbustotal, SUM(salvage) AS salvagetotal, SUM(einherjar) as sumeinherjar, SUM(wyrm) AS wyrmtotal FROM poll'; if ( !($sum_result = $db->query($sqla)) ) { message_die('Could not obtain item information', '', __FILE__, __LINE__, $sql); } while ( $sum = $db->fetch_record($sum_result) ) { $tpl->assign_block_vars('sum_row', array( 'ROW_CLASS' => $eqdkp->switch_row_class(), 'SEA_TOTAL' => $sum['seatotal'], 'SKY_TOTAL' => $sum['skytotal'], 'LIMBUS_TOTAL' => $sum['limbustotal'], 'SALVAGE_TOTAL' => $sum['salvagetotal'], 'EINHERJAR_TOTAL' => $sum['sumeinherjar'], 'WYRM_TOTAL' => $sum['wyrmtotal']) ); } $sqlb = 'SELECT * FROM poll'; if ( !($row_result = $db->query($sqlb)) ) { message_die('Could not obtain item information', '', __FILE__, __LINE__, $sql); } while ( $row = $db->fetch_record($row_result) ) { $tpl->assign_block_vars('data_row', array( 'ROW_CLASS' => $eqdkp->switch_row_class(), 'SEA' => $row['sea'], 'SKY' => $row['sky'], 'LIMBUS' => $row['limbus'], 'SALVAGE' => $row['salvage'], 'EINHERJAR' => $row['einherjar'], 'WYRM' => $row['wyrm'], 'HNM_PRIORITY' => $row['hnmprio'], 'TUESDAY' => $row['tuesday']) ); } $hnmprioy = mysql_query("SELECT * FROM poll WHERE hnmprio='yes'"); $hnmprioynum = mysql_num_rows($hnmprioy); $hnmprion = mysql_query("SELECT * FROM poll WHERE hnmprio='no'"); $hnmprionnum = mysql_num_rows($hnmprion); $tuesdayy = mysql_query("SELECT * FROM poll WHERE tuesday='yes'"); $tuesdayynum = mysql_num_rows($tuesdayy); $tuesdayn = mysql_query("SELECT * FROM poll WHERE tuesday='no'"); $tuesdaynnum = mysql_num_rows($tuesdayn); } $tpl->assign_vars(array( //Chamille vars start 'PID_LOGGED_IN' => $pid, 'P_NAME' => $pname, 'HNM_PRIORITY_YES' => $hnmprioynum, 'HNM_PRIORITY_NO' => $hnmprionnum, 'TUESDAY_PRIORITY_YES' => $tuesdayynum, 'TUESDAY_PRIORITY_NO' => $tuesdaynnum, 'F_ADD_VOTE' => 'poll.php' . $SID . '&' . URI_PAGE . '=addvote', 'S_VIEW_POLL' => $s_viewpoll, 'S_ADD_POL_DO' => $s_addpolldo, 'S_VIEW_RESULT' => $s_viewresult, 'ADD_VOTE_MESS' => $messagevote, 'L_SUBMIT' => $user->lang['submit'], 'S_REQUESTITEM' => $s_requestitem, 'S_REQUESTITEMFOR' => $s_requestitemfor) ); $pm->do_hooks('/poll.php'); $eqdkp->set_vars(array( 'page_title' => sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']), 'template_file' => 'poll.html', 'display' => true) ); ?>
  2. Changed the following two bits: $sql = "SELECT pid FROM poll WHERE pid=$pname"; $result = mysql_query($sql) or trigger_error(mysql_error()."<PRE>".$query."</PRE>", E_USER_ERROR); $num = mysql_num_rows($result); if ( $num > 0) { $messagevote = "You have already voted, $pname!"; unset($addvote); $s_addpolldo = true; } Still no go.
  3. Hm. yeah, it is. Didn't know that would be an issue. What can I do to fix?
  4. Trying to halt a program if a record already exists. This is a simple vote/poll script. The part I'm having problems with is the actual adding of the vote. I tried adding various clauses to check for, error trap if someone has already voted, if someone is logged in etc, etc. I've tried mysql_num_rows, tried tweaking the query itself, tried using fetch record (as in the code below) but for some reason it still updates database table even if that member has already voted. code: if ($_GET[uRI_PAGE] =='addvote') { $user->check_auth('u_member_list'); $sql = "SELECT pid FROM poll WHERE pid='$pname'"; $result = mysql_query($sql) or trigger_error(mysql_error()."<PRE>".$query."</PRE>", E_USER_ERROR); $row = mysql_fetch_row($result); if ( empty($pname) ) { $messagevote = "You are not logged in"; unset($addvote); $s_addpolldo = true; } if ( $row > 0) { $messagevote = "You have already voted"; unset($addvote); $s_addpolldo = true; } if(($sea == $sky) or ($sea == $limbus) or ($sea == $salvage) or ($sea == $einherjar) or ($sea == $wyrm) or ($sky == $limbus) or ($sky == $salvage) or ($sky == $einherjar) or ($sky == $wyrm) or ($limbus == $salvage) or ($limbus == $einherjar) or ($limbus == $wyrm) or ($salvage == $einherjar) or ($salvage == $wyrm) or ($einherjar == $wyrm)) { $messagevote = "You can only give one give 5 points to one option, 4 to another, 3 to a third etc. This is to rank your priorities. Giving same value to more than one event is not allowed."; unset($addvote); $s_addpolldo = true; } else { $updac = "INSERT INTO poll VALUES ('','$pname','$sea','$sky','$limbus','$salvage','$einherjar','$wyrm','$hnmpriority','$tuesday') "; mysql_query($updac); $s_addpolldo = true; $messagevote = "Successfully added your vote"; } } Can anyone spot the reason why it passes the check even if $pname already has voted?
  5. Thank you! This was a nifty little line which was incredibly helpful to debug sql. Wow. All fixed now! $reqres= mysql_query($query = "SELECT m.member_name, m.member_earned, m.member_spent, m.member_adjustment, (member_earned-member_spent+member_adjustment) AS member_current, m.member_lastraid, p.pid FROM " . MEMBERS_TABLE . " m, " . W_REQUEST_TABLE . " w RIGHT JOIN " . W_PLAYER_TABLE . " p ON m.member_name = p.pname WHERE (w.iid = '$iid') AND (w.pid = p.pid) ORDER BY member_current DESC") taking out table prefixes for (member_earned-member_spent+member_adjustment) AS member_current, did the trick
  6. mySQL version: MySQL - 4.1.21-standard Table structure Table #1 (this table is huge, so bare with me.) Name:lp_members Preset variable in file include MEMBERS_TABLE Structure: Field Type Null Default member_idsmallint(5)No member_namevarchar(30) No member_earnedfloat(11,2) No0.00 member_spentfloat(11,2) No0.00 member_adjustmentfloat(11,2) No0.00 member_statusenum('0', '1') No1 member_firstraidint(11) No0 member_lastraidint(11) No0 member_raidcountint(11) No0 member_leveltinyint(2) YesNULL member_race_idsmallint(3) No0 member_class_idsmallint(3) No0 member_rank_idsmallint(3) No0 Indexes: KeynameTypeCardinalityField PrimaryPRIMARY129member_id member_nameUNIQUE129member_name Engine: MyISAM Table #2 Name wplayer, Preset variable in file include W_PLAYER_TABLE Structure: FieldTypeNullDefault pidint(3)No pnamevarchar(30)No Indexes: KeynameTypeCardinalityField PrimaryPRIMARY62pid Table #3 Name: wrequest Preset variable in file include W_REQUEST_TABLE Structure: FieldTypeNullDefault ridint(3)No pidint(3)No0 iidint(3)No0 Indexes: KeynameTypeCardinalityField PrimaryPRIMARY74rid Notes: As you can see, pid reoccurs here too. Engine myISAM again. Now. My dilemma. Using and reading up on joins and various ways of query multiple tables at same time to get an array of rows, I haven't been able to find anything that works for me. The query roughly, that I've experimented is something like: SELECT m.member_name, (m.member_earned-m.member_spent+m.member_adjustment) AS m.member_current, m.member_earned, m.member_spent, m.member_adjustment, m.member_lastraid, p.pid, p.pname, w.rid, w.pid, w.iid FROM " . MEMBERS_TABLE . " m, " . W_PLAYER_TABLE . " p, " . W_REQUEST_TABLE . " w WHERE w.iid='$iid' AND (m.member_name = p.pname) AND (w.pid=p.pid) ORDER BY m.member_current The purpose is to get a array to loop through, with the columns I've selected. Best result I have gotten was Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Looping only through table 3 at first, I can get all the data output I want. By using mysql fetch assoc instead. But that loses the ability to order output by m.member_current since all data from MEMBERS_TABLE is gotten after the loops has already started. I thought I had it when I finally came up with: $reqres= mysql_query("SELECT m.member_name, m.member_earned, m.member_spent, m.member_adjustment (m.member_earned-m.member_spent+m.member_adjustment) AS m.member_current m.member_lastraid, p.pid FROM " . MEMBERS_TABLE . " m, " . W_REQUEST_TABLE . " w RIGHT JOIN " . W_PLAYER_TABLE . " p ON m.member_name = p.pname WHERE (w.iid = '$iid') AND (w.pid = p.pid)"); while ($row = mysql_fetch_array($reqres)) { (insert PHP formatting of output here) } but again, I get the Warning. Oh and for reassurance sake, $iid variable is working throughout rest of script. I've been trying my best, debugging this to bits. What I really want to know is, can someone come up with a query to actually do what I want this to do: Have a preset $iid that I want to look up who requested p.pid=w.pid and then loop through the member data of said player by looking up p.pname and looping through p.pname's records by setting it = to m.member_name. Then to finish it all off order this by a value I set in sql m.member_current.
×
×
  • 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.