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

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 に答える