/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Back to basics SQL count

I cant seem to get this to return a number, just resource id #3.

this is my code that detects the users search and displays the appropriate.

It all works great except that the new count line doesn’t show a number.

[code=php]
$con = mysql_connect($mysql_host, $mysql_user, $mysql_password);
mysql_select_db($mysql_database, $con);

if ( isset ( $_SESSION[‘order’] )) $order = $_SESSION[‘order’]; else $order = ‘price’;
if ( isset ( $_SESSION[‘type’] ) && $_SESSION[‘type’] != ‘all’) $type = $_SESSION[‘type’]; else $type = null;
if ( isset ( $_SESSION[‘subtype’] )) $subtype = $_SESSION[‘subtype’]; else $subtype = null;
if ( isset ( $_SESSION[‘subsubtype’] )) $subsubtype = $_SESSION[‘subsubtype’]; else $subsubtype = null;
if ( isset ( $_SESSION[‘colour’] )) $colour = $_SESSION[‘colour’]; else $colour = null;
if ( isset ( $_SESSION[‘thickness’] )) $thickness = $_SESSION[‘thickness’]; else $thickness = null;
if ( isset ( $_SESSION[‘shape’] )) $shape = $_SESSION[‘shape’]; else $shape = null;

if (isset ($type)) $search = $search . ” WHERE type = ‘” . $type . “‘”;
if (isset ($subtype)) $search = $search . ” AND subtype = ‘” . $subtype . “‘”;
if (isset ($subsubtype)) $search = $search . “AND subsubtype = ‘” . $subsubtype . “‘”;
if (isset ($colour)) $search = $search . ” AND colour = ‘” . $colour . “‘”;
if (isset ($shape)) $search = $search . ” AND shape = ‘” . $shape . “‘”;
if (isset ($thickness)) $search = $search . ” AND thickness = ‘” . $thickness . “‘”;

$finalsearch = “SELECT * FROM Items ” . $search . ” ORDER BY ” . $order . ” DESC”;
$count = “SELECT COUNT(*) FROM Items ” . $search;
$itemcount = mysql_query($count);
$data = mysql_query($finalsearch);

echo “<br />” . $count . “–>” . $itemcount . “<br/>”;
return $data;}
[/code]

the line “echo “<br />” . $count . “–>” . $itemcount . “<br/>”;”
returns :
SELECT COUNT(*) FROM Items WHERE type = ‘plecs’ AND subtype = ‘celluloid’ AND colour = ‘blue’–>Resource id #3

I think i’m just underslept again

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@PlecPickerauthorJun 26.2012 — also when i enter that generated sql code into phpadmin, it works.
Copy linkTweet thisAlerts:
@rtretheweyJun 26.2012 — Replace this:
<i>
</i> $itemcount = mysql_query($count); <br/>

With this:
<i>
</i> $result= mysql_query($count);
$row = mysql_fetch_assoc($result);
$itemcount = $row['COUNT(*)'];
Copy linkTweet thisAlerts:
@NogDogJun 26.2012 — You need to "fetch" the result from the query result resource (e.g.: mysql_fetch_assoc() or mysql_result()).
Copy linkTweet thisAlerts:
@PlecPickerauthorJun 26.2012 — Thanks Nog.

?
×

Success!

Help @PlecPicker spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...