heraldic2 Posted May 18, 2011 Share Posted May 18, 2011 Please deal with me for a moment as I try to explain what is occurring. I have created drop down menu that you choose a name and the php/MySQL will run multiple queries to display information regarding the chosen name. The query works great. There is no problem with the query. However when you leave the page, either by navigation or by X'ing out. When you return there are two errors that pop up: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in You can then use the drop down menu and choose a name and it all works great. It is my belief that these errors occur due to how the query was written, as the two queries that have these errors both have math in them. My question is, how do I block these errors from occurring when you return to the page? Here is the query: <?php //Worst Regular Season Record include_once('../other/functions.php'); $con = mysql_connect($hostname, $username, $password) OR DIE ('Unable to connect to database! Please try again later.'); $db = mysql_select_db($dbname, $con); $query = "SELECT win, loss, year, teamname FROM standings, owners WHERE owners.owner_id = standings.owner_id AND win = (SELECT MIN(win) FROM standings) AND standings.owner_id = $thing ORDER BY year"; $result = mysql_query($query); $row = mysql_fetch_array($result); @ mysql_data_seek($result, 0); if(mysql_num_rows($result)>0) { echo "<table CELLPADDING=5 border =1>"; echo "<tr>"; echo "<th align=center colspan=4 > Worst Regular Season Record </th>"; echo "</tr>"; while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td align=center> In '.$row['year'].', the '.$row['teamname'].' had '.$row['win'].' wins, and '.$row['loss'].' losses.</td>'; echo "</tr>"; } } else { } echo "</table>"; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/236717-due-to-math-in-query-there-is-an-error/ Share on other sites More sharing options...
sasa Posted May 18, 2011 Share Posted May 18, 2011 the variable $thing isn't set before you use it in query Quote Link to comment https://forums.phpfreaks.com/topic/236717-due-to-math-in-query-there-is-an-error/#findComment-1216834 Share on other sites More sharing options...
heraldic2 Posted May 18, 2011 Author Share Posted May 18, 2011 $thing is defined in functions.php based off of the choice of the drop down menu. Quote Link to comment https://forums.phpfreaks.com/topic/236717-due-to-math-in-query-there-is-an-error/#findComment-1216835 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.