loxfear Posted May 18, 2014 Share Posted May 18, 2014 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php //MySQL Database Connect include 'sqlconnect.php'; ?> <select name="aktivitet" id="aktivitet"> <?php //MySQL Database Connect include 'sqlconnect.php'; $sql = mysql_query("SELECT title FROM aktiviteter"); while ($row = mysql_fetch_array($sql)){ echo "<option value=\"owner1\">" . $row['title'] . "</option>"; } ?> </select> </body> </html> why dosnt this work?, if you cant see what i want to happen, ill post an explaination Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/ Share on other sites More sharing options...
Ch0cu3r Posted May 18, 2014 Share Posted May 18, 2014 Looking at the code it should be populating the menu with the results of the query. For why it is not working there could be an error with your query, which you have not checked for. $sql = mysql_query("SELECT title FROM aktiviteter"); // check query did not return an error if(!$sql) trigger_error('DB Error: ' . mysql_error(), E_USER_ERROR); Also you only need to include sqlconnect.php once, there is no need to include it each time you perform a query. Having said that though you should really change your code over to PDO or MySQLi. The mysql_* functions are deprecated and no longer supported, which means they could be removed from future versions of PHP. So this would be good time change. Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479919 Share on other sites More sharing options...
loxfear Posted May 18, 2014 Author Share Posted May 18, 2014 thx man, but i have to say, im quite a newbie so im not sure if your push will help me, ill try some stuff and be back Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479921 Share on other sites More sharing options...
loxfear Posted May 18, 2014 Author Share Posted May 18, 2014 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php //MySQL Database Connect include 'sqlconnect.php'; ?> <select name="aktivitet" id="aktivitet"> <?php $sql = mysqli_query($con,"SELECT title FROM aktiviteter"); // check query did not return an error if(!$sql) trigger_error('DB Error: ' . mysql_error(), E_USER_ERROR); while ($row = mysqli_fetch_array($sql)){ echo "<option value=\"owner1\">" . $row['title'] . "</option>"; } ?> </select> </body> </html> this is how it looks, i cant detect any difference still doesnt work http://polterplanner.dk/bestillere.html thats where it is . dont know if that would help? Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479922 Share on other sites More sharing options...
ginerjm Posted May 18, 2014 Share Posted May 18, 2014 What doesn't work? Besides the select tag? Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479928 Share on other sites More sharing options...
Solution ginerjm Posted May 18, 2014 Solution Share Posted May 18, 2014 OK - try this. It's your code with some error checking and some re-arrangement to make it more readable. <?php error_reporting(E_ALL | E_STRICT | E_NOTICE); ini_set('display_errors', '1'); //MySQL Database Connect include 'sqlconnect.php'; $sql = mysqli_query($con,"SELECT title FROM aktiviteter"); // check query did not return an error if(!$sql) { trigger_error('DB Error: ' . mysql_error(), E_USER_ERROR); exit(); } $options = "<select name='aktivitet' id='aktivitet'>"; while ($row = mysqli_fetch_array($sql)) { // NOTE - ALL OF YOUR OPTIONS WILL HAVE THE EXACT SAME VALUE CLAUSE - N.G.!! $options .= "<option value='owner1'>" . $row['title'] . "</option>"; } $options .= "</select>"; // NOW begin sending html!!! ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> $options </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479929 Share on other sites More sharing options...
mac_gyver Posted May 18, 2014 Share Posted May 18, 2014 your page/file has a .html extension. php code is NOT parsed in a .html file. change your page to a .php extension. Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479930 Share on other sites More sharing options...
Ch0cu3r Posted May 18, 2014 Share Posted May 18, 2014 PHP code does work in .html files (unless the server is confgured to do so). I suggest to rename your file so it ends in .php but i have to say, im quite a newbie so im not sure if your push will help me If you are new to PHP I highly recommend you to learn PDO or MySQLi. Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479931 Share on other sites More sharing options...
loxfear Posted May 18, 2014 Author Share Posted May 18, 2014 "; while ($row = mysqli_fetch_array($sql)) { // NOTE - ALL OF YOUR OPTIONS WILL HAVE THE EXACT SAME VALUE CLAUSE - N.G.!! $options .= ""; } $options .= ""; // NOW begin sending html!!! ?> $options what it gave me Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479932 Share on other sites More sharing options...
loxfear Posted May 18, 2014 Author Share Posted May 18, 2014 thx Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479933 Share on other sites More sharing options...
ginerjm Posted May 18, 2014 Share Posted May 18, 2014 I'm confused. Is my code working now ? (with the change as suggested to a .php filename) Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479935 Share on other sites More sharing options...
loxfear Posted May 18, 2014 Author Share Posted May 18, 2014 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> <?php //MySQL Database Connect include "sqlconnect.php"; echo "<select name='aktivitet' id='aktivitet'>" $sql = mysqli_query($con,"SELECT title FROM aktiviteter"); // check query did not return an error if(!$con) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } while ($row = mysqli_fetch_array($sql)){ echo "<option value=\"owner1\">" . $row['title'] . "</option>"; } echo "</select>" ?> now thats how it looks and php extendtion Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479937 Share on other sites More sharing options...
loxfear Posted May 18, 2014 Author Share Posted May 18, 2014 Ginerjm ur code just sais $options Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479938 Share on other sites More sharing options...
ginerjm Posted May 18, 2014 Share Posted May 18, 2014 (edited) oops. Change the line $options to: <? echo $options; ?> NOTE: just added a semi to the line above! Edited May 18, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479939 Share on other sites More sharing options...
loxfear Posted May 18, 2014 Author Share Posted May 18, 2014 Thanks man! it worked! and i understood why, whitch is even better than just working! Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479941 Share on other sites More sharing options...
loxfear Posted May 18, 2014 Author Share Posted May 18, 2014 edit the code up there to the one that works, so people who end in the same problem are able to make it work Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479942 Share on other sites More sharing options...
ginerjm Posted May 18, 2014 Share Posted May 18, 2014 HTH! Glad you understand what I did - it is good to keep the logic away from the presentation as much as possible. PS - I hope you are doing an error check on the connection in that included code and not doing it as you did in your last posted sample. Check that the connection worked when you do the connect, and check that the query works when you do the query. Quote Link to comment https://forums.phpfreaks.com/topic/288577-easy-problem-i-think-selection-menu-not-showing-rows/#findComment-1479943 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.