PHP - Moved: Sql Query Not Working Help Help!!
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=306850.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=332593.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=329559.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311010.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=344191.0 Im using the following query to pull all topics that have a new reply since the users last visit and where the user has posted within them. Code: [Select] $topic_query = $link->query("SELECT t.*, u.*, p.* FROM ".TBL_PREFIX."topics as t LEFT JOIN ".TBL_PREFIX."users as u ON (u.u_username = t.t_poster) LEFT JOIN ".TBL_PREFIX."posts as p ON (t.t_tid = p.p_tid) WHERE t.t_last_post_time > u.u_activity_time AND p.p_poster = '".$user->user_name."' GROUP BY t.t_tid ORDER BY t.t_sticky DESC, t.t_time_posted DESC LIMIT $start_page, $topics_to_show") or die(print_link_error()); for some reason though it still shows two topics that have a last post time which is less than that of the users activity time. The last_post_time for the topic is 1300309160 compare that with the users last activity time 1300784679 as you can see the last activity time is more than the last post time. there are no records in the database that are more than the last activity time so i shouldnt be getting any results. Anyone have any ideas? I am using a query to update the db when a user logs in. It sets every value correctly but it doesnt set the colum u_online which is INT(1). $link->query("UPDATE ".TBL_PREFIX."users SET u_last_login = '".$config['time_now']."', u_online = 1, u_ip = '".$_SERVER['REMOTE_ADDR']."', u_activity_time = '".$config['time_now']."', u_points = u_points + '$login_points' WHERE u_username = '$username'") or die(print_link_error()); when i echo the query: UPDATE asf_users SET u_last_login = '1300310822', u_online = 1, u_ip = '127.0.0.1', u_activity_time = '1300310822', u_points = u_points + '1' WHERE u_username = 'doddsey65' which works because i tried it in phpmyadmin and it changed the column. But it doesnt work in the actual script. It changes every other value that its supposed to but the u_online. Anyone have any ideas why? ok Im building a search page. The user can enter a name, county, category, address into my search field. The results page will show the details based on that. It works great so here is a snippet of the working code. $result = "-1"; if (isset($_POST['searchField'])) { $result = $_POST['searchField']; } $result = sprintf("SELECT Clubs.clubID, Clubs.name, Clubs.county, Clubs.logo, Clubs.postcode, Clubs.intro, Clubs.thumbsup, Clubs.cat, Category.*, County.*FROM Clubs INNER JOIN Category ON Clubs.cat = Category.catID INNER JOIN County ON Clubs.county = County.countyID WHERE ((Clubs.name Like %s) OR (Clubs.cat LIKE %s) OR (County.county LIKE %s) OR (Clubs.area LIKE %s) OR (Clubs.postcode LIKE %s) OR (Category.categorys LIKE %s)) " , String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text")); This code works great no matter what I enter. the problem Im having is I only want to show results based on the logged in users county. I have a variable stored under $user['county'] which is the ID found in the County table under countyID I have tried writing the code so many different ways. Here is my latest attemped but it doesnt work. It breaks the whole query and nothing is displayed. $result = "-1"; if (isset($_POST['searchField'])) { $result = $_POST['searchField']; } $County= "-1"; if (isset($user['county'])) { $County= $user['county']; } $result = sprintf("SELECT Clubs.clubID, Clubs.name, Clubs.county, Clubs.logo, Clubs.postcode, Clubs.intro, Clubs.thumbsup, Clubs.cat, Category.*, County.* FROM Clubs INNER JOIN Category ON Clubs.cat = Category.catID INNER JOIN County ON Clubs.county = County.countyID WHERE ((Clubs.name Like %s) OR (Clubs.cat LIKE %s) OR (County.county LIKE %s) OR (Clubs.area LIKE %s) OR (Clubs.postcode LIKE %s) OR (Category.categorys LIKE %s)) AND County.countyID = %s" , String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text"), String($result . "%", "text") String($County. "%", "int")); Thanks Danny Can someone review this piece of code and advise what's missing that's preventing the SQL query from working? Issue: no results being echoed out from $results. Note: I confirmed the db connection established (only the query not working - no results pulled from db and displayed via echo statements). $db = mysql_connect($host,$user,$pw) or die("Cannot connect to MySQL."); mysql_select_db($database,$db) or die("Cannot connect to database."); echo "Success! Connected to database ".$database."<br /><br />"; // $jsearch is variable sent in from form "title" name $jsearch = $_POST['jobsearch']; // I confirmed that all the field names are correct //-query the database table $sql="SELECT id,title,details,status FROM jobs WHERE title = '$jsearch';"; //-run the query against the mysql query function $result=mysql_query($sql) or die("<br>Query string: $result<br>Returned error: " . mysql_error() ); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $title =$row['title']; echo title."<br />"; $details=$row['details']; echo $details."<br />"; $status=$row['status']; echo $status."<br />"; $ID=$row['id']; Evening everybody, hoping someone can see my error here! $sql="INSERT INTO transactions (t_ref, m_affid, m_name, order_val, order_date, order_status, u_id, u_comm) VALUES('$t_ref', '$m_affid', '$m_name', '$order_val', '$order_date', '$order_status', '$u_id', '$u_comm')"; if (!mysql_query($sql)) { mysql_error(); } else { $newq = mysql_query("SELECT * FROM userbalance WHERE u_id = '$u_id'"); echo mysql_error(); $row = mysql_fetch_assoc($newq); $cpending = $row['pending']; $npending = $cpending + $u_comm; $updatepending = "INSERT into userbalance (pending) VALUES ('$npending') WHERE u_id = '$u_id'"; if (!mysql_query($updatepending)) { mysql_error(); } } Basically the 1st query works and inserts the data correctly, however once it gets to $newq = mysql_query("SELECT * FROM userbalance WHERE u_id = '$u_id'"); this query does not insert anything, no errors. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=358137.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=325846.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=326252.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306079.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=327525.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=347365.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319016.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348956.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=353002.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353189.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=334445.0 |