phpdog Posted May 13, 2011 Share Posted May 13, 2011 Hey guys, Having a slight problem with part of the code in my index.php file mysql_select_db('db_name', $con); $result = mysql_query("SELECT * FROM spy ORDER BY id desc limit 25"); $resulto = mysql_query("SELECT * FROM spy ORDER BY id desc"); $count = mysql_num_rows($resulto); while($row = mysql_fetch_array($result)) { ?> <div class="contentDiv">Someone is looking at <?=$row[title];?> Stats for "<a href="/<?=$row[type];?>/<?=$row[code];?>/<?=$row[city];?>"><?=$row[code];?> <?=$row[city];?></a>"</div> <?}?> </div> <div id="login"></div> <? include("footer.php"); ?> </div> </body> </html> I'm getting the following error when viewing the file Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ~path to file/index.php on line 70 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in ~path to file/index.php on line 71 where lines 70 and 71 are $count = mysql_num_rows($resulto); while($row = mysql_fetch_array($result)) Any ideas on how to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/236314-displaying-mysql-results-code-error/ Share on other sites More sharing options...
wigwambam Posted May 13, 2011 Share Posted May 13, 2011 Just after $resulto line add... echo mysql_error(); Could be a problem with structure of table? Quote Link to comment https://forums.phpfreaks.com/topic/236314-displaying-mysql-results-code-error/#findComment-1214962 Share on other sites More sharing options...
fugix Posted May 13, 2011 Share Posted May 13, 2011 change these two lines $result = mysql_query("SELECT * FROM spy ORDER BY id desc limit 25"); $resulto = mysql_query("SELECT * FROM spy ORDER BY id desc"); to $result = mysql_query("SELECT * FROM spy ORDER BY id desc limit 25") or die(mysql_error()); $resulto = mysql_query("SELECT * FROM spy ORDER BY id desc") or die(mysql_error()); and let use know what errors you receive if any Quote Link to comment https://forums.phpfreaks.com/topic/236314-displaying-mysql-results-code-error/#findComment-1215006 Share on other sites More sharing options...
phpdog Posted May 13, 2011 Author Share Posted May 13, 2011 Solved it guys.. One more problem in the same sheet (not really a problem actually) <form action="/search.php" method="get"> <div id="form"> <input id="query" name="query" type="text" onfocus="if(this.value=='enter city name...')this.value='';" onblur="if(this.value=='')this.value='enter city name...';"/> <input id="submit" value="find" type="submit" /> <input name="action" type="hidden" value="make" /> </div> </form> The user has to type in a city name and click "find'. Ive noticed you can click the button without actually typing anything in the box..is there any validation or something I could add so youre forced to type in that box (and if you click Find, it returns an error?) Quote Link to comment https://forums.phpfreaks.com/topic/236314-displaying-mysql-results-code-error/#findComment-1215028 Share on other sites More sharing options...
fugix Posted May 13, 2011 Share Posted May 13, 2011 first, you need to add a name to your submit button so you can check to see if it was pressed via $_POST[] Now to answer your question..what you'll want to do first is check if your submit button is pressed, then you'll want to make sure that the text field is filled out before processing your data. Try this if(isset($_POST['submit'])) { if(empty($_POST['query'])) { echo "please fill out the necessary filelds!"; } else { //process you data } } Quote Link to comment https://forums.phpfreaks.com/topic/236314-displaying-mysql-results-code-error/#findComment-1215041 Share on other sites More sharing options...
phpdog Posted May 13, 2011 Author Share Posted May 13, 2011 first, you need to add a name to your submit button so you can check to see if it was pressed via $_POST[] Now to answer your question..what you'll want to do first is check if your submit button is pressed, then you'll want to make sure that the text field is filled out before processing your data. Try this if(isset($_POST['submit'])) { if(empty($_POST['query'])) { echo "please fill out the necessary filelds!"; } else { //process you data } } Okay, where do I paste that though? Not too familiar with this :S Quote Link to comment https://forums.phpfreaks.com/topic/236314-displaying-mysql-results-code-error/#findComment-1215045 Share on other sites More sharing options...
fugix Posted May 13, 2011 Share Posted May 13, 2011 you would use that in whatever source you are using to retrieve the data sent from your form..so search.php Quote Link to comment https://forums.phpfreaks.com/topic/236314-displaying-mysql-results-code-error/#findComment-1215059 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.