Aaron Posted May 2, 2012 Report Share Posted May 2, 2012 I added a new field (not custom, added in table) that has VATSIM ID. I got it working so it gets put in the table upon registration, but I need to fix it so it can be eddited in the edit profile page. The problem is if I echo $vatsimid it prints "Array". Help is appreciated. This is what I have so far: Profile.php public function editprofile() { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.tpl'); return; } $pilotid = Auth::$userinfo->pilotid; $this->set('userinfo', Auth::$userinfo); $this->set('customfields', PilotData::GetFieldData(Auth::$pilotid, true)); $this->set('vatsimid', PilotData::GetVatsimId($pilotid)); $this->set('ivaoid', PilotData::GetIvaoId(Auth::$pilotid)); $this->set('bgimages', PilotData::GetBackgroundImages()); $this->set('countries', Countries::getAllCountries()); $this->set('pilotcode', PilotData::GetPilotCode(Auth::$userinfo->code, Auth::$userinfo->pilotid)); $this->render('profile_edit.tpl'); } PilotData public function GetVatsimId($pilotid) { $vatsimid = "SELECT vatsimid FROM phpvms_pilots WHERE pilotid='$pilotid'"; return DB::get_results($vatsimid); } public function GetIvaoId($pilotid) { $ivaoid = "SELECT ivaoid FROM phpvms_pilots WHERE pilotid='$pilotid'"; return DB::get_results($ivaoid); echo DB::$error; } profile_edit.tpl (so far) <?php if ($vatsimid==0) { $vnchecked="checked"; $vychecked=""; } else { $vychecked="checked"; $vnchecked=""; } echo $vatsimid; ?> <tr><td>Are you a VATSIM Member: *</td> <td><input type="radio" name="vatsim" id="VY" value="Y" onclick="VATSIMID()" <?php echo $vychecked ?>>Yes <input type="radio" name="vatsim" id="VN" value="N" onclick="VATSIMID()" <?php echo $vnchecked ?>>No</td> </tr> Quote Link to comment Share on other sites More sharing options...
Talisman57 Posted May 2, 2012 Report Share Posted May 2, 2012 Try doing the entire call in the Profile.tpl Do a MySQL query and then echo the row you want, all in the view file and see what happens Quote Link to comment Share on other sites More sharing options...
Tom Posted May 2, 2012 Report Share Posted May 2, 2012 PilotData public function GetVatsimId($pilotid) { $vatsimid = "SELECT vatsimid FROM phpvms_pilots WHERE pilotid='$pilotid'"; return DB::get_results($vatsimid); } public function GetIvaoId($pilotid) { $ivaoid = "SELECT ivaoid FROM phpvms_pilots WHERE pilotid='$pilotid'"; return DB::get_results($ivaoid); echo DB::$error; } ^ Get rid of all that you don't need it, use PilotData::getFieldValue() as follows profile_edit.tpl (so far) <?php $checked = false; if (PilotData::getFieldValue($pilotid, 'vatsimid')) { $checked = true; } ?> <tr><td>Are you a VATSIM Member: *</td> <td><input type="radio" name="vatsim" id="VY" value="Y" onclick="VATSIMID()" <?php if($checked){ echo 'checked'; ?>>Yes <input type="radio" name="vatsim" id="VN" value="N" onclick="VATSIMID()" <?php if(!$checked){ echo 'checked'; ?>>No</td> </tr> Quote Link to comment Share on other sites More sharing options...
Administrators simpilot Posted May 2, 2012 Administrators Report Share Posted May 2, 2012 The command DB::get_results($query); returns an array from the database, even it is only one line that it is returning. If you only want one line returned and have it in object form then use DB::get_row($query); Then you will have access to it as $variable->vatsimid Quote Link to comment Share on other sites More sharing options...
Aaron Posted May 2, 2012 Author Report Share Posted May 2, 2012 I can't use the getFieldValue() function because it isn't a custom field. I added a whole new column for it. This is what I did so far, but if I echo $vatsimid right before the ?> it gives me an error  Profile.php -> editprofile() $this->set('vatsimid', PilotData::GetVatsimId(Auth::$pilotid)); $this->set('ivaoid', PilotData::GetIvaoId(Auth::$pilotid)); PilotData public function GetVatsimId($pilotid) { $query = "SELECT vatsimid FROM phpvms_pilots WHERE pilotid='$pilotid'"; return DB::get_row($query); echo DB::$error; } public function GetIvaoId($pilotid) { $query = "SELECT ivaoid FROM phpvms_pilots WHERE pilotid='$pilotid'"; return DB::get_row($query); echo DB::$error; } profile_edit.tpl <?php if ($vatsimid==0) { $vnchecked = "checked"; $vychecked = ""; } else { $vychecked = "checked"; $vnchecked = ""; } echo $vatsimid; ?> <tr><td>Are you a VATSIM Member: *</td><td><input type="radio" name="vatsim" id="VY" value="Y" onclick="VATSIMID()" <?php echo $vychecked ?>>Yes <input type="radio" name="vatsim" id="VN" value="N" onclick="VATSIMID()" <?php echo $vnchecked ?>>No</td></tr> <tr><td>VATSIM ID:</td> <td><div id="VATSIMfield"><script type="text/javascript"> VATSIMID(); </script> </div> Quote Link to comment Share on other sites More sharing options...
Aaron Posted May 2, 2012 Author Report Share Posted May 2, 2012 Catchable fatal error: Object of class stdClass could not be converted to string in /home2/canforce..... Quote Link to comment Share on other sites More sharing options...
Guest lorathon Posted May 2, 2012 Report Share Posted May 2, 2012 Try This. public function GetVatsimId($pilotid) { $query = "SELECT vatsimid FROM phpvms_pilots WHERE pilotid='$pilotid'"; $res = DB::get_row($query); echo DB::$error; if($res) return $res->vatsimid; else return 0; } public function GetIvaoId($pilotid) { $query = "SELECT ivaoid FROM phpvms_pilots WHERE pilotid='$pilotid'"; $res = DB::get_row($query); echo DB::$error; if($res) return $res->ivaoid; else return 0; } Quote Link to comment Share on other sites More sharing options...
Guest lorathon Posted May 2, 2012 Report Share Posted May 2, 2012 Tom is correct though. You should be able to use the getFieldValue Quote Link to comment Share on other sites More sharing options...
Aaron Posted May 2, 2012 Author Report Share Posted May 2, 2012 holly crap it works thank you so much Quote Link to comment Share on other sites More sharing options...
Aaron Posted May 2, 2012 Author Report Share Posted May 2, 2012 Any ideas how to set the value in javascript? I want the current value of the vatsimid to show up there by default. Here's what I've tried: function VATSIMID(){ if(document.getElementById('VY').checked) { VATSIMfield.innerHTML="<input type='text' name='vatsimid' value='<?php echo $vatsimid ?>' maxlength='7' onKeyPress='return numbersonly(this, event)'/>" }else if(document.getElementById('VN').checked) { VATSIMfield.innerHTML="<input type='text' name='vatsimid' value='' disabled='disabled' style='background-color: #E6E6E6;'/>" } } 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.