1

嗨,我想显示数据库中的项目数。以下是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

请协助

4

3 回答 3

2

应该摆脱不应该使用 mysql_* 的方式,请参阅为什么我不应该在 PHP 中使用 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>";
于 2013-05-16T06:40:04.503 回答
1

尝试这个

<?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;
?>
于 2013-05-16T06:30:39.487 回答
1

尝试这个

 $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(*)']; 
于 2013-05-16T06:55:28.967 回答