Same user ID in WP

muti
User w
User w
Posts: 16
Joined: Thu Dec 26, 2019 5:45 am

Re: Same user ID in WP

Post by muti »

On Last topic can display by last "topic_id" and for last post by "post_id" or i need to make sql script ...


Code: Select all

<body bgcolor="black" link="blue" alink="blue" vlink="blue"><font size="1" color="blue"><center>Last 10 topics</center>
<?

function mysqlerror($err) {
global $mysql;

if ($mysql == "off") return;
echo $err . "<br><b>" . mysql_error() . "</b>";
exit;
}

function mysqlconnect() {
global $mysqlid, $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb;
if ($mysqlid) return;
$mysqlid = mysql_connect($mysqlhost, $mysqllogin, $mysqlpass) or mysqlerror("Can not connect to $mysqlhost");
mysql_select_db($mysqldb, $mysqlid) or mysqlerror("Missing DB $mysqldb");
}

function mysqlclose() {
global $mysqlid;
if ($mysqlid) @mysql_close($mysqlid);
}

function mysqlquery($sql) {
global $mysqlid;
if (!$mysqlid) mysqlconnect();
$res = mysql_query($sql, $mysqlid) or mysqlerror($sql);
return $res;
}

register_shutdown_function("mysqlclose");

// MySQL loading ----------------------------------------------
$mysqlid = 0;
$mysqlhost = 'Host';
$mysqldb = 'DB';
$mysqllogin = 'User';
$mysqlpass = 'Pass';
mysqlconnect();
// END MySQL loading ----------------------------------------------

$table_prefix = "Tabble prefix phpbb_";
$forum_url = "http://Forum URL";
$news_forum_id = 2;
$number_of_news = 10;
$date_format = "d.m.Y, G:i:s";

$query = "SELECT
t.`topic_id`,
t.`topic_title`,
p.`post_time`,
p.`post_username`,
p.`poster_id`,
u.`username`

FROM
`" . $table_prefix . "topics` as t,
`" . $table_prefix . "posts` as p,
`" . $table_prefix . "posts_text` as pt,
`" . $table_prefix . "users` as u
WHERE
t.`topic_first_post_id` = p.`post_id` AND
t.`topic_first_post_id` = pt.`post_id` AND
p.`poster_id` = u.`user_id` AND
t.`forum_id` = '" . $news_forum_id . "'
ORDER BY p.`post_time` DESC
LIMIT $number_of_news";
$result = mysqlquery($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<br>
<a href="<?= $forum_url ?>viewtopic.php?t=<?= $row['topic_id'] ?>">
<?= $row['topic_title'] ?>
<?= nl2br($row['post_text']) ?>

<? } ?>
</font></body>
Or something wrong ? :)

User avatar
axew3
w3all User
w3all User
Posts: 1971
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Same user ID in WP

Post by axew3 »

Well, may you're over complicating things.
Beside the fact i should run the query that we assume is correct, where you want to display the result?
In WordPress? Because the code you present is may suitable to run into phpBB side, not wordpress.

The query use variables and the way/style phpBB do things, not the wordpress way that basically is based into ezSQL library style.

a query into wp_w3all plugin, that since i use ezSQL even before WP, i use with old wild style, and not this
https://developer.wordpress.org/referen ... b/prepare/
that over complicate things for me, i know that not secure values needs to be passed on queries wrapped like this:
$w3db_conn->get_results(" SELECT * FROM topics where aVal = ' ".$var." ' ");
substantially wrapping/casting $vars like this ' " . $var . " ' (i give a white space to make it more clear the way it need to be)
and not this way:
$w3db_conn->get_results("SELECT * FROM topics where aVal = $var");
and not like this:
$w3db_conn->get_results("SELECT * FROM topics where aVal = ".$var.");
if you're not secure of what data are coming in. And i normally by the way like to know (sanitize) everything is coming in.

So a query in wp is more easy then in phpBB, like this (look that $w3all_config["table_prefix"] can be a more easy named var or even not a var so all result even much more readable):

Code: Select all

   $topics = $w3db_conn->get_results("SELECT T.*, P.*, U.* 
    FROM ".$w3all_config["table_prefix"]."topics AS T
    JOIN ".$w3all_config["table_prefix"]."posts AS P on (T.topic_last_post_id = P.post_id and T.forum_id = P.forum_id)
    JOIN ".$w3all_config["table_prefix"]."users AS U on U.user_id = T.topic_last_poster_id
    WHERE T.topic_visibility = 1
    AND T.forum_id IN(".$gf.")
    AND P.post_visibility = 1
    ORDER BY T.topic_last_post_time DESC
    LIMIT 0,$ntopics");
do you want to move the code above into wordpress? How the shortcode or widget should be named?

muti
User w
User w
Posts: 16
Joined: Thu Dec 26, 2019 5:45 am

Re: Same user ID in WP

Post by muti »

Like to display last topics in static WP page.
Like to display in web-tourist.net
Can check old site before migration but is not styled 91.196.126.30

muti
User w
User w
Posts: 16
Joined: Thu Dec 26, 2019 5:45 am

Re: Same user ID in WP

Post by muti »

Hi,
in WP on Settings > General New User Role is set to Contributor. But linked users have Subscriber role. How to change to set automatic role Contributor ?

User avatar
axew3
w3all User
w3all User
Posts: 1971
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Same user ID in WP

Post by axew3 »

So, the scenario is, you let register users in phpBB, then an user register into phpBB, and is added in WordPress, as subscriber, while you would like him added into wp Contributor group instead?
... looking ...
ah nice one!
Well, the actual code unchanged from long time, just do this, you're right:
admin in phpBB -> admin in wp
moderator in phpBB -> editor in wp
all others, as subscribers.

On the wild, you could change code with easy to accomplish with this.
And i assume will work.

Into file:
class.wp.w3all-phpbb.php
search for this line, (two times into file, same instruction, change both):

Code: Select all

 }  else { $role = 'subscriber'; }  // for all others phpBB Groups default to WP subscriber
change into:

Code: Select all

 }  else { $role = 'contributor'; }  // for all others phpBB Groups default to WP subscriber
then open wp_w3all.php and do the same into a single line, like the above.

We can provide option for this, so do this until 2.1.2, which will provide an option to add new coming phpBB users, into a specified WP group.
This option will be available since 2.1.2 next coming.

Post Reply