Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP/mySQL dynamic form help

Options
  • 13-12-2004 7:52pm
    #1
    Moderators, Education Moderators Posts: 2,432 Mod ✭✭✭✭


    Hey,

    Am having a bit of trouble generating a dynamic form in php, getting info from a mySQL database

    The form isnt displaying anything (i.e. its blank) although it does 'go down' the correct number of spaces. Hope you know what i'm on about here!
    // Select fields in the bugid table to be displayed
    		$bugidQuery = "SELECT BugID FROM BugFind";
    		$bugidResult = mysql_query($bugidQuery);
    		
    	
    		// Determine the number of Bugs
    		$bugidNumber = mysql_numrows($bugidResult);
    
    		// Print the Bug names as a drop-down menu
    
    		print "Pick the bug that you wish to modify : ";
    
    		print "<select name=\"bug\">
        	<option value=\"\">Select an Bug</option>";
    
    		for ($i=0; $i<$bugidNumber; $i++) {
            	$bugidName = mysql_result($bugidResult,$i,"bug");
           	 
            print "<option>$bugidName</option>";
    }
    		print "</select><p>";
    		
    

    The strange thing is i have nearly identical code below, and it works fine!!!

    i.e. instead of blanks, it displays stuff
    
    //get list of features leave it up to the user to pick correct ones
    	//only makes sense to pick active features when logging a bug
    
    	$featureQuery = "SELECT feature FROM Features where status='Active'";
    	$featureResult = mysql_query($featureQuery);
    
    	//get no. of features
    	$featureNumber = mysql_numrows($featureResult);
    
    	//make drop down menu
    	print "Select the Feature: ";
    
    	print "<select name=\"feature\">
        <option value=\"\">Select a Feature</option>";
    
    	for ($i=0; $i<$featureNumber; $i++) {
     	 $featureName = mysql_result($featureResult,$i,"feature");
      
      print "<option>$featureName</option>";
    }
    print "</select><p>";
    		
    
    

    To me they look identical, but then it is driving me crazy so.....

    It could also be a probelm with the database???

    Thanks for any help in advance, any more info needed and i'll gladly show you


Comments

  • Registered Users Posts: 7,276 ✭✭✭kenmc


    you're pulling X elements from the database correectly, but you're not accessing them correctly in the results..
    check this....
    $bugidQuery = "SELECT BugID FROM BugFind";
    this will result in a small table looking like this:
    BugID
    123
    1231
    3321
    213
    ...

    $bugidName = mysql_result($bugidResult,$i,"bug");
    but here you're looking for things called "bug" in the results, but there are none - need to change "bug" here to "BugID".
    K


  • Registered Users Posts: 6,508 ✭✭✭daymobrew


    While I don't know much SQL, I know some debugging techniques.

    Have you run the problem query from a console to ensure it returns data? (I'm guessing yes).
    Add return code checks to ensure mysql functions are not having problems.
    Maybe "print mysql_error()" every few lines.

    I was reading:
    http://www.php.net/manual/en/function.mysql-result.php

    [Aside: You should ensure $bugidResult is > 0 before printing 'select' tags]


  • Registered Users Posts: 7,276 ✭✭✭kenmc


    daymo,
    the fact that "it does 'go down' the correct number of spaces" indicates that s/he's getting data back, but is just not pulling it from the result array correctly (asking for apples when there are only oranges there....)


  • Moderators, Education Moderators Posts: 2,432 Mod ✭✭✭✭Peteee


    Thanks very much, i knew it would be something trivial like that!

    My eternal gratitude, hopefully will not make a stupid mistake like that again!


  • Closed Accounts Posts: 16,396 ✭✭✭✭kaimera


    ah pete, you should have asked me! I haven't had time to look at it properly yet ;)


  • Advertisement
  • Registered Users Posts: 7,276 ✭✭✭kenmc


    u're welcome. 2nd pair of eyes often spots it....


  • Moderators, Education Moderators Posts: 2,432 Mod ✭✭✭✭Peteee


    Yep, unfortunatly 3 pairs of eyes didnt spot it our house

    Ah well 2 heads are better then 3!


Advertisement