Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-01-2013, 11:52 AM   PM User | #1
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,544
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
What do I replace the depreciated mysql_num_rows with ?

Hi,

I quite often use :

PHP Code:
$sql "SELECT page_id,page_type,cat_cd FROM pages WHERE assigned = 'n' ";
$result mysql_query($sql)    or die("could not find SITE: $site_id"mysql_error());
$num mysql_num_rows($result);

if (
$num ) { 
I just noticed that the Manual says "mysql_num_rows - This extension is deprecated as of PHP 5.5.0"

I write php in procedural style rather than OOP.

What should I use instead of
$num = mysql_num_rows($result);

Thanks


.
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 02-01-2013, 05:16 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 361 Times in 360 Posts
sunfighter is on a distinguished road
This page in the manual: http://www.php.net/manual/en/mysqli-stmt.num-rows.php
sunfighter is offline   Reply With Quote
Old 02-01-2013, 07:05 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,744
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
That one would be for statements, while from result you can use mysqli_num_rows. So it depends on if you are preparing a statement or querying directly.
I should note that since there are two functions and you could do either statements or direct querying, you'd be better of using either the statement's get_result and pulling the mysqli_num_rows off of that, or even better, simply sticking to object oriented as both mysqli_stmt and mysqli_result contain a num_rows property on them.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Old 02-02-2013, 11:51 AM   PM User | #4
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,907
Thanks: 10
Thanked 293 Times in 289 Posts
Dormilich is on a distinguished road
depending on the case, SQL’s COUNT() function can be used to avoid the PHP row counting alltogether.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:11 PM.


Advertisement
Log in to turn off these ads.