medaswho Posted February 13, 2009 Share Posted February 13, 2009 am trying to find out why my code prints and extra check box when it shouldn't this is the code: if(!$result == "") { echo "<h2>some heading.</h2><form>"; while($title = mysql_fetch_array($result, MYSQL_ASSOC)) { $down=$title['title']; echo "<input type='checkbox' name='C1' value='ON'>".$down." "; } //end while } // end while any advice would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2009 Share Posted February 13, 2009 You either have a row in your table with an empty or null $title['title'] or something in your code prior to that point is outputting a check box. Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761236 Share on other sites More sharing options...
printf Posted February 13, 2009 Share Posted February 13, 2009 can we see what comes before that, but just a guess, $result is a resource identifier so you can't compare it to "" if ( mysql_num_rows ( $result ) > 0 ) { Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761237 Share on other sites More sharing options...
medaswho Posted February 13, 2009 Author Share Posted February 13, 2009 thank you 'printf', but the only thing preceding this section of code is an include getting db name variables and then the code to actually connect to the db. include 'variables.dat'; $quer = "SELECT * FROM thisdb"; mysql_connect($host,$user,$password); mysql_select_db($dbname); $result = mysql_query($quer); and then of course the other stuff...i am baffled? Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761243 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2009 Share Posted February 13, 2009 You either have a row in your table with an empty or null $title['title'] Have you bothered to look at the data in your table Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761246 Share on other sites More sharing options...
medaswho Posted February 13, 2009 Author Share Posted February 13, 2009 PFMaBiSmAd, thanks for you input, but the db is brand new...it's a tester since i am just get started and it has three rows in it, and no extraneous data. Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761256 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2009 Share Posted February 13, 2009 Post the "view source" from your browser. Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761265 Share on other sites More sharing options...
medaswho Posted February 13, 2009 Author Share Posted February 13, 2009 here is the "view source" printf: <html> <head> <title>Welcome</title> </head> <link rel='stylesheet' type='text/css' href='index.css' /> <body><div id='banner'> <id='banner' table border='0' width='100%' bgcolor='#FFFFFF'> <tr> <td width='100%'><p align='center'><img src='images/banner.jpg'></p></td> </tr> </table></div> <p align='center'> <div id='linkbar'><p align='center'> <a href='index.php'>Home</a> <a href='gigs.php'>Gigs</a> <a href='downloads.php'>Downloads</a> <a href='forum.php'>Forum</a> <a href='contact.php'>Contact</a> <a href='about.htm'>About us</a> </p><h2>some header</h2><form><input type='checkbox' name='' value='ON'> <input type='checkbox' name='file.mp3' value='ON'>file.mp3 <input type='checkbox' name='file2.mp3' value='ON'>file2.mp3 <br><input type='submit' value='Check out'> <input type='reset'></form><br> <p><img src='images/cards_flat_smaller.jpg'></p> <p> </p> </div> </p> <table id='footer' bgcolor=#ffffff><tr><td> Copyright info </td></tr></table> </body></html> Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761280 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2009 Share Posted February 13, 2009 You have three rows in your table and that code has three check boxes. What is the problem? Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761293 Share on other sites More sharing options...
medaswho Posted February 13, 2009 Author Share Posted February 13, 2009 the previous post was erroneous. there are only two entries in the database Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761302 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2009 Share Posted February 13, 2009 Have you checked, because the information you have posted in this thread indicates there is a row with at least an empty title in it. Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761308 Share on other sites More sharing options...
medaswho Posted February 13, 2009 Author Share Posted February 13, 2009 got it. Thanks a million. it's a little embarrassing to make such a careless mistake, but it's good to know that at least my php code was correct. Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761326 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2009 Share Posted February 13, 2009 Computers only do what their code tells them to do. You cannot assume that there is x amount of data because you think it is so, you must always check so that you know it is so. Link to comment https://forums.phpfreaks.com/topic/145071-solved-i-take-it-no-one-knows-this-problem/#findComment-761332 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.