Hi all,

The following should display a record count, however im getting to a blank screen.

Can anybody see why this query wont display anything?

<?php

$link = mysql_connect("localhost", "uname", "pword");
mysql_select_db("dbname", $link);

$result = mysql_query("SELECT ID FROM tbl_sellers", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?> 

i get no errors, just a blank screen

Hi whiteyoh,

Must admit, it looks fine to me too... presumably table name, column name or similar is the issue.

Try outputing the error by adding a row:

echo "Error " . mysql_errno($link) . ": " . mysql_error($link);

Generally when debugging mysql the following is how to do it.

<?php

$link = mysql_connect("localhost", "uname", "pword") or die('error 1<hr>'.mysql_error());
mysql_select_db("dbname", $link) or die('error 2<hr>'.mysql_error());

$result = mysql_query("SELECT ID FROM tbl_sellers", $link) or die('error 3<hr>'.mysql_error());
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>

Hi This worked fine so thanks for that. Very interesting on the error reporting, makes it so much easier.

Can you offer any advice on multiple queries in one call?

mysql connect - query 1 to table 1
connect - query 2 to table 2

all in one page

<?php

$link = mysqli_connect("localhost", "uname", "pword", "dbname");

$query="SELECT ID FROM tbl_sellers";
$result=mysqli_query($link, $query);
$count=0;
while($row=mysqli_fetch_array($result)){
   $count++;
}

echo "$count."<br />";

?>

OR

<?php

$link = mysqli_connect("localhost", "uname", "pword", "dbname");

$query="SELECT ID FROM tbl_sellers";
$result=mysqli_query($link, $query);
$count=count(mysqli_fetch_array($result);

echo "$count."<br />";

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.