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 Quote Link to comment 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. Quote Link to comment 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 ) { Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2009 Share Posted February 13, 2009 Post the "view source" from your browser. Quote Link to comment 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> Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.