blacknight Posted April 4, 2007 Share Posted April 4, 2007 ok i have an array that deines things by number fro example array( {1] = "NooB", [2] = "Expert" ) but then its sapose to be inserted in to the database all i get is the first lettera nd i have no i dea why this is happaning because i can echo the same value and it shows as the fill value any ideas or help please Quote Link to comment Share on other sites More sharing options...
btherl Posted April 4, 2007 Share Posted April 4, 2007 Please post your code. Quote Link to comment Share on other sites More sharing options...
blacknight Posted April 4, 2007 Author Share Posted April 4, 2007 if (isset($guildRanks[$char['Rank']]['Title'])){ $rnk = $guildRanks[$char['Rank']]['Title']; }else{ $rnk = $guildRanks[$char['Rank']]; } $guildRanks is the defined array Quote Link to comment Share on other sites More sharing options...
trq Posted April 4, 2007 Share Posted April 4, 2007 How about posting the part that inserts into the database? Were not freaking mind readers! Quote Link to comment Share on other sites More sharing options...
blacknight Posted April 4, 2007 Author Share Posted April 4, 2007 whole code that uses the given array function update_guild_member( $guildId, $name, $char, $currentTimestamp, $guildRanks ) { $name_escape = $this->escape( $name ); $querystr = "SELECT `member_id` FROM `".ROSTER_MEMBERSTABLE."` WHERE `name` = '$name_escape' AND `guild_id` = '$guildId'"; $result = $this->query($querystr); if( !$result ) { $this->setError('Member could not be selected for update',$this->error()); return; } $memberInfo = $this->fetch_assoc( $result ); if ($memberInfo) $memberId = $memberInfo['member_id']; if (isset($guildRanks[$char['Rank']]['Title'])){ $rnk = $guildRanks[$char['Rank']]['Title']; }else{ $rnk = $guildRanks[$char['Rank']]; } //print $rnk; $this->closeQuery($result); $this->reset_values(); $this->add_value( 'name', $name_escape); $this->add_value( 'class', $char['Class']); $this->add_value( 'level', $char['Level']); if( isset($char['Note']) ) $this->add_value( 'note', $char['Note']); else $this->add_value( 'note', ''); $this->add_value( 'guild_rank', $char['Rank']); $this->add_value( 'guild_title', $rnk); if( isset($char['OfficerNote']) ) $this->add_value( 'officer_note', $char['OfficerNote']); else $this->add_value( 'officer_note', ''); $this->add_value( 'zone', $char['Zone']); if( isset($char['Status']) ) $this->add_value( 'status', $char['Status']); else $this->add_value( 'status', ''); $this->add_time( 'update_time', getDate($currentTimestamp)); if( $char['Online'] == '1' ) { $this->add_value( 'online', 1 ); $this->add_time('last_online', getDate($currentTimestamp)); } else { $this->add_value( 'online', 0 ); list($lastOnlineYears,$lastOnlineMonths,$lastOnlineDays,$lastOnlineHours) = explode(':',$char['LastOnline']); # use strtotime instead # $lastOnlineTime = $currentTimestamp - 365 * 24* 60 * 60 * $lastOnlineYears # - 30 * 24 * 60 * 60 * $lastOnlineMonths # - 24 * 60 * 60 * $lastOnlineDays # - 60 * 60 * $lastOnlineHours; $timeString = '-'; if ($lastOnlineYears > 0) $timeString .= $lastOnlineYears.' Years '; if ($lastOnlineMonths > 0) $timeString .= $lastOnlineMonths.' Months '; if ($lastOnlineDays > 0) $timeString .= $lastOnlineDays.' Days '; $timeString .= max($lastOnlineHours,1).' Hours'; $lastOnlineTime = strtotime($timeString,$currentTimestamp); $this->add_time( 'last_online', getDate($lastOnlineTime) ); } if( $memberId ) { $querystr = "UPDATE `".ROSTER_MEMBERSTABLE."` SET ".$this->assignstr." WHERE `member_id` = '$memberId' AND `guild_id` = '$guildId'"; $this->setMessage('<li>[ '.$name.' ]</li>'); $this->membersupdated++; $result = $this->query($querystr); if( !$result ) { $this->setError(''.$name.' could not be inserted',$this->error()); return; } } else { // Add the guild Id first if( !empty($guildId) ) $this->add_value( 'guild_id', $guildId); $querystr = "INSERT INTO `".ROSTER_MEMBERSTABLE."` SET ".$this->assignstr; $this->setMessage('<li><span class="green">[</span> '.$name.' <span class="green">] - Added</span></li>'); $result = $this->query($querystr); if( !$result ) { $this->setError(''.$name_escape.' could not be inserted',$this->error()); return; } $querystr = "SELECT * FROM `".ROSTER_MEMBERSTABLE."` WHERE `guild_id` = '$guildId' AND `name` = '$name_escape' AND `class` = '".$char['Class']."';"; $result = $this->query($querystr); if( !$result ) { $this->setError('Member could not be selected for MemberLog',$this->error()); } else { $row = $this->fetch_array($result); $this->setMemberLog($row,1); } } } Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 4, 2007 Share Posted April 4, 2007 How about posting the part that inserts into the database? Were not freaking mind readers! also, put this in your code: echo "<pre>"; print_r($guildRanks); echo "</pre>\n"; and post what it spits outs. another thing to consider, what are the types of data stored in these columns in your database? Quote Link to comment Share on other sites More sharing options...
blacknight Posted April 4, 2007 Author Share Posted April 4, 2007 Array ( [1] => Vice President [2] => General [3] => Class Colonel [4] => Raid Colonel [5] => Class Captain [6] => Leiutenant [7] => First Sergeant [8] => Sergeant [9] => Private [0] => President ) is the array data and thay are stored in varchar 255 so i dono y its not worken man oh and $char['Rank'] is there rank in number from 0-9 Quote Link to comment Share on other sites More sharing options...
btherl Posted April 4, 2007 Share Posted April 4, 2007 With that array structure, you should only use one level to access it: print "Element 0 is " . $guildRanks[0] . "\n"; If you use two levels, then you will not get what you want print "This is nonsense: " . $guildRanks[0][0] . "\n"; Probably you just need to replace $guildRanks[$char['Rank']]['Title'] with $guildRanks[$char['Rank']] Quote Link to comment Share on other sites More sharing options...
blacknight Posted April 4, 2007 Author Share Posted April 4, 2007 if (isset($guildRanks[$char['Rank']]['Title'])){ $rnk = $guildRanks[$char['Rank']]['Title']; }else{ $rnk = $guildRanks[$char['Rank']]; is designed to compare aganst 2 arrays one witch contains a "["Title"]" veriable and one that dosent and uses the correct veriable it all works fine as far as the array and the structure just when i go from echoing for example "$guildRanks[$char['Rank']]" and $char['Rank'] = 0 i get President on the echo but then when its inserted in to the database i just get the letter p insted of the Full name and i dono y this is my problem Quote Link to comment Share on other sites More sharing options...
trq Posted April 4, 2007 Share Posted April 4, 2007 Not sure how else to put it. Consider this example.... #!/usr/bin/php <?php $a = array(); $a[0] = "abc"; echo $a[0][1]; ?> You can access each char in a string via $string[char], this appears to be your problem. Quote Link to comment Share on other sites More sharing options...
blacknight Posted April 4, 2007 Author Share Posted April 4, 2007 well i got it solved lol changed my code a lil if (array_key_exists ('Title',$guildRanks)){ $rnk = $guildRanks[$char['Rank']]['Title']; }else{ $rnk = $guildRanks[$char['Rank']]; } since one array dosent use the Title key this figures witch way to update the rank name lol 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.