Hi, I'm struggling to get a relatively simple PHP/MySQL script to work. Basically, I've got two tables populated with entries from a database.
PHP ver: 5.2.6
apache ver:2.2.9
Mysql ver:5.0.51b

However I'm getting errors on the second table:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/local/server/apache/htdocs/board.php on line 23

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/server/apache/htdocs/board.php on line 44

board.php code table:

16 <?php
     17 //DB connect
     18 include "dbconn.inc";
     19 
     20 //select
     21 $query = "SELECT * FROM 'freeboard' where'is_comment' = 0 order by 'thread' desc";
     22 $result = mysql_query($query, $dbconn);
     23 $total = mysql_num_rows($result);
     24 
     25 //paging
     26 $page = $_GET[page];
     27 $list_scale = 10;
     28 $page_scale = 10;
     29 if(!$page) {$page = 1;}
     30 $total_pages = ceil($total/$list_scale);
     31 $start = ($page-1)*$list_scale;
     32 if($total_pages > 1)
     33 {
     34 $page_count = ceil($page/$page_scale);
     35 $start_page = ($page_count-1)*$page_scale+1;
     36 $end_page = $start_page + $page_scale-1;
     37 if($end_page > $total_pages){
     38 $end_page = $total_pages;
     39 }}
     40 
     41 $query = "SELECT * FROM 'freeboard' where'is_comment' = 0 order by 'thread'desc limit $start, $list_scale";
     42 $result = mysql_query($query, $dbconn);
     43 
     44 for($i=$total-(($page-1)*$list_scale); $list=mysql_fetch_array($result); $i--){
     45 
     46 //reply &nbsp
     47 $reply = "";
     48 $reply2 = "";
     49 for($a = 0; $a < $list[depth]; $a++)
     50 $reply.="&nbsp;&nbsp;&nbsp;&nbsp;";
     51 if($list[depth] > 0)
     52 $repy2 = "[reply]";
     53 if($list[comment_num] > 0)
     54 $list[title].="($list[comment_num])";

Database Table:

+---------------+-------------+------+-----+---------+----------------+
| Field         | Type        | Null | Key | Default | Extra          |
+---------------+-------------+------+-----+---------+----------------+
| idx           | int(11)     | NO   | PRI | NULL    | auto_increment | 
| name          | varchar(20) | NO   |     | NULL    |                | 
| passwd        | varchar(20) | NO   |     | NULL    |                | 
| title         | varchar(80) | NO   |     | NULL    |                | 
| date          | varchar(10) | NO   |     | NULL    |                | 
| time          | varchar(8)  | NO   |     | NULL    |                | 
| hit           | int(11)     | NO   |     | NULL    |                | 
| contents      | text        | NO   | MUL | NULL    |                | 
| thread        | int(11)     | NO   | UNI | NULL    |                | 
| depth         | int(11)     | NO   |     | NULL    |                | 
| is_comment    | int(11)     | NO   |     | NULL    |                | 
| parent_thread | int(11)     | NO   |     | NULL    |                | 
| comment_num   | int(11)     | NO   |     | NULL    |                | 
+---------------+-------------+------+-----+---------+----------------+
13 rows in set (0.00 sec)
$query = "SELECT * FROM freeboard where is_comment = 0 order by thread desc";

Notice that I have removed unwanted '.

$query = "SELECT * FROM freeboard where is_comment = 0 order by thread desc";

try to use query in this forrm

$query = "SELECT * FROM freeboard where is_comment = 0 order by thread desc";

Notice that I have removed unwanted '.

If MySQL 5.* is being used then it is most likely you have this all wrong. This is because on some servers, MySQL 5 requires the apostrophe or as I would call it, the third quotation mark. Also the structure of the code is wrong as you need to refer to the column first.
So try the following.

$query = "SELECT * FROM `freeboard` WHERE `field` = 'is_comment' AND (`Type` ='0' OR `Null` = '0' OR `Key` = '0' OR `Default` = '0') ORDER BY 'thread' desc";

The only part of the above code I am not sure about is the following as it does not refer to any appropriate columns and I don't think there are any:

ORDER BY 'thread' desc

Also as a general notice, make sure you have the right code to connect to the MySQL database as that can cause the same error message.

If MySQL 5.* is being used then it is most likely you have this all wrong. This is because on some servers, MySQL 5 requires the apostrophe or as I would call it, the third quotation mark. Also the structure of the code is wrong as you need to refer to the column first.
So try the following.

$query = "SELECT * FROM `freeboard` WHERE `field` = 'is_comment' AND (`Type` ='0' OR `Null` = '0' OR `Key` = '0' OR `Default` = '0') ORDER BY 'thread' desc";

The only part of the above code I am not sure about is the following as it does not refer to any appropriate columns and I don't think there are any:

ORDER BY 'thread' desc

Also as a general notice, make sure you have the right code to connect to the MySQL database as that can cause the same error message.

1. ` can be used and not '
2. I don't know what Type, Null, Key or Default you are talking about in your query.
3. As I can see from the table structure posted by OP, there is a column called thread.

As I can see from the table structure posted by OP, there is a column called thread.

Isn't it a row called thread because those other words I included in the below text are what I believed to be the columns.

(`Type` ='0' OR `Null` = '0' OR `Key` = '0' OR `Default` = '0')

Note that when using phpMyAdmin, the columns are listed along the top and not the side. The things on the side are rows.

Well, here is the table structure for you.

+---------------+-------------+------+-----+---------+----------------+
| Field         | Type        | Null | Key | Default | Extra          |
+---------------+-------------+------+-----+---------+----------------+
| idx           | int(11)     | NO   | PRI | NULL    | auto_increment | 
| name          | varchar(20) | NO   |     | NULL    |                | 
| passwd        | varchar(20) | NO   |     | NULL    |                | 
| title         | varchar(80) | NO   |     | NULL    |                | 
| date          | varchar(10) | NO   |     | NULL    |                | 
| time          | varchar(8)  | NO   |     | NULL    |                | 
| hit           | int(11)     | NO   |     | NULL    |                | 
| contents      | text        | NO   | MUL | NULL    |                | 
| thread        | int(11)     | NO   | UNI | NULL    |                | 
| depth         | int(11)     | NO   |     | NULL    |                | 
| is_comment    | int(11)     | NO   |     | NULL    |                | 
| parent_thread | int(11)     | NO   |     | NULL    |                | 
| comment_num   | int(11)     | NO   |     | NULL    |                | 
+---------------+-------------+------+-----+---------+----------------+
13 rows in set (0.00 sec)

Thread is a column name of type int.

Below is an example of designing the above database:

+---------------+-------------+------+------+-----------+----------------+
| Column name   | Column name |Column|Column|Column name| Column name    |
+---------------+-------------+------+------+-----------+----------------+
| Row 1         | example     |      |      |           |                |
| Row 2         | example     |      |      |           |                |
| Row 3         | example     |      |      |           |                |
| idx           | int(11)     | NO   | PRI  | NULL      | auto_increment | 
| name          | varchar(20) | NO   |      | NULL      |                | 
| passwd        | varchar(20) | NO   |      | NULL      |                | 
| title         | varchar(80) | NO   |      | NULL      |                | 
| date          | varchar(10) | NO   |      | NULL      |                | 
| time          | varchar(8)  | NO   |      | NULL      |                | 
| hit           | int(11)     | NO   |      | NULL      |                | 
| contents      | text        | NO   | MUL  | NULL      |                | 
| thread        | int(11)     | NO   | UNI  | NULL      |                | 
| depth         | int(11)     | NO   |      | NULL      |                | 
| is_comment    | int(11)     | NO   |      | NULL      |                | 
| parent_thread | int(11)     | NO   |      | NULL      |                | 
| comment_num   | int(11)     | NO   |      | NULL      |                | 
+---------------+-------------+------+------+-----------+----------------+

So as you can see in my example is that straight across the top is the names of each column and the column on the very left has the rows like my example points out. Note that columns are verticle ( | ) and rows are horizontal ( --- ). Hope this helps to explain the confusion in this topic.

:-/ Did you see the table structure of the OP ? I am talking about column name "thread". Btw, a "row" represents "data" of the table and "column" represents the "columnname" (irrespective of how it displays the structure).

I have being analyzing the code and text snippets even further and I have a question that could turn around my answer. Is the following the table with all the data in it or is the following just the properties of a table.

+---------------+-------------+------+-----+---------+----------------+
| Field         | Type        | Null | Key | Default | Extra          |
+---------------+-------------+------+-----+---------+----------------+
| idx           | int(11)     | NO   | PRI | NULL    | auto_increment | 
| name          | varchar(20) | NO   |     | NULL    |                | 
| passwd        | varchar(20) | NO   |     | NULL    |                | 
| title         | varchar(80) | NO   |     | NULL    |                | 
| date          | varchar(10) | NO   |     | NULL    |                | 
| time          | varchar(8)  | NO   |     | NULL    |                | 
| hit           | int(11)     | NO   |     | NULL    |                | 
| contents      | text        | NO   | MUL | NULL    |                | 
| thread        | int(11)     | NO   | UNI | NULL    |                | 
| depth         | int(11)     | NO   |     | NULL    |                | 
| is_comment    | int(11)     | NO   |     | NULL    |                | 
| parent_thread | int(11)     | NO   |     | NULL    |                | 
| comment_num   | int(11)     | NO   |     | NULL    |                | 
+---------------+-------------+------+-----+---------+----------------+

Its the property (or the structure) of the table.

Its the property (or the structure) of the table.

Then sorry for the misunderstanding as this has been a confusing topic. But still the point I had about the third quotation mark (or apostrophe) needs to be put to use if you are using MySQL 5.*

The first piece of code I provided was assuming the above structure was all the data entered into the database. But knowing that is the structure of the table, you would need to use the following:

$query = "SELECT * FROM `freeboard` WHERE `is_comment` = '0' ORDER BY `thread` desc";

Right.. :) But one thing though.

But still the point I had about the third quotation mark (or apostrophe) needs to be put to use if you are using MySQL 5.*

Its optional and not mandatory.

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.