Dynadot โ€” .com Transfer

How to "echo" .. PHP/Mysql

SpaceshipSpaceship
Watch
Impact
9
select count(*) from address where blenderp=1


I have spent 3 hours reading php tutorials and am not making any progress. even though I know this is pretty basic .. I cant get it

I know it is somehting like ..<?php
$Query = "select count(*) from address where blenderp=1"?>

Getting lost on how to echo that count

really appreciate some help
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Have you connected to the database?

Submitted the query?

Heres an example (which i've changed slightly) from http://au.php.net/manual/en/msql.examples-basic.php

Code:
<?php
/* Connecting, selecting database */
$link = msql_connect('localhost', 'username', 'password')
    or die('Could not connect : ' . msql_error($link));

msql_select_db('database', $link)
    or die('Could not select database');

/* Issue SQL query */
$Query = "select count(*) AS address_count from address where blenderp=1";
$result = msql_query($query, $link) or die('Query failed : ' . msql_error());

while ($row = msql_fetch_array($result)) {
 echo $row['address_count'];
}

/* Close connection */
msql_close($link);
?>
 
Last edited:
0
•••
Got it..thank You Music !
 
0
•••
This method is much more efficient.

This is easier on resources and faster:

PHP:
<?php
$dbname = 'xxx'; // db name 
$dbuser = 'xxx'; // db username 
$dbpass = 'xxx'; // db password 
$dbhost = 'localhost';     // db host, localhost should suffice. 
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); 
mysql_select_db($dbname, $conn) or die(mysql_error()); 
require('header.php');
$result = mysql_query('SELECT count(*) AS `address_count` FROM `address` WHERE `blenderp`=1') or die(mysql_error());
$result = mysql_result($result, 0, 0);
echo $result;
require('footer.php');

// you do not need to call mysql_cose(), it happens automagically at end of script.
?>
 
0
•••
Thanks for your codes.
Good sharing keep it up!
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back