SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Why is it always '1' ?
Hybrid View
-
Apr 12, 2009, 21:12 #1
- Join Date
- Apr 2009
- Location
- Texas
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?
awolbush
-
Apr 12, 2009, 21:53 #2
Try
Code PHP:Code PHP:
This is more of a PHP question ^^
-
Apr 13, 2009, 04:02 #3
- Join Date
- Jul 2006
- Location
- Augusta, Georgia, United States
- Posts
- 4,194
- Mentioned
- 17 Post(s)
- Tagged
- 5 Thread(s)
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.
-
Apr 13, 2009, 04:09 #4
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
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.
For example:
PHP Code:<?php
$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.Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Apr 13, 2009, 17:09 #5
- Join Date
- Apr 2009
- Location
- Texas
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, the mysql_num_rows () gave the expected results.
awolbush
If my IQ was 1 point lower I couldn't fly this frakkin' jet.
Bookmarks