Jump to content

Barand

Moderators
  • Posts

    24,420
  • Joined

  • Last visited

  • Days Won

    805

Posts posted by Barand

  1. [php:1:5cdcaf3177]<?php

    $sql = \"SELECT * FROM forums WHERE forumno = \'$board\' ORDER BY threadid, postid DESC \";

    $res = mysql_query($sql);

    $lastid=0;

    while ($row = mysql_fetch_array($res)) {

    if ($row[\'threadid\'] != $lastid) {

    $array[$row[\'threadid\']] = $row[\'postid\']<br>\";

    }

    $lastid = $row[\'threadid\'];

    }

    ?>[/php:1:5cdcaf3177]

    We now have array with key = thread and value = lastest postid for thread. Sort to reverse order and display.

     

    [php:1:5cdcaf3177]<?php

    arsort ($array);

     

    foreach ($array as $thread=>$post) {

    echo $thread $post;

    }

    ?>[/php:1:5cdcaf3177]

  2. What I need is to be able to get a list of posts in desc order and group them by threadid which then leave me with the the most recnt post for each thread in a descending order.

     

    The code I posted will give the latest post for each thread but not necessarily in desc time order by thread. For that you would need the date field, but as its varchar (and not datetime) I don\'t know if the contents would give the correct sorted sequence.

     

    Edit: just realised we _can_ use postid, I\'ll amend my code and resubmit.

  3. Heres the SQL dump I used:-

     

    [php:1:1ca2a8e291]CREATE TABLE forums (

    postid int(8) unsigned NOT NULL auto_increment,

    forumno int(8) unsigned NOT NULL default \'0\',

    threadid int(8) unsigned NOT NULL default \'0\',

    date varchar(15) NOT NULL default \'\',

    user_id int(8) unsigned NOT NULL default \'0\',

    ip varchar(30) NOT NULL default \'\',

    subject varchar(50) NOT NULL default \'\',

    comment blob NOT NULL,

    deleted int(1) unsigned NOT NULL,

    newthread int(1) unsigned NOT NULL,

    PRIMARY KEY (postid),

    KEY game_id (user_id)

    ) TYPE=MyISAM;[/php:1:1ca2a8e291]

     

     

    Will I need to change the structure then?

     

    I\'d strongly advise using a proper datetime type for date fields instead of varchar and also do not call it \'date\' as it\'s a reserved word. Use something like \'post_date\'.

  4. Assuming your db does not support subqueries, this will list the latest post for each thread

     

    [php:1:0308db28b1]<?php

    $sql = \"SELECT * FROM forums WHERE forumno = \'$board\' ORDER BY threadid, postid DESC \";

    $res = mysql_query($sql);

    $lastid=0;

    while ($row = mysql_fetch_array($res)) {

    if ($row[\'threadid\'] != $lastid) {

    echo \"$row[\'threadid\'] $row[\'postid\']<br>\";

    }

    $lastid = $row[\'threadid\'];

    }

    ?>[/php:1:0308db28b1]

     

    hth

  5. will that keep it constantly updated?

     

    No, its a one time transfer. If you are keeping both tables do it this way

     

    1 Create new table without any auto_increment on uid but keep as primary key

     

    2 Add \'uid\' field to my query and execute

    INSERT INTO cont_users (uid, username, password,email) SELECT 
    
    uid, uname, pass,email FROM nkw_users

     

    3 drop uname, pass and email field from original table (don\'t want duplication.

     

    4. Decide on which is to be the master table (prob the new one) and change to auto_inc on uid and take auto_inc off old table (or vice versa) so only one generates new uid. When adding new users, insert one with auto key first and write record with same key to other table.

     

    5. Now for JOIN bit

    To access data from both tables

    SELECT * FROM cont_users c INNER JOIN nkw_users n ON c.uid = n.uid

     

    hth

  6. Nooo!

     

    Either recreate table completely (losing data) with my original create SQL

     

    mysql_query("CREATE TABLE reviews ( 
    
       id int auto_increment primary key, 
    
       review_name VARCHAR(20), 
    
       basic_plot VARCHAR(80), 
    
       review VARCHAR(100), 
    
       email VARCHAR(20), 
    
       poster_url VARCHAR(20), 
    
       publisher VARCHAR(20), 
    
       author VARCHAR(30))"); 

    or run alter query on its own - adds field witthout you losing data

     

     

    ALTER TABLE reviews ADD id int auto_increment primary key

     

    hth

  7. I haven\'t ploughed through every line of that tome you submitted but heres a couple of observations

     

    You are using reserved words as field names, eg Date, which will give sql syntax errors (unless you put backtick araound the `date` in queries).

     

    If you are going to have a date field you are much better off using type DATE or DATETIME and not text.

     

    Having created a primary key on field id, why then go and create two further indexes on the same field? - its just a waste of time and space.

  8. To find the records that are in TableMaster but not in TableEncoding use a LEFT JOIN :-

     

    SELECT m.ProvinceCode, m.CityOrMuni, m.BarangayName

    FROM TableMaster m LEFT JOIN TableEncoding e

    ON m.ProvinceCode = e.ProvinceCode

    AND m.CityOrMuni = e.CityOrMuni

    AND m.BarangayName = e.BarangayName

    WHERE e.ProvinceCode IS NULL

     

    hth

  9. I suppose it comes down to how keywords are decided.

     

    If users enter the keywords relevant to the record at the time it is submitted to the database, and you want searches limited to those keywords, go with the solution of separate indexed table.

     

    If keywords can be anything in the text, go with FULLTEXT.

     

    Does this sound reasonable?

  10. As many as you like.

     

    For example, ou might want something like

     

    $[php:1:6b1d98c71d]<?php

    datetime = date(\'d m Y H:i\');

    $name = $_POST[\'name\'];

    $body = \"$name submitted a form at $date\";

    ?>[/php:1:6b1d98c71d]

     

    hth

  11. Adding id field

    [php:1:63bb55816f]<?php

    mysql_query(\"CREATE TABLE reviews (

    review_id int not null auto_increment primary key,

    review_name VARCHAR(20),

    basic_plot VARCHAR(80),

    review VARCHAR(100),

    email VARCHAR(20),

    poster_url VARCHAR(20),

    publisher VARCHAR(20),

    author VARCHAR(30))\");

    ?>[/php:1:63bb55816f]

     

    Listing reviews

    [php:1:63bb55816f]<?php

    $query = \"SELECT review_id, review_name FROM reviews\";

    $result = mysql_query($query);

    $numrows = mysql_num_rows($result);

     

    print(\"We have <b>$numrows</b> reviews in our database <p>\");

     

    while($row = mysql_fetch_array($result)){

    $id = $row[\'review_id\'];

    echo \"<A href=\"showreview.php?id=$id\"><b>$row[review_name]</b></A><br>\";

     

    }

     

     

    ?>[/php:1:63bb55816f]

     

    In showreview.php

    [php:1:63bb55816f]<?php

    $id = $_GET[\'id\'];

    $query = \"SELECT * FROM reviews WHERE review_id = $id\"

    // display review contents

    ?>[/php:1:63bb55816f]

     

    hth

  12. SELECT p.perm_name, p.perm_desc FROM

    (some_perms p INNER JOIN some_role_perms r

    ON p.perm_id = r.perm_id)

    INNER JOIN some_user_roles u

    ON r.role_id = u.role_id

    WHERE u.user_id = $userid

     

    hth

  13. Each property can have many appellations and each appellation can apply to many properties. Same goes for grape varieties

     

    In these cases you need linking tables to provide many to many relationships. Only one classification is required so classification_id can be held in property table with link to classification table.

     

    Can\'t see a way to do attachments in this forum so I\'ll email diagram

×
×
  • 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.