Why is it always '1' ?
I'm a newbie at this, this is my first project. I got about a half dozen static pages built with xhtml 1.0 and everything links fine. Then I wanted to add the database to control the page content. I have two mysql queries that always return the value '1'.
1) The first happens after a successful connect, here is the code snippet:
$DbList = mysql_list_dbs ($conn);
$ListSz = mysql_num_fields ($DbList);
echo "MysqlConnect: DBCount = " . $ListSz . ", ";
Before I created my database, the value was '1'. After the database was successfully created, the value is still '1'.
2) The second happens when I try to create tables, here is the code snippet:
$txt = "SHOW TABLES";
$TbList = mysql_query ($txt);
$ListSz = mysql_num_fields ($TbList);
echo "MysqlConnect: TableCount = " . $ListSz . ", ";
Before I created a single table, I got a result of '1'. I successfully created 2 tables and I still get the value of '1'.
For my environment I'm using the latest version of MAMP (1.7.2 I believe).
I'm hoping someone can tell me what I'm doing wrong?
Try instead of
This is more of a PHP question ^^
show tables; - results in one column. The column contains the names of the tables. If you run that SQL inside the terminal you'll see what I mean. As suggested mysql_num_rows is what your after.
Welcome to the forums, AwolBush.
MySQL_Num_Fields()' job is to tell you how many fields are returned by the query.
MySQL_Num_Rows()' job is to tell you how many rows are returned.
The MySQL_List_DBs() function returns how many databases are available in the connection. Only one field is in that result, 'Database'.
$Query = MySQL_Query('SELECT ID, Name, Value FROM Table LIMIT 10');
$RowCount = MySQL_Num_Rows($Query); // 10 rows, as given by the limit.
$FieldCount = MySQL_Num_Fields($Query); // 3 fields - ID, Name, Value.
Thanks, the mysql_num_rows () gave the expected results.
If my IQ was 1 point lower I couldn't fly this frakkin' jet.