PDA

View Full Version : PHP query? I'm a noob at this



Illkillutill
08-06-2010, 09:37 PM
I posted on the actual support forums for this, but no one will give me an answer.

I'm attempting to make a version of RuneScape's Adventurer's Log for our clan site. I'm making a list of all Clan Member's so it's easier to look up that person's log. Instead of having to update the file manually, I want the list of members to be pulled from the Clan Member group on the forum.

The support team leader told me I have to query the group, because it's not loaded on every page load. I asked him for a tutorial or something to help me out, but he hasn't responded for the past 2 days, even though I've seen him on that thread...

So how do I query? It's all PHP and MySQL.

nielsie95
08-06-2010, 09:44 PM
If you want to have all the members, you need to have access to the database or you'll need to parse the members page.

Illkillutill
08-06-2010, 09:45 PM
I want all the members of just one group. I have full access to everything, so what do I do beyond that point? Maybe point me toward a tutorial? Google hasn't helped me out yet :p

nielsie95
08-06-2010, 09:48 PM
If you have the layout of the database, you should be able to build your query. Have you ever done something with SQL?

Illkillutill
08-06-2010, 09:51 PM
No, this is my first real attempt at anything like this.

nielsie95
08-06-2010, 09:54 PM
http://www.w3schools.com/PHP/php_mysql_intro.asp

I can help you build the query if you want. For that, the layout of the database would be of help (note: not a dump, just the layout) :)

Illkillutill
08-06-2010, 09:58 PM
Wow, thanks :)

The problem is, I'm not really sure what the layout of the DB is. No one seems to care at the support forum. It's MyBB forum software if that helps any. www.mybb.com

nielsie95
08-06-2010, 10:05 PM
I'm not sure what host you are using, but maybe phpMyAdmin is installed? I've never worked with MyBB before.. =\

Illkillutill
08-06-2010, 10:07 PM
http://www.000webhost.com/ is the host and yes, phpMyAdmin is installed.


offtopic:MyBB is officially my new favorite forum software :) It beat SMF and phpBB + a bunch of others in the best free forum software poll.

nielsie95
08-06-2010, 10:09 PM
phpMyAdmin will show you the structure of the database ;)
Although, now that I think of it, you could also use a php script to show the structure of the database..

EDIT: If you can get it to work with phpMyAdmin, this script (http://www.webcheatsheet.com/PHP/export_database_schema_xml.php)might be useful (it's also an example of how to perform queries on the database).

Illkillutill
08-06-2010, 10:23 PM
I used that script but keep getting an error saying
Warning: mysql_connect() [function.mysql-connect]: Host '66.197.250.118' is not allowed to connect to this MySQL server in /home/a5611424/public_html/forum/testphpdb.php on line 10

nielsie95
08-06-2010, 10:27 PM
I'm afraid I can't help you with that. Are you sure you filled in the information correctly?

Illkillutill
08-06-2010, 10:31 PM
:duh:
I didn't fill in the password, which I can't find the file I saved it in. Camaro isn't responding to me on msn to tell me it again... I'm sorry

nielsie95
08-06-2010, 10:35 PM
If there's a settings file for the forum, it might be in there?

Illkillutill
08-06-2010, 10:46 PM
Ok, I found this if it's what your looking for:

http://dev.mybb.com/projects/mybb/repository/entry/tags/mybb_1600/install/resources/mysql_db_tables.php

nielsie95
08-06-2010, 10:50 PM
Yap, looks like mybb_users is the table you're looking for.

"SELECT username FROM mybb_users" will return the names of all users. I don't know which users you need or how the groups work with MyBB, but it's probably something like "WHERE usergroup = 1" (attached to the query) or something.

Illkillutill
08-06-2010, 10:52 PM
Thank you!

Wouldn't it be mybb_usergroups? im trying to find anyone within the Clan Member group...

You've been more help in 5 minutes than any of there support team has been in a week lol

nielsie95
08-06-2010, 10:58 PM
No, I think mybb_usergroups holds information about the actual group itself. mybb_users holds the usergroup(s) in usergroup and additionalgroups.

Illkillutill
08-06-2010, 11:04 PM
Ok, so I've got this file setup:


<?php

define("IN_MYBB", 1);
$templatelist = "adLog";
require_once './global.php';
require_once './rsslib.php';

add_breadcrumb("Adventurer's Log", "adLog.php");

$output = '';

if ($mybb->user['usergroup'] == 7) {
error_no_permission();
} else {

mysql_connect(localhost,$username,$password);
$list = mysql_query("SELECT username FROM mybb_users WHERE usergroups=4");

$output .= '<center><table width="100%">
<tr colspan="2">
<th colspan="2" class="thead"><div style="float:left; color:white;">The Great Spiritz

Adventurer's Log</div><div style="float:right;"><input type="text" value="Search

players"><input type="button" value="Search"></th>
</tr>
<tr>
<td style="width:50%;" class="trow2 page_content"><center>Choose a clan member's

name to view their Adventurer's Log.<br><br><div>' .$list. '</div></center></td>
<td style="width:50%;" class="trow2 page_content"><center>Search for a player's

Adventurer's Log.<br><br></center></td>
</tr>
<tr colspan="2"><td colspan="2" class="tcat"></td></tr>
</table></center>';




eval("\$adLog_home = \"".$templates->get("adLog"). "\";");
output_page($adLog_home);
}

?>

and keep getting these errors

The following warnings occurred:
Warning [2] mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) - Line: 17 - File: adLog.php PHP 5.2.11 (Linux)
File Line Function
[PHP] errorHandler->error
/adLog.php 17 mysql_query
Warning [2] mysql_query() [function.mysql-query]: A link to the server could not be established - Line: 17 - File: adLog.php PHP 5.2.11 (Linux)
File Line Function
[PHP] errorHandler->error
/adLog.php 17 mysql_query


meaning it needs to have the correct information in the connection settings? then it should be right...

once camaro responds, i'll have it set up :p

nielsie95
08-06-2010, 11:10 PM
You have to walk through $list to get the information you want ;)
http://www.w3schools.com/PHP/php_mysql_select.asp

If you do "SELECT * FROM tablehere", you select all the fields from the table. Might be useful :)

Illkillutill
08-06-2010, 11:51 PM
Cool! That is going to be useful :)

I think I've got it now.

<?php

define("IN_MYBB", 1);
$templatelist = "adLog";
require_once './global.php';
require_once './rsslib.php';

add_breadcrumb("Adventurer's Log", "adLog.php");

$output = '';
// $usergroup['clan_member']
if ($mybb->user['usergroup'] == 7) {
error_no_permission();
} else {

$con = mysql_connect(localhost,username,password);
if (!$con) {
die('Could not connect: ' . mysql_error());
}

$sel = mysql_select_db("mybb_user", $con);
$que = mysql_query("SELECT * FROM mybb_users");
$list = mysql_fetch_array($que);

while($list['usergroup'] == clan_member) {
$output .= '<center><table width="100%">
<tr colspan="2">
<th colspan="2" class="thead"><div style="float:left; color:white;">The

Great Spiritz Adventurer's Log</div><div style="float:right;"><input

type="text" value="Search players"><input type="button" value="Search"></th>
</tr>
<tr>
<td style="width:50%;" class="trow2 page_content"><center>Choose a clan

member's name to view their Adventurer's Log.<br><br><div>' .$list

['usergroup']. '</div></center></td>
<td style="width:50%;" class="trow2 page_content"><center>Search for a

player's Adventurer's Log.<br><br></center></td>
</tr>
<tr colspan="2"><td colspan="2" class="tcat"></td></tr>
</table></center>';
}



eval("\$adLog_home = \"".$templates->get("adLog"). "\";");
output_page($adLog_home);
}

?>

nielsie95
08-07-2010, 12:01 AM
I'm afraid not, what are you trying to do here?

while($list['usergroup'] == clan_member)

http://php.net/manual/en/function.mysql-fetch-array.php

Also, usergroup should be an integer and you're comparing it to a constant (clan_member)?

Illkillutill
08-07-2010, 12:15 AM
<?php

define("IN_MYBB", 1);
$templatelist = "adLog";
require_once './global.php';
require_once './rsslib.php';

add_breadcrumb("Adventurer's Log", "adLog.php");

$output = '';
// $usergroup['clan_member']
if ($mybb->user['usergroup'] == 7) {
error_no_permission();
} else {

$con = mysql_connect(localhost,username,password);
if (!$con) {
die('Could not connect: ' . mysql_error());
}

$sel = mysql_select_db("mybb_user", $con);
$que = mysql_query("SELECT * FROM mybb_users");
while($list = mysql_fetch_array($que, MYSQL_NUM) == 4) {
$output .= '<center><table width="100%">
<tr colspan="2">
<th colspan="2" class="thead"><div style="float:left; color:white;">The

Great Spiritz Adventurer&#39;s Log</div><div style="float:right;"><input

type="text" value="Search players"><input type="button" value="Search"></th>
</tr>
<tr>
<td style="width:50%;" class="trow2 page_content"><center>Choose a clan

member&#39;s name to view their Adventurer&#39;s Log.<br><br><div>' .$list

['usergroup']. '</div></center></td>
<td style="width:50%;" class="trow2 page_content"><center>Search for a

player&#39;s Adventurer&#39;s Log.<br><br></center></td>
</tr>
<tr colspan="2"><td colspan="2" class="tcat"></td></tr>
</table></center>';
}



eval("\$adLog_home = \"".$templates->get("adLog"). "\";");
output_page($adLog_home);
}

?>


I am trying to see if the username is in the usergroup (4) which is the clan member group

nielsie95
08-07-2010, 12:47 AM
<?php

define("IN_MYBB", 1);
$templatelist = "adLog";
require_once './global.php';
require_once './rsslib.php';

add_breadcrumb("Adventurer's Log", "adLog.php");

$output = '';
// $usergroup['clan_member']
if ($mybb->user['usergroup'] == 7) {
error_no_permission();
} else {

$con = mysql_connect(localhost,username,password);
if (!$con) {
die('Could not connect: ' . mysql_error());
}

$sel = mysql_select_db("mybb_user", $con);
$que = mysql_query("SELECT * FROM mybb_users WHERE usergroup = 4");
$output .= '<center><table width="100%">
<tr colspan="2">
<th colspan="2" class="thead"><div style="float:left; color:white;">The
Great Spiritz Adventurer\'s Log</div><div style="float:right;"><input
type="text" value="Search players"><input type="button" value="Search"></th>
</tr>
<tr>
<td style="width:50%;" class="trow2 page_content"><center>Choose a clan
member\'s name to view their Adventurer\'s Log.<br><br><div>';
while($list = mysql_fetch_array($que)) {
$output .= $list['username']."<br>\n";
}
$output .= '</div></center></td><td style="width:50%;" class="trow2 page_content">
<center>Search for a player\'s Adventurer\'s Log.<br><br></center></td>
</tr>
<tr colspan="2"><td colspan="2" class="tcat"></td></tr>
</table></center>';

eval("\$adLog_home = \"".$templates->get("adLog"). "\";");
output_page($adLog_home);
}

?>


Try this..

Illkillutill
08-13-2010, 12:49 AM
Ok, I have the info now.

The problem is, when i put the username and real password in, it returns:

Parse error: syntax error, unexpected T_STRING in /home/a5611424/public_html/forum/adLogv.php on line 16

and if i put the username with the password field as "password", it just says that it can't connect.


Edit: I fixed it... for the moment :p I didn't have some stuff right.