larsbrimmer Posted February 1, 2009 Share Posted February 1, 2009 When i run the code i get: Database is down and Warning: mysql_fetch_assoc(): on line 34 My tabel: `RayMusicCategories` (`ID`, `Parent`, `Title`) VALUES (1, 0, 'House'), (2, 1, 'Progressive House'), (3, 1, 'Acid house'), (4, 1, 'Deep house'), (5, 1, 'Electro house'), (6, 1, 'Tech house'), (7, 1, 'Tribal house'), (8, 0, 'Trance'), (9, 2, 'Acid trance'), (10, 2, 'Hard trance'), (11, 2, 'Progressive trance'), (12, 2, 'Vocal trance'); Here is the code: <?php $hostname = "localhost"; $username = ""; $password = ""; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("RayMusicCategories",$dbh); if( isset($_POST['Submit']) ) { echo "<pre>"; print_r($_POST); } if( isset($_GET['ajax']) ) { //In this if statement $query = sprintf("SELECT * FROM RayMusicCategories WHERE PARENT=%d",$_GET['ajax']); $result = mysql_query($query); echo "<option value=''></option>"; while ($row = mysql_fetch_assoc($result)) { echo "<option value='{$row['ID']}'>{$row['TITLE']}</option>\n"; } mysql_close($dbh); exit; //we're finished so exit.. } if (!$result = mysql_query("SELECT * FROM RayMusicCategories WHERE PARENT=0")) { echo "Database is down"; } //for use with my FIRST list box $List1 = ""; while ($row = mysql_fetch_assoc($result)) { $List1 .= "<option value='{$row['ID']}'>{$row['TITLE']}</option>\n"; } ?> For some reason this looks wrong to me. <?php if (!$result = mysql_query("SELECT * FROM RayMusicCategories WHERE PARENT=0")) { echo "Database is down"; } ?> -Lars Quote Link to comment https://forums.phpfreaks.com/topic/143339-solved-help-with-madtechies-dynamic-dropdown-phpajax-code/ Share on other sites More sharing options...
Philip Posted February 1, 2009 Share Posted February 1, 2009 Change: if (!$result = mysql_query("SELECT * FROM RayMusicCategories WHERE PARENT=0")) { echo "Database is down"; } to: $result = mysql_query("SELECT * FROM RayMusicCategories WHERE PARENT=0") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/143339-solved-help-with-madtechies-dynamic-dropdown-phpajax-code/#findComment-751777 Share on other sites More sharing options...
trq Posted February 1, 2009 Share Posted February 1, 2009 Your field is called Parent, not PARENT, there is a difference. Quote Link to comment https://forums.phpfreaks.com/topic/143339-solved-help-with-madtechies-dynamic-dropdown-phpajax-code/#findComment-751778 Share on other sites More sharing options...
larsbrimmer Posted February 1, 2009 Author Share Posted February 1, 2009 I replaced code with both suggestions and get No database selected error <?php $hostname = "localhost"; $username = ""; $password = ""; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("RayMusicCategories",$dbh); if( isset($_POST['Submit']) ) { echo "<pre>"; print_r($_POST); } if( isset($_GET['ajax']) ) { //In this if statement $query = sprintf("SELECT * FROM RayMusicCategories WHERE Parent=%d",$_GET['ajax']); $result = mysql_query($query); echo "<option value=''></option>"; while ($row = mysql_fetch_assoc($result)) { echo "<option value='{$row['ID']}'>{$row['TITLE']}</option>\n"; } mysql_close($dbh); exit; //we're finished so exit.. } $result = mysql_query("SELECT * FROM RayMusicCategories WHERE Parent=0") or die(mysql_error()); //for use with my FIRST list box $List1 = ""; while ($row = mysql_fetch_assoc($result)) { $List1 .= "<option value='{$row['ID']}'>{$row['TITLE']}</option>\n"; } ?> My connection properties are correct and server is up. Quote Link to comment https://forums.phpfreaks.com/topic/143339-solved-help-with-madtechies-dynamic-dropdown-phpajax-code/#findComment-751784 Share on other sites More sharing options...
larsbrimmer Posted February 1, 2009 Author Share Posted February 1, 2009 Sorry, I got it now. I was using the table name as the db name. -lars Quote Link to comment https://forums.phpfreaks.com/topic/143339-solved-help-with-madtechies-dynamic-dropdown-phpajax-code/#findComment-751810 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.