Jump to content

Canman2005

Members
  • Posts

    669
  • Joined

  • Last visited

    Never

Posts posted by Canman2005

  1. In my sample table

     

    ID 1 & ID 2 - these are main topics (hence `type`=1)

    ID 3 & ID 4 - these are replies to main topics (hence `type`=2)

     

    ID 3 is a reply of ID 1 as it has TOPICID set to 1 (ID number 1)

    ID 4 is a reply of ID 2 as it has TOPICID set to 2 (ID number 2)

  2. Just to try to make it easier

     

    So with my table example

     

    ID  |  TYPE  |  TOPICID  |  TITLE  |      DATE      |  TIME

    1          1              1            post 1      2007-04-04    13:23:54

    2          1              2            post 2      2007-04-07    23:12:32

    3          2              1            reply 1      2007-04-10    08:23:53

    4          2              2            reply 2      2007-04-10    12:32:12

     

    When the query is run, it should return the rows as

     

    ID 2

    ID 1

     

    The reason it should return ID 2 first, is that the last row to be posted was ID4 (posted at 12:32:12 on 2007-04-10) and as ID 4 has a TOPICID as 2 then it would return row 2 (ID 2) as the first row, as that was the last replied to TOPIC.

     

    As we are only returning rows with a TYPE as 1, then it wouldnt return ID 3 or ID 4, but ID 4 was the last posted row.

     

    Does that make anymore sense?

     

    Thanks

  3. Hi all

     

    I wonder if someone can help, im really really stuck.

     

    I have a little message board that I setup, there is one table which runs the whole thing, this is a sample of the table;

     

    -------FORUM---------

     

    ID  |  TYPE  |  TOPICID  |  TITLE  |      DATE      |  TIME

    1          1              1            post 1      2007-04-04    13:23:54

    2          1              2            post 2      2007-04-07    23:12:32

    3          2              1            reply 1      2007-04-10    08:23:53

    4          2              2            reply 2      2007-04-10    12:32:12

     

    Let me explain what each field means

     

    ID - this is an auto ID

    TYPE - 1 means its a main topic \ 2 means its a reply to a main topic

    TOPICID - this is the ID number of the main topic

    TITLE - the title of the topic or reply

    DATE - date posted

    TIME - time posted

     

    What I currently do, is run a query to get all rows which have a TYPE as 1, basically this gets all the main topics, so if I run the QUERY

     

    SELECT * FROM `forum` WHERE `type` = '1'

     

    This returns all the topic posts.

     

    Once a topic is clicked on, I run another query to get the replies to the topic clicked on, this query is;

     

    SELECT * FROM `membersforum` WHERE `type` = '2' AND `topicid` = '".$_GET['topicid']."'

     

    This then grabs the replies to the topic selected.

     

    What I want to do is to alter the first QUERY

     

    SELECT * FROM `forum` WHERE `type` = '1'

     

    so that it returns all rows that have the `type` as 1, but ORDER these results with the first row returned, being the row that had the last reply (type 2) left on it.

     

    Basically I want to order all rows which have `type` as 1 in an order which has the row with the last reply to it, at the top, so I can sort them by last replied.

     

    Does that make sense?

     

    Sorry,  I tried to write this as best I can to explain my problem.

     

    Does anyone understand what im trying to do and can anyone help?

     

    Thanks in advance

     

    Dave

  4. Hi

     

    I dont think I explained it very well.

     

    Basically I want to get the ID number of all orders held in the "ordertransactions" table which were placed in August, I then want add together all the TOTAL fields in the 'orderlog' table which have the ORDER ID number of any of those orders placed in August on the `ordertransactions` table.

     

    On my example data, it would look in the table

     

    << ordertransactions >>

     

    and get the following rows (as they are the month of August)

     

    ID    DATE

    876  2007-08-12

    899  2007-08-14

     

    It would store the ID numbers and then get all the rows in the table `orderlog` which have those ID numbers stored in the ORDERID field;

     

    ID    ORDERID  TOTAL(£)

    1      876          29.99

    2      876          13.99

    3      899          10.00

     

    It would then add up all the totals for those ID's and then output it the TOTAL added together.

     

    So it would get ID numbers `876` and `899` and look them up in the ORDERID field of the `orderlog` table, which are ID numbers 1,2 and 3 and then add up the total for the TOTAL field, outputting 29.99 + 13.99 + 10.00.

     

    Does that make much sense?

     

    Thanks in advance

     

    Dave

  5. Hi all

     

    I have a small online shop, i have 2 SQL tables, one called "orderlog" which stores each item the user has purchased and also a table called "ordertransactions" which store the master details of each order. Each row of the table "ordertransactions" has a unique ID number.

     

    An example is

     

    << orderlog >>

     

    ID    ORDERID  TOTAL(£)

    1      876          29.99

    2      876          13.99

    3      899          10.00

     

    ID - this is a autoincreased number

    ORDERID - this is the ID number for the master order details in the table `ordertransactions`

    TOTAL - this is the total for each product bought

     

    << ordertransactions >>

     

    ID    DATE

    876  2007-08-12

    899  2007-08-14

     

    ID - this is a autoincreased number, this number is what is held in the field `ORDERID` in the `orderlog` table.

    DATE - this is the date the order was placed, in the format YYYY-MM-DD.

     

    As you can see, in the table `ordertransactions` there are 2 orders held, in the table `orderlog` you can see there are 3 rows, the first 2 rows relate to order ID 876 and the last row relates to order ID 899.

     

    You will now notice that inside the table `ordertransactions` there is a date held in the format YYYY-MM-DD.

     

    Okay, so what I want to do is to run a SUM query

     

    SELECT SUM(price) FROM ***

     

    on the `ordertransactions` table to return the total earned in a particular month. So if I run the query for the month August (08) then it would check the table `ordertransactions" for all rows where the month value equals 08, it would then grab the ID numbers for each of these rows and do a SUM on the `orderlog` table for all rows which contain those ORDER ID numbers, this would then return the TOTAL spent during the month 08.

     

    Does that make sense?

     

    Can anyone help, i've been trying to crack this for the last 9 hours and im getting no where fast.

     

    Thanks in advance

     

    Dave

  6. Hi all

     

    I have a simple query

     

    $sql = "SELECT * FROM siteusers";
    $query = @mysql_query($sql,$connection) or die(mysql_error());
    while ($row = mysql_fetch_array($query))
    {
    print $row['email'].'; ';
    }

     

    This basically produces something like;

     

    email@domain.com; myname@domain.com;

     

    How can I define these as a variable such as

     

    $allemails;

     

    So that I can insert it into a INSERT query.

     

    And lastly, how can I remove the symbol ; from the last row returned

     

    Can anyone help?

     

    Thanks

     

    Dave

  7. Sorry, might not be making much sense.

     

    Basically I want to get rid of everything that is held between two tags, so if the page content was

     

    -----------------------

    Welcome to the page

     

    *C*

    click here

    *C*

    ----------------------

     

    then it would strip out the following

     

    *C*

    click here

    *C*

     

    and simply print

     

    --------------------------

    welcome to the page

    --------------------------

     

    does the make any sense?

     

    Thanks

  8. Thanks for that, but what I meant was that it would replace anything between

     

    *C*

     

    So it would basically use them as tags, I could change them all to

     

    *C-start*

     

    and

     

    *C-end*

     

    so that it knows what the start tag is and what the end tag is

     

    can this be done in this case?

     

    Thanks again

     

    Dave

  9. Hi all

     

    Wonder if someone can help

     

    What I have is text for each page of my site which is stored in a sql table, to print the text on the pages I use

     

    <?php
    print $row['content'];
    ?>

     

    The following is an example of the type of content stored

     

    ------------------------------------------------

     

    Welcome to the contact page

     

    *C*

    page check

    *C*

     

    Please use the navigation bar above

     

    ------------------------------------------------

     

    What I want to do is to remove the section of the content which is between and including

     

    *C*

    page check

    *C*

     

    So it would just print the content as

     

    ------------------------------------------------

     

    Welcome to the contact page

     

    Please use the navigation bar above

     

    ------------------------------------------------

     

    Can this be done?

     

    Any help would be great

     

    Thanks in advance

     

    Dave

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.