0

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
4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by benqus
0

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);
0

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";

?>

Edited by cwarn23: n/a

0

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

0
<?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 />";

?>

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.