clauddiu Posted April 2, 2008 Share Posted April 2, 2008 I have to generete fields dinamically from database thay are all text fields, this part of the codefor a moving company I do it for free but I get stuck so this will be the edit part of the quote, the fields are genetared automatocalluy from the database, but Now I have to fil the values in each field was submited before. this is the code, and it's show me only the first match insted of 5 //the data from inventory field looks like: /* Arm Chair=1| Bed – double/queen=2| Desk (Student)=2| Freezer=3| Pictures=3 */ // here is what I made\ // get the data from database function GetFormValue($table, $field, $where){ global $host, $user, $pass, $database; // Connecting, selecting database $link = mysql_connect($host,$user, $pass) or die('Could not connect: ' . mysql_error()); //echo 'Connected successfully'; mysql_select_db($database) or die('Could not select $database'); // Performing SQL query $query = "SELECT * FROM `$table` $where"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML while ($row = mysql_fetch_assoc($result)) { $cat = $row[$field]; return $cat; } // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); } // this is the parth where I generate the firlds again and I try to fill them with value from actual quote // $mumu = array(); $mumu = GetFormValue("quotes","inventory","where id='$QuoteID'"); $dudu = explode("|",$mumu); $cac = count($dudu); $fd = array(); $sanda =array(); $panda =array(); foreach ($dudu as $sd) { $fd = explode("=",$sd); //echo $fd[0], " | ", $fd[1],"<br>" ; $sanda[] = $fd[0]; $panda[] = $fd[1]; } $cc = count($sanda); $asas = 0; // get each row while($myrow = mysql_fetch_row($mysql_result)){ //get data - eg, reading fields 0 and 1 $tn = $myrow[0]; $in= $myrow[1]; $ln= $myrow[2]; if ($numcolsprinted == $numcols) { print "</tr>\n<tr>\n"; $numcolsprinted = 0; } if ($in == $sanda[$asas]){ $out = "$in: <input type=\"text\" value=\"{$panda[$asas]}\" name=\"item|$in|$ln\" size=\"2\">\n"; }else{ $out = "$in: <input type=\"text\" value=\"0\" name=\"item|$in|$ln\" size=\"2\">\n"; } //$out = "$in: <input type=\"text\" value=\"0\" name=\"item|$in|$ln\" size=\"2\">\n"; // output row from database echo "<td align=\"right\" bgcolor=\"#e2e0e8\"> $out </td>\n"; // bump up row counter $numcolsprinted++; $asas++; } // end while loop Thank you guys for all your help! Claudiu Link to comment https://forums.phpfreaks.com/topic/99116-problem-to-check-some-values/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.