angeloghiotto Posted March 24, 2010 Share Posted March 24, 2010 Hi, first i need to expose to you. i dont speak english well... so.. hehhe well .. i need to put one form.. where appears the informations of mysql DB to be selected. anyone there can help me? thx Link to comment https://forums.phpfreaks.com/topic/196358-forms-by-mysql/ Share on other sites More sharing options...
Catfish Posted March 24, 2010 Share Posted March 24, 2010 try something like this $data = mysql_query('query'); // send query to database asking for data while ($row = mysql_fetch_assoc($data)) // loop through results { $dataArray[] = $row['fieldName']; // put value of field name you want to put in the form item into an array if there are multiple values } print('<form><select name="fieldName">'); foreach($dataArray as $value) // loop through data to be put into select dropdown print('<option value="'.$value.'"/>'); output values into dropdown options. print('</select></form>'); Link to comment https://forums.phpfreaks.com/topic/196358-forms-by-mysql/#findComment-1031208 Share on other sites More sharing options...
angeloghiotto Posted March 24, 2010 Author Share Posted March 24, 2010 thx a lot.. bur. i try to do this ... <?php include_once 'config.php'; mysql_connect($host,$user,$pass); mysql_select_db($db); $sql = "SELECT * FROM `cadastro` LIMIT 0, 30 "; $data = mysql_query($sql); // send query to database asking for data echo $data; while ($row = mysql_fetch_assoc($data)) // loop through results { $dataArray[] = $row['UTE']; // put value of field name you want to put in the form item into an array if there are multiple values } print('<form><select name="UTE">'); foreach($dataArray as $value) // loop through data to be put into select dropdown print('<option value="'.$value.'"/>'); //output values into dropdown options. print('</select></form>'); ?> and .. when i run... appears this result... whats happen? Link to comment https://forums.phpfreaks.com/topic/196358-forms-by-mysql/#findComment-1031224 Share on other sites More sharing options...
Catfish Posted March 25, 2010 Share Posted March 25, 2010 $dataArray is empty. i think. try print_r($dataArray); to see if there is data in $dataArray. you need to verify your data is being taken from the database, and being passed into the array as expected. you could try using mysql_num_rows($data) to check if the select statement is getting dat from your table. http://au.php.net/manual/en/function.mysql-num-rows.php is the field name in this line: $dataArray[] = $row['UTE']; correct? letter case is important. Link to comment https://forums.phpfreaks.com/topic/196358-forms-by-mysql/#findComment-1031547 Share on other sites More sharing options...
angeloghiotto Posted March 25, 2010 Author Share Posted March 25, 2010 i try to print_r($data) but, the result is the same... after .. i put the mysql_num_rows($data)... and show "2".. look.. if the help.. the pics of my DB above... thanks very much for the patience and help Link to comment https://forums.phpfreaks.com/topic/196358-forms-by-mysql/#findComment-1031644 Share on other sites More sharing options...
Catfish Posted March 25, 2010 Share Posted March 25, 2010 print_r($dataArray), not $data Link to comment https://forums.phpfreaks.com/topic/196358-forms-by-mysql/#findComment-1031742 Share on other sites More sharing options...
angeloghiotto Posted March 26, 2010 Author Share Posted March 26, 2010 sorry.. now.. the correct way shows this... Link to comment https://forums.phpfreaks.com/topic/196358-forms-by-mysql/#findComment-1032173 Share on other sites More sharing options...
Catfish Posted March 27, 2010 Share Posted March 27, 2010 mysql_num_rows() i guess is returning the '2' in the output, which means the query is working, the result data contains two rows from the database. If you used print_r($dataArray) and it is only showing 'Array' in the output, then $dataArray is not filling up correctly. But looking at what you've posted it should be. Did you use print_r($dataArray) or print($dataArray) ? If you used print($dataArray) it may be the foreach loop that is not working. You may need to add braces for the foreach block like: foreach($dataArray as $value) { print('<option value="'.$value.'"/>'); //output values into dropdown options. } Link to comment https://forums.phpfreaks.com/topic/196358-forms-by-mysql/#findComment-1032632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.