![]() |
|
#1
|
|||
|
|||
comparing two columnsIs it possible two compare two columns in a database?
I have never tried to compare two columns so I dont know if it is the way I have written it or if it is even possible.#counts total posts in a thread. PHP Code:
"post_id" and "id" are the columns. I am trying to retrieve the number of posts to a thread and place the result on a page next to the listed thread. Am I making any sense? Can anyone help? Last edited by LuciWiz : 14-Nov-2005 at 02:08.
Reason: Please insert your Php code between [php] & [/php] tags
|
|
#2
|
|||
|
|||
Re: comparing two columnsI am building a forum system right now and it is possible to count posts in a certain thread, or threads in a topic for that matter. The way I did it was by creating separate tables for topics, threads, and posts. And in the threads table I used topic_id (which would equal the "id" field of the topic it belonged to), then in the posts table I made a thread_id (again associating the post to the thread table's "id").
For example (very simple tables): PHP Code:
With these tables you then join them in a SQL search statement: PHP Code:
This is called a class-based query search, in which you use two or more tables and therefore have to associate the field you are looking for to a table by adding the table's name in front of it: TABLENAME.FIELD. If any of this doesn't make sense, please let me know Last edited by LuciWiz : 14-Nov-2005 at 02:09.
Reason: Please insert your Php code between [php] & [/php] tags
|
|
#3
|
|||
|
|||
Re: comparing two columnsfallen_samurai, I am doing the same thing you are. Only difference is I use one table. When someone makes a post I associate the row number of the thread to the post as a value. post_id gets its number from the id of the thread. At this point I am trying to match them up and count them.
But I cant seem to get it to work. |
|
#4
|
||||
|
||||
Re: comparing two columnsIf you really want some suggestions, you need to supply the table structure with some example data and what you expect to retrieve.
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#5
|
|||
|
|||
Re: comparing two columnsQuote:
Hi JdS, I can try and do that. Table structure: http://zurke.biz/table.php Location: http://zurke.biz/location.php As you can see in the table structure the post_id has the same number as the thread_id's row 'id'. When a thread is created post_id is '0' and thread_id takes on a section number, that I can group together. When a post is created thread_id is '0' and Post_id takes on the row 'id' of the thread_id to match them up. I want to count how many post_id's have a particular thread_id, place it into a variable for a while statement and display them as replies/posts to a particular thread. As shown on the "location" document I provided. If this is not enough info just ask. I can get whatever you need. I have tried for some time to get it to work but I can only put them into an array. An array doesnt work because there could be 10, 20, 100 + posts, who knows? I appreciate the help. Thanks. |
|
#6
|
|||
|
|||
Re: comparing two columnsQuote:
correction: I should have written thread_id as id. The correction is in bold. As you can see in the table structure the post_id has the same number as the thread_id's row 'id'. When a thread is created post_id is '0' and thread_id takes on a section number, that I can group together. When a post is created thread_id is '0' and Post_id takes on the row 'id' of the thread_id to match them up. I want to count how many post_id's have a particular id, place it into a variable for a while statement and display them as replies/posts to a particular thread. As shown on the "location" document I provided. If this is not enough info just ask. I can get whatever you need. I have tried for some time to get it to work but I can only put them into an array. An array doesnt work because there could be 10, 20, 100 + posts, who knows? Also, here is the actual code for the placement of the variable: # This section is the product of the above query. echo"<table border='1' background='' bgcolor='' cellpadding='0' cellspacing='0' width='850' height='80' align='center'><tr>"; echo"<td background='' bgcolor='' width='400' align='left'>";view_post(); echo"</td><td background='' bgcolor='' width='150' height='80' align='center'><font size='3' color='ffffff' face''><b>$author </b></font></td>"; echo"<td background='' bgcolor='' width='100' height='80' align='center'><font size='3' color='ffffff' face''>$date<br>$time </font></td>"; echo"<td background='' bgcolor='' width='100' height='80' align='center'><font size='3' color='ffffff' face''>$total </font></td>"; echo"<td background='' bgcolor='' width='100' height='80' align='center'><font size='3' color='ffffff' face''>$views </font></td>"; echo"</tr></table>"; |
Recent GIDBlog
First week of IA training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| speed of comparing char arrays | andy_t_roo | C Programming Language | 3 | 30-Jun-2005 18:12 |
| Comparing strings in C | Tanag | C Programming Language | 2 | 28-Nov-2004 18:07 |
| Sorting columns by selection | dean | MySQL / PHP Forum | 1 | 03-Oct-2003 06:29 |
| Opinions Wanted: do 2 columns or 3 look best for this site layout? | jps0 | Websites Reviewed Forum | 10 | 20-Aug-2003 15:30 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The