seany123 Posted May 2, 2009 Share Posted May 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824384 Share on other sites More sharing options...
vicodin Posted May 2, 2009 Share Posted May 2, 2009 This should do it. $query = $db->execute("select `msg`, `status` from `user_log` where `status` = 'read' AND `status` = 'unread' AND `player_id`=? order by `status` desc", array($player->id)); Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824388 Share on other sites More sharing options...
seany123 Posted May 2, 2009 Author Share Posted May 2, 2009 $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 Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824390 Share on other sites More sharing options...
wildteen88 Posted May 2, 2009 Share Posted May 2, 2009 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)); Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824392 Share on other sites More sharing options...
seany123 Posted May 2, 2009 Author Share Posted May 2, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824399 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 I think you meant to say: mysql_num_rows($query)? I don't know what datatype your $db->execute() function returns. Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824409 Share on other sites More sharing options...
seany123 Posted May 2, 2009 Author Share Posted May 2, 2009 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)); Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824414 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Can you post what this outputs? var_dump($query); Put that line before the - if ($query->readcount() > 0) Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824418 Share on other sites More sharing options...
seany123 Posted May 2, 2009 Author Share Posted May 2, 2009 i just got: bool(false) Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824426 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Mind posting your db execute function here? Problem is $query is a boolean, not an object so you can't call $query->readcount() Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824431 Share on other sites More sharing options...
seany123 Posted May 2, 2009 Author Share Posted May 2, 2009 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'); } Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824441 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824447 Share on other sites More sharing options...
seany123 Posted May 2, 2009 Author Share Posted May 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824454 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 Can you post the query method that's in ADONewConnection? Quote Link to comment https://forums.phpfreaks.com/topic/156571-help-with-query/#findComment-824687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.