Jump to content

help with query.


seany123

Recommended Posts

can some help me turn this query so it only selects `status`='read' and `status`='unread'.

 

//Get all log messages ordered by status

$query = $db->execute("select `msg`, `status` from `user_log` where `player_id`=? order by `status` desc", array($player->id));

 

thanks

Link to comment
Share on other sites

$query = $db->execute("select `msg`, `status` from `user_log` where `player_id`=? AND `status` = 'unread' AND `status` = 'read' order by `status` desc", array($player->id));

You should post SQL questions in the SQL forum.

Link to comment
Share on other sites

$query = $db->execute("select `msg`, `status` from `user_log` where `player_id`=? AND `status` = 'unread' AND `status` = 'read' order by `status` desc", array($player->id));

You should post SQL questions in the SQL forum.

 

yeah im sorry, it seemed to work here though ;)

 

 

ill give it a try thanks

Link to comment
Share on other sites

If im not mistaken but status cannot equal read and unread at the same time. Your query should be

$query = $db->execute("select `msg`, `status` from `user_log` where AND `player_id`=? AND `status` = 'read' OR `status` = 'unread' order by `status` desc", array($player->id));

 

Link to comment
Share on other sites

okay i now tested this out but got a error...

 

Fatal error: Call to a member function on a non-object on line 31

 

 

line 31 is...

 

if ($query->recordcount() > 0)

 

 

 

this is the entire page..

 

<?php
include("lib.php");
define("PAGENAME", "Log");
$player = check_user($secret_key, $db);

include("templates/private_header3.php");

if ($_GET['act'] == "clear")
{
    //Clear all log messages for current user
    $query = $db->execute("update `user_log` set `status`='deleted' where `player_id`=? and `status`='read' or `status`='unread'", array($player->id));
}

//Get all log messages ordered by status
$query = $db->execute("select `msg`, `status` from `user_log` where AND `player_id`=? AND `status` = 'read' OR `status` = 'unread' order by `status` desc", array($player->id));

//Update the status of the messages because now they have been read
$query2 = $db->execute("update `user_log` set `status`='read' where `player_id`=? and `status`='unread'", array($player->id));
?>
      
<html>
<head>
<title>Mafiakiller</title>
<link rel="stylesheet" href="/css/style.css" type="text/css" media="all" />
</head>
<body alink="#cc9900" vlink="#cc9900" link="#cc9900">
<div id="holder">
<div id="left_c"><div class="g_content"><h3>  Events</h3><div class="g_text"><table width='100%'>

<?php
if ($query->recordcount() > 0)
{
    echo "<a href=\"log.php?act=clear\">Clear log</a>";
    while ($log = $query->fetchrow())
    {
        echo "<fieldset>\n";
        echo "<legend>";
        echo ($log['status']=="unread")?"<b>" . ucwords($log['status']) .   "</b>":ucwords($log['status']);
        echo "</legend>\n";
        echo $log['msg'] . "\n";
        echo "</fieldset>\n<br />\n";
    }
}
else
{
    echo "No log messages!";
}

?>
</div>
</div>
</div>
</div>
</body>
</html>    

Link to comment
Share on other sites

well this worked fine when i had...

 

 

<?php
if ($_GET['act'] == "clear")
{
    //Clear all log messages for current user
    $query = $db->execute("delete from `user_log` where `player_id`=?", array($player->id));
}

//Get all log messages ordered by status
$query = $db->execute("select `msg`, `status` from `user_log` where `player_id`=? order by `status` desc", array($player->id));

 

but now ives changed it to this its not working and giving that error.

 

<?php
if ($_GET['act'] == "clear")
{
    //Clear all log messages for current user
    $query = $db->execute("update `user_log` set `status`='deleted' where `player_id`=? and `status`='read' or `status`='unread'", array($player->id));
}

//Get all log messages ordered by status
$query = $db->execute("select `msg`, `status` from `user_log` where AND `player_id`=? AND `status` = 'read' OR `status` = 'unread' order by `status` desc", array($player->id));

Link to comment
Share on other sites

 

do you mean this?

 

 

//Insert a log message into the user logs
function addlog($id, $msg, &$db)
{
$insert['player_id'] = $id;
$insert['msg'] = $msg;
$insert['time'] = time();
$query = $db->autoexecute('user_log', $insert, 'INSERT');
}

Link to comment
Share on other sites

The function should be in a class. See if you can find a line like: $db = new something(); That something is the class name. Open up the file with that class and find the function query. Then post it here.

 

You'll have to find all that on your own.

Link to comment
Share on other sites

this...

 

 

$db = &ADONewConnection('mysql'); //Connect to database

$db->Connect($config_server, $config_username, $config_password, $config_database); //Select table

 

$db->SetFetchMode(ADODB_FETCH_ASSOC); //Fetch associative arrays

$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; //Fetch associative arrays

//$db->debug = true; //Debug

 

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.