Jump to content

[SOLVED] Strange problem.. can't get mysql_fetch_array() to work?


kernelgpf

Recommended Posts

Here's my entire script- it's worked previously, and is suddenly not working.. no errors, nothing being printed. That's the problem.

 

<?php
include "header.php";
print "Searching usernames is searching all player's BASIC names, not their display names.<p>";
if($_GET['action'] == "search"){
$name=$_POST['username'];
$idnumber=$_POST['idnumber'];
$acctkind=$_POST['acctkind'];
$onstatus=$_POST['onstatus'];

if($acctkind == "Premium"){
$acctkind=1;
}
if($acctkind == "normal"){
$acctkind=0;
}
if($acctkind == "Doesn\'t Matter"){
$acctkind="";
}

if($onstatus == "Doesn\'t Matter"){
$query=mysql_query("select displayname,id from users where basicname LIKE '$name%' AND id LIKE '$idnumber%' AND acctkind LIKE '$acctkind%' ORDER BY id ASC")or die(mysql_error());
}

if($onstatus == "Online"){
$query=mysql_query("select displayname,id from users where basicname LIKE '$name%' AND id LIKE '$idnumber%' AND acctkind LIKE '$acctkind%' AND lli > (NOW() - INTERVAL 2 MINUTE)")or die(mysql_error());
}

if($onstatus == "Offline"){
$query=mysql_query("select displayname,id from users where basicname LIKE '$name%' AND id LIKE '$idnumber%' AND acctkind LIKE '$acctkind%' AND lli < (NOW() - INTERVAL 2 MINUTE)")or die(mysql_error());
}


$num=mysql_num_rows($query);
if($num == "0"){
print "No matches to your search query.";
include "footer.php";
exit;
}

while($thing=mysql_fetch_array($query)){
print "<a href='userprofiles.php?id=$thing[id]'>$thing[displayname]</a><br>";
}
include "footer.php";
exit;
}
?>





<form method=post action=searchusers.php?action=search>
Username: <input type=text name=username><br>
Player ID#: <input type=text name=idnumber><br>
Account Type: <select name=acctkind>
<option>Doesn't Matter</option>
<option>Premium</option>
<option>normal</option></select><br>
Online/Offline: <select name=onstatus>
<option>Doesn't Matter</option>
<option>Online</option>
<option>Offline</option>
</select><br>
<input type=submit name=submit value='Search Users'>
</form>



<?php
include "footer.php";
?>





Link to comment
Share on other sites

Okay, try this:

 

EDIT Don't try it yet...hold on.

EDIT AGAIN Okay, try it now.

 

<?php
include "header.php";

print "Searching usernames is searching all player's BASIC names, not their display names.<p>";

if ($_GET['action'] == "search") {
    $name=$_POST['username'];
    $idnumber=$_POST['idnumber'];
    $acctkind=$_POST['acctkind'];
    $onstatus=$_POST['onstatus'];
    
    if ($acctkind == "Premium") $acctkind=1;
    if ($acctkind == "normal") $acctkind=0;
    if ($acctkind == "Doesn\'t Matter") $acctkind="";
    
    if ($onstatus == "Doesn\'t Matter")
        $query= "select displayname,id from users where basicname LIKE '%$name%' AND id LIKE '%$idnumber%' 
        AND acctkind LIKE '%$acctkind%' ORDER BY id ASC";
    
    else if ($onstatus == "Online")
        $query= "select displayname,id from users where basicname LIKE '%$name%' AND id LIKE '%$idnumber%' 
        AND acctkind LIKE '%$acctkind%' AND lli > (NOW() - INTERVAL 2 MINUTE)";
    
    else if ($onstatus == "Offline")
        $query= "select displayname,id from users where basicname LIKE '%$name%' AND id LIKE '%$idnumber%' 
        AND acctkind LIKE '%$acctkind%' AND lli < (NOW() - INTERVAL 2 MINUTE)";
        
     $result = mysql_query($query)or die(mysql_error());
   
     
    $num = mysql_num_rows($result);
    
    if ($num == "0") {
        print "No matches to your search query.";
        include "footer.php";
        exit;
    }
    
    while ($thing = mysql_fetch_assoc($result)) {
        print "<a href='userprofiles.php?id={$thing['id']}'>{$thing['displayname']}</a><br>";
    }
    
    include "footer.php";
    exit;
}
?>


<form method="post" action="searchusers.php?action=search">
Username: <input type="text" name="username"><br>
Player ID#: <input type="text" name="idnumber"><br>
Account Type: <select name="acctkind">
<option>Doesn't Matter</option>
<option>Premium</option>
<option>normal</option></select><br>
Online/Offline: <select name="onstatus">
<option>Doesn't Matter</option>
<option>Online</option>
<option>Offline</option>
</select><br>
<input type="submit" name="submit" value="Search Users">
</form>



<?php
include "footer.php";
?>

Link to comment
Share on other sites

Okay, change this line

$result = mysql_query($query)or die(mysql_error());

 

To

$result = mysql_query($query)or die(mysql_error().$query);

 

Then copy and paste what it prints.

 

In all your queries you had

LIKE '$var%'

 

I looked up the syntax for LIKE and they had a percent sign on both sides of the variable...so I changed that. You might be able to do it with the one as well...you might want to change it to one just to make sure, and see if it works.

Link to comment
Share on other sites

It works that way too. Two percent signs makes it so it searches all user IDs with a "1" in them, while my way only brings up account IDs that START with 1.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1Resource id #6

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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