NameSilo

How to "echo" .. PHP/Mysql

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
Got it..thank You Music !
 
0
Close
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
Close
Thanks for your codes.
Good sharing keep it up!
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back