Jump to content

mysql_num_rows


Sfrius

Recommended Posts

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
Share on other sites

$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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.