r-it Posted April 5, 2007 Share Posted April 5, 2007 can anyone tell me why this error is appearing, here is my code: session_start(); require("connex.php"); $conn = new dbConnector(); $sql = $conn->query("SELECT * FROM roles WHERE roleID != '1'"); while($rec = $conn->fetchArray($sql)) { $rid = $rec['roleID']; $role = $rec['role']; $text .= "<h2>$role</h2>"; $qry = $conn->query("SELECT users.name AS naam, users.surname AS van, users.descr as desc FROM users, user_roles WHERE users.userID = user_roles.userID AND user_roles.roleID = '$rid' ORDER BY users.surname"); if(mysql_affected_rows($qry) < 1) { $text .= "(No records)<br>"; } else { while($rek = $conn->fetchArray($qry)) { $name = $rek['naam']; $surname = $rek['van']; $desc = $rek['desc']; $text .= "<b>$name $surname</b><br>$desc<br><br>"; } } } Link to comment https://forums.phpfreaks.com/topic/45699-solved-mysql_affected_rows-supplied-argument-is-not-a-valid-mysql-link-resource/ Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 mysql_affected_rows (PHP 3, PHP 4, PHP 5) mysql_affected_rows -- Get number of affected rows in previous MySQL operation Description int mysql_affected_rows ( [resource link_identifier] ) Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier. Link to comment https://forums.phpfreaks.com/topic/45699-solved-mysql_affected_rows-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-221995 Share on other sites More sharing options...
r-it Posted April 5, 2007 Author Share Posted April 5, 2007 the thing is i want to check if there were no records meeting the where clause, ie. there were no rows selected, and i tried mysql_num_rows as well and it works as well, but gives me those errors at the top of the page Link to comment https://forums.phpfreaks.com/topic/45699-solved-mysql_affected_rows-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-221999 Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 in ur connex.php file there is a function query() Just post it here Link to comment https://forums.phpfreaks.com/topic/45699-solved-mysql_affected_rows-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-222002 Share on other sites More sharing options...
r-it Posted April 5, 2007 Author Share Posted April 5, 2007 heres the connex.php <?php require_once 'sysComp.php'; class dbConnector extends Conn { var $theQuery; var $link; //constructor function: connect to db function dbConnector() { $settings = Conn::getSettings(); $host = $settings['dbhost']; $db = $settings['dbname']; $user = $settings['dbusername']; $pass = $settings['dbpass']; //connect to the database $this->link = mysql_connect($host, $user, $pass); mysql_select_db($db); } //query function: execute a db query function query($query) { $this->theQuery = $query; return mysql_query($query, $this->link); } //fetchArray function: get array of query results function fetchArray($result) { return mysql_fetch_array($result); } //close function: close the connection function close() { mysql_close($this->link); } } ?> Link to comment https://forums.phpfreaks.com/topic/45699-solved-mysql_affected_rows-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-222026 Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 $qry = $conn->query("SELECT users.name AS naam, users.surname AS van, users.descr as `desc` FROM users, user_roles WHERE users.userID = user_roles.userID AND user_roles.roleID = '$rid' ORDER BY users.surname"); if(isset($qry) and mysql_num_rows($qry)){ ...........found data......... }else{ ........Prb with query or zero records found........... } Link to comment https://forums.phpfreaks.com/topic/45699-solved-mysql_affected_rows-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-222029 Share on other sites More sharing options...
AndyB Posted April 5, 2007 Share Posted April 5, 2007 important tip: do not use mysql reserved words (like desc) for field names. Link to comment https://forums.phpfreaks.com/topic/45699-solved-mysql_affected_rows-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-222031 Share on other sites More sharing options...
r-it Posted April 5, 2007 Author Share Posted April 5, 2007 thanks a lot guys, it helped a lot Link to comment https://forums.phpfreaks.com/topic/45699-solved-mysql_affected_rows-supplied-argument-is-not-a-valid-mysql-link-resource/#findComment-222037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.