soccadude Posted August 27, 2009 Share Posted August 27, 2009 I have the file updatepage.php <?php session_start(); include ("config.php"); $user = $_SESSION['username']; $chk="SELECT `page` FROM `users` where `username`='$user'"; $check=@mysql_query($chk) or die (mysql_error()); if($currentpage < $check) { } else { $query="update `users` set `page`='$currentpage' where `username`='$user'"; $result=@mysql_query($query) or die(mysql_error()); ?> On each page, I have $currentpage = "(an integer starting from 0 and increasing by 1 each page)" What I'm trying to do is make it where if $currentpage <= page, it will do nothing. If it is not equal to that then it will update that entry in the table. -------------- Also, I have another code that I'm working on. I am trying to compare two tables. Table 1: id,username,password,page Table 2: id,page,actualpage I'm trying to have it check if page = page, then it will display actualpage. So far I have been unable to figure it out. Thanks for your time. Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/ Share on other sites More sharing options...
gaza165 Posted August 27, 2009 Share Posted August 27, 2009 I cant see where you have defined $current_page. Also try <?php session_start(); include ("config.php"); $user = $_SESSION['username']; $chk="SELECT `page` FROM `users` where `username`='$user'"; $check=@mysql_query($chk) or die (mysql_error()); $row = mysql_fetch_row($check); $currentpage = $row[0]; if($currentpage < $check) { } else { $query="update `users` set `page`='$currentpage' where `username`='$user'"; $result=@mysql_query($query) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907511 Share on other sites More sharing options...
soccadude Posted August 27, 2009 Author Share Posted August 27, 2009 I cant see where you have defined $current_page. Also try <?php session_start(); include ("config.php"); $user = $_SESSION['username']; $chk="SELECT `page` FROM `users` where `username`='$user'"; $check=@mysql_query($chk) or die (mysql_error()); $row = mysql_fetch_row($check); if($row[0] < $check) { } else { $query="update `users` set `page`='$currentpage' where `username`='$user'"; $result=@mysql_query($query) or die(mysql_error()); ?> I have $currentpage declared on each page that you visit. and it includes the updatepage.php file Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907512 Share on other sites More sharing options...
gaza165 Posted August 27, 2009 Share Posted August 27, 2009 <?php session_start(); include ("config.php"); $user = $_SESSION['username']; $chk="SELECT `page` FROM `users` where `username`='$user'"; $check=@mysql_query($chk) or die (mysql_error()); $row = mysql_fetch_row($check); if($currentpage < $row[0]) { } else { $query="update `users` set `page`='$currentpage' where `username`='$user'"; $result=@mysql_query($query) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907513 Share on other sites More sharing options...
soccadude Posted August 27, 2009 Author Share Posted August 27, 2009 Parse error: syntax error, unexpected $end Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907522 Share on other sites More sharing options...
gaza165 Posted August 27, 2009 Share Posted August 27, 2009 <?php session_start(); include ("config.php"); $user = $_SESSION['username']; $chk= mysql_query("SELECT `page` FROM `users` where `username`='$user'") or die(mysql_error()); $row = mysql_fetch_row($chk); if($currentpage < $row[0]) { } else { $query= mysql_query("update `users` set `page`='$currentpage' where `username`='$user'") or die(mysql_error()); } ?> try that... Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907524 Share on other sites More sharing options...
soccadude Posted August 27, 2009 Author Share Posted August 27, 2009 Success, thank you very much. Any chance you can help with the second part of my question? Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907527 Share on other sites More sharing options...
gaza165 Posted August 27, 2009 Share Posted August 27, 2009 You will need to explain in more detail so i can better understand what your trying to achieve. Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907528 Share on other sites More sharing options...
soccadude Posted August 27, 2009 Author Share Posted August 27, 2009 Alright, for the above coding that I was previously inquiring about. What it did was a user logged in. Went to various pages, it updated the page column for that user Page 1 wrote the integer 1 into the table Page 2 wrote the integer 2 into the table Page 3 wrote the integer 3 into the table, etc. Well now, I'm trying to make it where if the user is logged in. They can see the value of Page 3 (i.e. indexpage.html, or chapter1.html, or chaptertwo.html, etc.) In order to do this, I created another database with Id, Page, ActualPage Page from table 1 is supposed to be compared to Page from table 2. If they are equal, it displays ActualPage from table2 So if the user is on page 2(according to the database). When they login, I'll be able to display chapter1.html, or even create a link to it $actupage = mysql_query("SELECT `actualpage` FROM `pages` where `page`='$getlevel'") $url = "http://".$_SERVER['HTTP_HOST'].$getlevel echo "<a href=".$url;.">Click Here</a>"; Or something along those lines. Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907538 Share on other sites More sharing options...
gaza165 Posted August 27, 2009 Share Posted August 27, 2009 Ok Whats the name of your 2 tables?? my MSN is [email protected] if it is easier to talk through that?? You will need a JOIN to merge the two tables together and then do a comparison. Link to comment https://forums.phpfreaks.com/topic/172118-solved-sql-query-update/#findComment-907540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.