Haroskyline Posted May 27, 2009 Share Posted May 27, 2009 Heres my problem, on the update page, the code should be pulling the information from the database and implementing the data into the form, but the form, once the child and the specific service is selected, is remaining blank, and the selection box shows only the defaults. I'm not sure what went wrong here. <!-- {{{ PHP section to find selected records --> <?PHP if ((!isset($_POST['sssn'])) or (isset($_POST['newselect']))) { include "include/select_serv ice1.inc.php"; exit(); } $oldssn = $_POST['sssn']; $oldserv = substrpos($_POST['service'], 0, '\-'); $oldid = substr(substrpos($_POST['service'], '\-', 10),1); $result = $db->get_results("SELECT fname, mname, lname FROM childdemo WHERE ssn = $oldssn",OBJECT); foreach ($result as $child) { $name = $child->fname; $name .= ($child->mname == NULL) ? "" : " ".$child->mname.""; $name .= " ".$child->lname; } $cnt = $db->get_var("SELECT count(*) FROM services WHERE ssn = $oldssn"); if ($cnt ==0) include "include/no_rec_found.inc.php"; if (($cnt > 1) && (!isset($_POST['service']))) { ?> <br /><br /><br /> <div style="text-align: center; background-color: #FFFFFF; margin: 0px; padding: 0px; border: 2px solid #000180; border-spacing: 0px; border-collapse: collapse; width: 70%; margin-left: auto; margin-right: auto;"> <div style="background-color: #A4C8EE; border: solid 1px #000195; padding: 1px 1px 1px 1px; border-collapse: collapse;"> <h1 align="center">Update A Service For <br /><?PHP echo $name; ?></h1> </div> </div> <br /> <form name="services" method="post" action="index.php?serv=2"><center> <input type="hidden" name="sssn" value="<?PHP echo ($oldssn); ?>"> <table border="1" style="margin: 1em 1em 1em 1em;"> <tr style="background-color: #A4C8EE;"> <th>Select</th> <th width="40%">Service</th> <th width="40%">Vendor</th> </tr> <?PHP $cnt = $db->get_results("SELECT id,service,vendor,ssn,sessions FROM services WHERE ssn = $oldssn"); $x = 1; foreach($cnt as $key) { $ser = $db->get_var("SELECT service FROM serviceslookup WHERE code=".$key->service); $ven = $db->get_var("SELECT vendor_name FROM vendor WHERE vendor = ".$key->vendor); print "\t\t\t<tr>\n\t\t\t\t<td align=\"center\"><input type=\"radio\" name=\"service\" value=\"".$key->service.'-'.$key->id."\"></td>\n"; print "\t\t\t\t<td style=\"padding: 3px 3px 3px 3px;\">$ser</td>\n"; print "\t\t\t\t<td style=\"padding: 3px 3px 3px 3px;\">$ven</td>\n\t\t\t</tr>\n"; $x++; } print "\t\t</table></center>\n"; print "\t\t<br /><center>\n"; print "\t\t\t<input type=\"submit\" name=\"save\" value=\"Update\">\n"; print "\t\t\t<input type=\"reset\" name=\"reset\" value=\"Reset\">\n"; print "\t\t</center>\n"; print "\t\t</form>\n</body>\n</html>\n"; exit(); } else { if (isset($_POST['service'])) { $results = $db->get_results("SELECT * FROM services WHERE ((ssn = $oldssn) and (service = ".$_POST['service'].") and (id = $oldid))",OBJECT); } else { $results = $db->get_results("SELECT * FROM services WHERE ssn = $oldssn",OBJECT); } } foreach ($child as $info) { ?><!--}}}--> <!--{{{ Header section --> <br /><br /> <div style="text-align: center; background-color: #FFFFFF; margin: 0px; padding: 0px; border: 2px solid #000180; border-spacing: 0px; border-collapse: collapse; width: 70%; margin-left: auto; margin-right: auto;"> <div style="background-color: #A4C8EE; border: solid 1px #000195; padding: 1px 1px 1px 1px; border-collapse: collapse;"> <h1 align="center">Update A Service For <br /><?PHP echo $name; ?></h1> </div> </div> <br /><!--}}}--> <!--{{{ Main input area --> <div style="width: 725px; margin-left: auto; margin-right: auto;"> <form id="form1" name="form1" method="post" action=""> <input type="hidden" name="ssn" value="<?PHP echo "$oldssn" ?>" /> <b style="margin-left: 5px;">Services</b> <b style="margin-left: 150px;">Begin Date (mmddyyyy)</b> <b style="margin-left: 20px;">End Date (mmddyyyy)</b> <b style="margin-left: 15px;">School Year</b><br /> <select name="services" size="1" style="margin-left: 5px;"> <?PHP $sresult = $db->get_results("SELECT * FROM serviceslookup ORDER BY code",OBJECT); foreach ($sresult as $key) { if ($key->code == $info->service) print "<option value=".$key->code." selected>".$key->service."</option>"; else print "<option value=".$key->code.">".$key->service."</option>"; } ?> </select> <?PHP $beg = substr($info->begin,5,2).substr($info->begin,8,2).substr($info->begin,0,4); $end = substr($info->end,5,2).substr($info->end,8,2).substr($info->end,0,4); ?> <input type="text" name="begin" size="11" maxlength="8" value="<?PHP echo "$beg" ?>" style="margin-left: 10px;" /> <input type="text" name="end" size="11" maxlength="8" value="<?PHP echo "$end" ?>" style="margin-left: 65px;" /> <select name="schoolyear" size="1" style="margin-left: 50px;"> <?PHP $query = "SELECT * FROM school_year WHERE ((year < ".$year2dig.") OR (year LIKE '".$year2dig."%')) ORDER BY code DESC"; $sresult = $db->get_results($query,OBJECT); foreach ($sresult as $key) { if ($key->code == $info->schoolyear) print "<option value=".$key->code." selected>".$key->year."</option>"; else print "<option value=".$key->code.">".$key->year."</option>"; } ?> </select> <br /><br /> <b style="margin-left: 5px;">Provider</b> <b style="margin-left: 257px;">Site</b> <b style="margin-left: 198px;">Full, Half, Related</b><br /> <select name="provider" size="1" style="margin-left: 5px;"> <?PHP $sresult = $db->get_results("SELECT * FROM vendor ORDER BY vendor_name",OBJECT); foreach ($sresult as $key) { if ($key->vendor == $info->vendor) print "<option value=".$key->vendor." selected>".$key->vendor_name."</option>"; else print "<option value=".$key->vendor.">".$key->vendor_name."</option>"; } ?> </select> <select name="site" size="1" style="margin-left: 5px;"> <?PHP $sresult = $db->get_results("SELECT * FROM sites ORDER BY site",OBJECT); foreach ($sresult as $key) { if ($key->code == $info->site) print "<option value=".$key->code." selected>".$key->site."</option>"; else print "<option value=".$key->code.">".$key->site."</option>"; } ?> </select> <select name="fhr" size="1" style="margin-left: 5px;"> <?PHP $sresult = $db->get_results("SELECT * FROM related ORDER BY related",OBJECT); foreach ($sresult as $key) { if ($key->code == $info->fhr) print "<option value=".$key->code." selected>".$key->related."</option>"; else print "<option value=".$key->code.">".$key->related."</option>"; } ?> </select> <br /><br /> <b style="margin-left: 5px;">Days</b> <b style="margin-left: 125px;">Sessions</b> <b style="margin-left: 101px;">Amount</b> <b style="margin-left: 82px;">100% Funded</b> <b style="margin-left: 30px;">STAC 3</b><br /> <input type="text" name="days" size="11" maxlength="8" value="<?PHP echo $info->days; ?>" style="margin-left: 5px;" /> <input type="text" name="sessions" size="11" maxlength="8" value="<?PHP echo $info->sessions; ?>" style="margin-left: 65px;" /> <input type="text" name="amount" size="11" maxlength="8" value="<?PHP echo $info->amt; ?>" style="margin-left: 65px;" /> <select name="funded" size="1" style="margin-left: 45px;"> <option value="Y" <?PHP ($info->funded =='Y') ? print "selected" : print ""; ?>>Yes</option> <option value="N" <?PHP ($info->funded =='N') ? print "selected" : print ""; ?>>No</option> </select> <input type="radio" name="stac" value="Y" style="margin-left: 55px;" <?PHP ($info->stac3 == 1) ? print "checked" : print ""; ?> /> Yes <input type="radio" name="stac" value="N" style="margin-left: 5px;" <?PHP ($info->stac3 == 0) ? print "checked" : print ""; ?> /> No<br /><br /> <center> <input type="submit" name="save" value="Save"> <input type="reset" name="reset" value="Reset"> <input type="submit" name="newselect" value="New Selection"> </center> </form> <script language="JavaScript"> document.forms[0].services.focus(); </script> </div> <?PHP } ?><!--}}}--> This is the whole code for updateserv.inc.php It starts off with the selection of the child, and then the selection of a specific service that is associated with that child, followed by a big spaced out form, it goes through one section of the form at a time. I tried putting <input type="text" name="begin" size="15" maxlength="15" value="<?PHP echo "$info->begin"; ?>" style="margin-left: 5px;"> in the code and it created the input box, but it's supposed to have the information to update in it when you load the page! Can someone explain why when I put that batch of code in, it doesn't display the information correctly? If you need anymore information, please let me know and I'll try to find out. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/159903-solved-problems-pulling-data-from-the-database/ Share on other sites More sharing options...
Alt_F4 Posted May 28, 2009 Share Posted May 28, 2009 Are you expecting more than 1 result when you run this query? $result = $db->get_results("SELECT fname, mname, lname FROM childdemo WHERE ssn = $oldssn",OBJECT); foreach ($result as $child) { $name = $child->fname; $name .= ($child->mname == NULL) ? "" : " ".$child->mname.""; $name .= " ".$child->lname; } 'cause if you are then if i'm not mistaken this code will only ever give you the details from the last record. Then when you run through this code foreach ($child as $info) { ?><!--}}}--> <!--{{{ Header section --> <br /><br /> <div style="text-align: center; background-color: #FFFFFF; margin: 0px; padding: 0px; border: 2px solid #000180; border-spacing: 0px; border-collapse: collapse; width: 70%; margin-left: auto; margin-right: auto;"> <div style="background-color: #A4C8EE; border: solid 1px #000195; padding: 1px 1px 1px 1px; border-collapse: collapse;"> <h1 align="center">Update A Service For <br /><?PHP echo $name; ?></h1> </div> </div> <br /><!--}}}--> <!--{{{ Main input area --> <div style="width: 725px; margin-left: auto; margin-right: auto;"> <form id="form1" name="form1" method="post" action=""> <input type="hidden" name="ssn" value="<?PHP echo "$oldssn" ?>" /> <b style="margin-left: 5px;">Services</b> <b style="margin-left: 150px;">Begin Date (mmddyyyy)</b> <b style="margin-left: 20px;">End Date (mmddyyyy)</b> <b style="margin-left: 15px;">School Year</b><br /> <select name="services" size="1" style="margin-left: 5px;"> <?PHP $sresult = $db->get_results("SELECT * FROM serviceslookup ORDER BY code",OBJECT); foreach ($sresult as $key) { if ($key->code == $info->service) print "<option value=".$key->code." selected>".$key->service."</option>"; else print "<option value=".$key->code.">".$key->service."</option>"; } ?> </select> <?PHP $beg = substr($info->begin,5,2).substr($info->begin,8,2).substr($info->begin,0,4); $end = substr($info->end,5,2).substr($info->end,8,2).substr($info->end,0,4); ?> <input type="text" name="begin" size="11" maxlength="8" value="<?PHP echo "$beg" ?>" style="margin-left: 10px;" /> <input type="text" name="end" size="11" maxlength="8" value="<?PHP echo "$end" ?>" style="margin-left: 65px;" /> <select name="schoolyear" size="1" style="margin-left: 50px;"> <?PHP $query = "SELECT * FROM school_year WHERE ((year < ".$year2dig.") OR (year LIKE '".$year2dig."%')) ORDER BY code DESC"; $sresult = $db->get_results($query,OBJECT); foreach ($sresult as $key) { if ($key->code == $info->schoolyear) print "<option value=".$key->code." selected>".$key->year."</option>"; else print "<option value=".$key->code.">".$key->year."</option>"; } ?> </select> <br /><br /> <b style="margin-left: 5px;">Provider</b> <b style="margin-left: 257px;">Site</b> <b style="margin-left: 198px;">Full, Half, Related</b><br /> <select name="provider" size="1" style="margin-left: 5px;"> <?PHP $sresult = $db->get_results("SELECT * FROM vendor ORDER BY vendor_name",OBJECT); foreach ($sresult as $key) { if ($key->vendor == $info->vendor) print "<option value=".$key->vendor." selected>".$key->vendor_name."</option>"; else print "<option value=".$key->vendor.">".$key->vendor_name."</option>"; } ?> </select> <select name="site" size="1" style="margin-left: 5px;"> <?PHP $sresult = $db->get_results("SELECT * FROM sites ORDER BY site",OBJECT); foreach ($sresult as $key) { if ($key->code == $info->site) print "<option value=".$key->code." selected>".$key->site."</option>"; else print "<option value=".$key->code.">".$key->site."</option>"; } ?> </select> <select name="fhr" size="1" style="margin-left: 5px;"> <?PHP $sresult = $db->get_results("SELECT * FROM related ORDER BY related",OBJECT); foreach ($sresult as $key) { if ($key->code == $info->fhr) print "<option value=".$key->code." selected>".$key->related."</option>"; else print "<option value=".$key->code.">".$key->related."</option>"; } ?> </select> <br /><br /> <b style="margin-left: 5px;">Days</b> <b style="margin-left: 125px;">Sessions</b> <b style="margin-left: 101px;">Amount</b> <b style="margin-left: 82px;">100% Funded</b> <b style="margin-left: 30px;">STAC 3</b><br /> <input type="text" name="days" size="11" maxlength="8" value="<?PHP echo $info->days; ?>" style="margin-left: 5px;" /> <input type="text" name="sessions" size="11" maxlength="8" value="<?PHP echo $info->sessions; ?>" style="margin-left: 65px;" /> <input type="text" name="amount" size="11" maxlength="8" value="<?PHP echo $info->amt; ?>" style="margin-left: 65px;" /> <select name="funded" size="1" style="margin-left: 45px;"> <option value="Y" <?PHP ($info->funded =='Y') ? print "selected" : print ""; ?>>Yes</option> <option value="N" <?PHP ($info->funded =='N') ? print "selected" : print ""; ?>>No</option> </select> <input type="radio" name="stac" value="Y" style="margin-left: 55px;" <?PHP ($info->stac3 == 1) ? print "checked" : print ""; ?> /> Yes <input type="radio" name="stac" value="N" style="margin-left: 5px;" <?PHP ($info->stac3 == 0) ? print "checked" : print ""; ?> /> No<br /><br /> <center> <input type="submit" name="save" value="Save"> <input type="reset" name="reset" value="Reset"> <input type="submit" name="newselect" value="New Selection"> </center> </form> <script language="JavaScript"> document.forms[0].services.focus(); </script> </div> <?PHP } ?><!--}}}--> you may not be seeing the results you expect? Link to comment https://forums.phpfreaks.com/topic/159903-solved-problems-pulling-data-from-the-database/#findComment-843873 Share on other sites More sharing options...
Haroskyline Posted May 28, 2009 Author Share Posted May 28, 2009 In that query it's just supposed to determine which child to bring up. So it's only supposed to bring up one result. The problem is, you choose which child to update, and it's supposed to pull the information of the child's services, and it isn't doing that. <?PHP echo "$info->begin"; ?> That php statement I have selected is what he used on a similar page to pull the data and display it in the input boxes, but it's not working for this page. Link to comment https://forums.phpfreaks.com/topic/159903-solved-problems-pulling-data-from-the-database/#findComment-844297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.