2minutes2midnight Posted May 19, 2014 Share Posted May 19, 2014 I have a basic table where I am trying to retrieve records that are filtered by a form request. Here is the code I have...$ps = $pdo->prepare("SELECT * FROM `Products` Where `Vendor` LIKE concat('%',?,'%');$ps->execute(array($_POST['Vendor']));;echo "post=" . $_POST['vendor']; ////Displays correct data from form request$count = $ps->rowCount();echo "Count=" . $count; ////Count = 0 although I know for a fact that there is 1 record that should be in there////Used for display of recordsforeach ($ps as $row){echo $row, PHP_EOL . "xxx<br>";}Where is the incorrect code? I am new to php and pdo. Thank you in advanceK Quote Link to comment https://forums.phpfreaks.com/topic/288604-retrieving-data/ Share on other sites More sharing options...
linus72982 Posted May 20, 2014 Share Posted May 20, 2014 I'm going to assume you're using mysql: From the PHP.net page on rowCount (http://www.php.net/manual/en/pdostatement.rowcount.php): For most databases, PDOStatement::rowCount() does not return the number of rows affected by a SELECT statement. Instead, use PDO::query() to issue a SELECT COUNT(*) statement with the same predicates as your intended SELECT statement, then use PDOStatement::fetchColumn() to retrieve the number of rows that will be returned. Your application can then perform the correct action. This has been a known issue with rowCount for some time now. Quote Link to comment https://forums.phpfreaks.com/topic/288604-retrieving-data/#findComment-1480120 Share on other sites More sharing options...
trq Posted May 20, 2014 Share Posted May 20, 2014 Also, $_POST['Vendor'] os not the same as $_POST['vendor'] Quote Link to comment https://forums.phpfreaks.com/topic/288604-retrieving-data/#findComment-1480121 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.