Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
iamstinky
Feb 4, 2004

This is not as easy as it looks.

gi- posted:

So I just upgraded my hosting environment. Went from PHP4 to PHP5 and getting this error 'Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource'

for this piece of code:

$rs = mysql_query($query);
if (mysql_num_rows($rs)>0)

PHP.net posted:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
var_dump($rs) when you get the error and see what it actually says. Presumably other pieces of code that do mysql work? Or is the only db connection you have?

Adbot
ADBOT LOVES YOU

iamstinky
Feb 4, 2004

This is not as easy as it looks.
Or download the php function look up extension for PHP here : http://www.folta.info/blog/

iamstinky
Feb 4, 2004

This is not as easy as it looks.
I am trying to implement a reversible sort a 2d array by an arbitrary key in the second level function.

So I used an insertion sort (or it's based on an insertion sort rather):

php:
<?
function sort_list($array,$index="person_id",$direction) {
//$array[0] = "person_id"=> 1223523,"class"=>"Shakespeare","type"=>"Final",etc...
$max = count($array);

  if ( $direction == "asc" ) {
 
    for($j=1; $j < $max; $j++){
      $temp = $array[$j];
      $i = $j;
    
      while(!empty($array[$i-1]) && ($i >= 0) && ($array[$i-1][$index] > $temp[$index])){
         $array[$i] = $array[$i-1];
         $i--;
      }
      
      $array[$i] = $temp;
      
    }

  } else if ( $direction == "desc" ) {
    
    for($j=1; $j < $max; $j++){
      $temp = $array[$j];
      $i = $j;
    
      while( !empty($array[$i-1]) && ($i >= 0) && ($array[$i-1][$index] < $temp[$index])){
         $array[$i] = $array[$i-1];
         $i--;
      }
      
      $array[$i] = $temp;
      
    }
  }  
  
  return $array;
}
?>
Is there a better way to do this if I need to be able to sort on class or person_id etc? $array size won't ever be more than a couple thousand elements.

iamstinky
Feb 4, 2004

This is not as easy as it looks.

bt_escm posted:

I have to question where you're getting the data from that you would need to sort it in php?

It is a combination of physical file data and stuff from db, sortable by the user as needed. As some of it isn't db related I can't let the DB sort the data for me. But if you have any suggestions, feel free to offer them.

iamstinky
Feb 4, 2004

This is not as easy as it looks.
php:
<?
$_SESSION['current_vendor'] or $_SESSION['current_vendor']    = $r[2];
?>
Can someone explain to me what the person who wrote this might have thought they were doing? I mean it makes me feel like a billion of my brain cells just committed suicide every time I try to figure what he was doing here. For what it's worth $r[2] is part of a result set that should contain the vendor information.

:saddowns:

Adbot
ADBOT LOVES YOU

iamstinky
Feb 4, 2004

This is not as easy as it looks.
I hate the guy that worked here before me so much.

EDIT:
Of the six or so apps that I enhance, unfuck and add functionality to, I have at least 10 pages that are 1000+ line switch statements that just end because the one loving function the guy bothered to write in his entire life calls something that includes something that started an output buffer and defined a preg_replace that calls a template and then somehow magically shits out a page that is functional.

iamstinky fucked around with this message at 21:39 on Aug 12, 2008

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply