Sfrius Posted April 4, 2014 Share Posted April 4, 2014 Hello, I cannot figure out why the following code is giving me problems. Here it works. $AssignedOpportunities = array(); $SQLstring = "SELECT opportunityID FROM $TableName " . " WHERE date_approved IS NOT NULL"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) > 0) { while (($Row = mysql_fetch_row($QueryResult)) !== FALSE) $AssignedOpportunities[] = $Row[0]; mysql_free_result($QueryResult); } Here it doesn't work $TableName = "opportunities"; $Opportunities = array(); $SQLstring = "SELECT opportunityID, company, city, " . " start_date, end_date, position, description " . " FROM $TableName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) > 0) { //LINE CONTAINING THE ERROR while (($Row = mysql_fetch_assoc($QueryResult)) !== FALSE) $Opportunities[] = $Row; mysql_free_result($QueryResult); } Link to comment https://forums.phpfreaks.com/topic/287524-mysql_num_rows/ Share on other sites More sharing options...
Sfrius Posted April 4, 2014 Author Share Posted April 4, 2014 $SQLstringg = "SELECT * FROM `opportunities`"; This works for now. I had to use the special characters for '. For some reason the language in my db is set to latin1/swedi. Why doesn't the mysql database except the basic format for mysql commands? Link to comment https://forums.phpfreaks.com/topic/287524-mysql_num_rows/#findComment-1474995 Share on other sites More sharing options...
davidannis Posted April 4, 2014 Share Posted April 4, 2014 The line $QueryResult = @mysql_query($SQLstring, $DBConnect); suppresses error messages from the query http://www.php.net/manual/en/language.operators.errorcontrol.php As a general rule suppressing errors is not a good idea so get rid of the @ Then, the next line gives an error because $QueryResult contains false. To see the error when the query fails try: $QueryResult = mysql_query($SQLstring, $DBConnect) or die (mysql_error($DBConnect)); http://www.php.net/manual/en/function.mysql-error.php which will print the error that caused your query to fail then stop. Link to comment https://forums.phpfreaks.com/topic/287524-mysql_num_rows/#findComment-1474997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.