SELECT script, where I would like to select active AND expir
Posted: Fri Dec 12, 2008 1:05 pm
I'm sorry if this is question is regarding too mutch PHP, but a friend of mine said that I should make a better MySQL query that gets both expired bans AND active bans. I've tried, but for no help. Please move this thread if it's too mutch PHP.
ebid = expired ban id
bid = ban id
This script works fine where it's both active AND expired bans, but not if there is only expired bans.
As I wrote, I've tried to make a select code that selects both active and expired bans, but the page just keep loading and if I try to query directly with a query browser, it's not responding. Anyways, here is the select code I tried:Thanks for any help, but please, try not to send me to a guide - I'm totally blank!
ebid = expired ban id
bid = ban id
This script works fine where it's both active AND expired bans, but not if there is only expired bans.
Code: Select all
if(preg_match("^user_\d{1,10}$^",trim(strtoupper($_GET["s"])))) {
mysql_connect('xxx','xxx','xxx');
@mysql_select_db('xxx') or die("Unable to select database");
$query = mysql_query("SELECT * from lol_old WHERE user_id='".$_GET['s']."'") or die(mysql_error());
$query1 = mysql_query("SELECT * from lol_oldbans WHERE user_id='".$_GET['s']."'") or die(mysql_error());
if(mysql_num_rows($query)) {
while($myrow = mysql_fetch_array($query)) {
if($myrow['ban_length'] == 0) {
$length = 'perm';
}
else {
$length = $myrow['ban_length'].'min';
}
$result = ' <p>'.$myrow['ban_reason'].' ('.$length.') - <a target="_blank" href="/?bid='.$myrow['bid'].'">?bid='.$myrow['bid'].'</a> (ACTIVE)</p>'."\r\n";
}
}
elseif(mysql_num_rows($query1)) {
while($myrow1 = mysql_fetch_array($query1)) {
if($myrow1['ban_length'] == 0) {
$length = 'perm';
}
else {
$length = $myrow1['ban_length'].'min';
}
$oldres .= ' <p>'.$myrow1['ban_reason'].' ('.$length.') - <a target="_blank" href="/ebid='.$myrow1['ebid'].'">?ebid='.$myrow1['ebid'].'</a></p>'."\r\n";
}
}
else {
$result = " <p>Not banned.</p>"."\r\n";
}
}
else {
$result = " <p>Error! The search has to start with 'user_'</p>"."\r\n";
}
echo $result;
echo $oldres;Code: Select all
SELECT * FROM lol_bans active, lol_oldbans expired WHERE active.user_id='".$_GET['s']."' OR expired.user_id='".$_GET['s']."'