Php 计数并显示数据库中的项目数(&D)

Php 计数并显示数据库中的项目数(&D),php,mysql,Php,Mysql,嗨,我想显示数据库中项目的编号。以下是php代码: $jobid = $_SESSION['SESS_MEMBER_JOB']; $data = "SELECT * FROM attributes WHERE jobid = $jobid"; $attribid = mysql_query($data) or die(mysql_error); $count = "SELECT count(*) FROM attributes WHERE jobid = $jobid"; $database_

嗨,我想显示数据库中项目的编号。以下是php代码:

$jobid = $_SESSION['SESS_MEMBER_JOB'];
$data = "SELECT * FROM attributes WHERE jobid = $jobid";
$attribid = mysql_query($data) or die(mysql_error);

$count = "SELECT count(*) FROM attributes WHERE jobid = $jobid";
$database_count = mysql_query($count);
//Declare the Array
$DuetiesDesc = array();

print_r ($database_count);
但我没有得到想要的结果,而是得到:

资源id 14

请协助

试试这个

<?php
 $jobid = $_SESSION['SESS_MEMBER_JOB'];
 $data = "SELECT * FROM attributes WHERE jobid =$jobid";
 $attribid = mysql_query($data) or die(mysql_error);
 $count=mysql_num_rows($attribid);
 echo $count;
?>
试试这个

<?php
 $jobid = $_SESSION['SESS_MEMBER_JOB'];
 $data = "SELECT * FROM attributes WHERE jobid =$jobid";
 $attribid = mysql_query($data) or die(mysql_error);
 $count=mysql_num_rows($attribid);
 echo $count;
?>

应该避免使用mysql,请参见

请参阅下面的代码。。。评论中有解释

$jobid = $_SESSION['SESS_MEMBER_JOB'];
// escape variables using mysql_real_escape_string
$data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string($jobid);

$attrRes = mysql_query($data) or die(mysql_error());

// I'm assuming you want all of the attributes return in this query in an array
$attributes = array();
while($row = mysql_fetch_assoc($attrRes)){
    $attributes[] = $row;
}

// Now if you want the count we have all of the records in the attributes array;

$numAttributes = count($attributes);


// here is an example of how you can iterate through it..
print "<p>Found ".$numAttributes." attributes</p>";
print "<table>";
foreach($attributes as $row){
    print "<tr>";
    foreach ($row as $cell){
        print "<td>".$cell."</td>";
    }
    print "</tr>";
}
print "</table>";

应该避免使用mysql,请参见

请参阅下面的代码。。。评论中有解释

$jobid = $_SESSION['SESS_MEMBER_JOB'];
// escape variables using mysql_real_escape_string
$data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string($jobid);

$attrRes = mysql_query($data) or die(mysql_error());

// I'm assuming you want all of the attributes return in this query in an array
$attributes = array();
while($row = mysql_fetch_assoc($attrRes)){
    $attributes[] = $row;
}

// Now if you want the count we have all of the records in the attributes array;

$numAttributes = count($attributes);


// here is an example of how you can iterate through it..
print "<p>Found ".$numAttributes." attributes</p>";
print "<table>";
foreach($attributes as $row){
    print "<tr>";
    foreach ($row as $cell){
        print "<td>".$cell."</td>";
    }
    print "</tr>";
}
print "</table>";
试试这个

 $jobid = $_SESSION['SESS_MEMBER_JOB'];
 $data = "SELECT *FROM attributes WHERE jobid =$jobid";
 $attribid = mysql_query($data) or die(mysql_error);

 $count = "SELECT count(*) FROM attributes WHERE jobid = $jobid";
 $database_count = mysql_query($count);
 //Declare the Array
 $DuetiesDesc = array();
 $database_count=mysql_fetch_assoc($database_count);
 echo $database_count['count(*)']; 
试试这个

 $jobid = $_SESSION['SESS_MEMBER_JOB'];
 $data = "SELECT *FROM attributes WHERE jobid =$jobid";
 $attribid = mysql_query($data) or die(mysql_error);

 $count = "SELECT count(*) FROM attributes WHERE jobid = $jobid";
 $database_count = mysql_query($count);
 //Declare the Array
 $DuetiesDesc = array();
 $database_count=mysql_fetch_assoc($database_count);
 echo $database_count['count(*)']; 
mysql函数扩展是。我建议使用mysqli_*函数或其他函数。mysql函数扩展是。我建议使用mysqli_*函数或其他函数。