bluebyyou Posted July 2, 2007 Share Posted July 2, 2007 I am having trouble on my photo gallery. Users have the ability to comment on a picture. That works fine, the info is put into the DB no problem. however when the page is reloaded or refreshed the last entry does not show up until another comment is made, at which point the newest comment still doesnt show up. I am not ready to just give out a password for everyone to try it to help me trouble shoot(site not secure at all yet). So I would like to PM someone a username and password. Let me know if you would like to. (preferably someone with quite a few stars under thier name). Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/ Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 can u post ur code. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287715 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 I will post some of it, the whole page is kind of messy The form... <form name="addcomment" method="post" action="comment_action.php"> <input type="hidden" name="randnum" value="<?php echo $randnum; ?>"> <input type="hidden" name="picid" value="<?php echo $pictureid; ?>"> <input type="hidden" name="posterid" value="<?php echo $_SESSION['user']; ?>"> <input type="hidden" name="postername" value="<?php echo $_SESSION['fname']." ".$_SESSION['lname']; ?>"> <textarea name="text" cols="49" rows="4"></textarea><br><br> <input name="submitcomment" type="submit" value="submit"><br><br> </form> comment_action.php <?php include("db_connect.php"); $striptext = stripslashes(strip_tags($_POST['text'])); $finaltext = mysql_real_escape_string($striptext); $now = date("Y-m-d H:i:s"); $query = "INSERT INTO piccomment (picid,posterid,commentdatetime,postername,comment) VALUES ('$_POST[picid]','$_SESSION[user]','$now','$_POST[postername]','$finaltext')"; query_db($query); $getid = $_POST['picid']; header("location:pic.php?id=$getid"); ?> and heres the query that grabs from the db $query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 0,7 "; If the whole page would be more helpful let me know. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287721 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Do u have a unique id or primary key something like that for every entry to db. Then try this: $query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY id DESC LIMIT 7 "; OR: $query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 7 "; Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287724 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 yeah, there definately is a PK and I just tried that, It works the same without the 0 as well. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287725 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Did u try the code i mention above. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287726 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 Yes I did, sorry I put it in an edit. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287727 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Can i check with username and pass if u dont mind. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287730 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 PM sent, go to gallery, then click on a picture. You will be able to see and add comments there. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287735 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 I did not see any login page while clicking on it. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287741 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 Oh im sorry, its on the top right on the index page with a right pointing arrow next to it. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287743 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Why u use so dark colors while the bg is also dark. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287745 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 It must be showing much darker on your monitor, Im still working on the design, I will keep that in mind before I open it up to people. Were you able to find the login form? Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287747 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Yes i login and add comments. Can i ask where ur query for selecting goes. Is this in this page: pic.php Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287750 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 Did you notice that your second comment does not show up when the page is reloaded or refreshed? Yes it is on pic.php Here is the whole thing (pic.php) if that helps <?php session_start(); // START SESSION (MUST BE FIRST ON EVERY PAGE) include("header.php"); include("db_connect.php"); $strippicid = stripslashes(strip_tags($_GET['id'])); $getid = mysql_real_escape_string($strippicid); $query2 = "SELECT * FROM pic WHERE pictureid = '$getid'"; query_db2($query2); $row2 = mysql_fetch_array($result2); extract($row2); ?> <div id="gallerynav"> <a href="gallery.php"> Go back to the gallery </a> </div> <div id="gallery"> <div id="galfloatleft"> <h2><?php if ($picturetitle == ""){ echo "Untitled"; } else {echo $picturetitle;} ?></h2> </div> <div id="galfloatright"> <br> <a href="#">Prev</a> | <a href="#">Next</a> </div> </div> <div id="gallerynav"> <?php $query = "SELECT * FROM member WHERE memberid = '$pictureuserid'"; query_db($query); $row = mysql_fetch_array($result); extract($row); $timestamp = strtotime($picturedate); $format_date = date("F n",$timestamp); ?> <center> <table> <tr><td align="right">Photographer:</td><td align="left"><?php echo $fname." ".$lname; ?></td></tr> <tr><td align="right">Year:</td><td align="left"><?php echo $pictureyear; ?></td></tr> <tr><td align="right">Day:</td><td align="left"><?php echo $pictureday; ?></td></tr> <tr><td align="right">Date:</td><td align="left"><?php echo $format_date; ?></td></tr> <tr><td align="right">Location:</td><td align="left"><?php echo $picturelocation; ?></td></tr> <?php if ($picturetag != "") { $query = "SELECT * FROM member"; query_db($query); $row = mysql_fetch_array($result); ?> <tr><td colspan="2" align="center"><br /></td></tr> <tr><td colspan="2" align="center">In this photo:</td></tr> <tr><td colspan="2" align="center"> <?php $array = explode(",",$picturetag); foreach ($array as $name) { if (in_array($name,$row)) { $query2 = "SELECT fname,lname FROM member WHERE memberid = $name"; query_db2($query2); $row2 = mysql_fetch_array($result2); echo "<a href='profile.php?id=$name'>$row2[0] $row2[1]</a><br />"; } } }?> </td></tr> </table> </center> </div> <div id="gallery"> <img id="larger" src="<?php echo "uploads/$picturefile"; ?>"> </div> <? if ($_SESSION['auth'] == "yes"){ $randnum = rand(0,99999); ?> <div id="gallery"> <h3>Add a comment:</h3> <form name="addcomment" method="post" action="comment_action.php"> <input type="hidden" name="randnum" value="<?php echo $randnum; ?>"> <input type="hidden" name="picid" value="<?php echo $pictureid; ?>"> <input type="hidden" name="posterid" value="<?php echo $_SESSION['user']; ?>"> <input type="hidden" name="postername" value="<?php echo $_SESSION['fname']." ".$_SESSION['lname']; ?>"> <textarea name="text" cols="49" rows="4"></textarea><br><br> <input name="submitcomment" type="submit" value="submit"><br><br> </form> </div> <?php } ?> <?php $maxcomments = 6; if ($_GET['show'] == 1){$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC ";} if ($_GET['show'] != 1) {$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 7 ";} query_db($query); $num = mysql_num_rows($result); if ($num > 0){ ?> <div id="gallery"> <div id="galfloatleft"><h2>Comments</h2></div> <div id="galfloatright"> <?php if ($_GET['show'] != "1"){?> <br /><a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $pictureid; ?>&show=1">View All</a> <?php }else{ echo " ";}?> </div> <?php while ($row = mysql_fetch_array($result)) { extract($row); $timestamp = strtotime($commentdatetime); $showdate = date('F j', $timestamp); $showtime = date('g:i a', $timestamp); ?> <div id="comment"> <div id="commentpic"><img src="images/nopic.gif"></div> <div id='commenttext'> <h4><a href="profile.php?id=<?php echo $posterid; ?>"><?php echo $postername; ?></a> wrote: (on <?php echo $showdate; ?> at <?php echo $showtime; ?> )</h4> <p><?php echo $comment; ?></p> </div> </div> <?php } ?> </div> <?php } ?> <?php include("footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287751 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Yes i note it. Which mysql version u r using. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287753 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 4.1.22 Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287754 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Try this: if ($_GET['show'] == 1){$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY id DESC "; query_db($query);} if ($_GET['show'] != 1) {$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 7 ";} query_db($query); $num = mysql_num_rows($result); if ($num > 0){ Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287761 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 made that change, still having the same problem Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287765 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Do u have a id which is just for table to increment every time with code execution in db. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287767 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 yeah it is picindex...so i put this: f ($_GET['show'] == 1){$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY picindex DESC ";} if ($_GET['show'] != 1) {$query = "SELECT * FROM piccomment WHERE picid = '$pictureid' ORDER BY commentdatetime DESC LIMIT 7 ";} query_db($query); $num = mysql_num_rows($result); if ($num > 0){ Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287778 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 If u dont mind add a field in ur table like id and auto increment it in ur table not in coding to put by. And then use it as order by id desc limit 7. Hope this will help u. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287788 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 picindex is auto increment in the table and not in my code. Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287790 Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Just examining ur code can u tell me from where this $result is coming. $num = mysql_num_rows($result); Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287792 Share on other sites More sharing options...
bluebyyou Posted July 2, 2007 Author Share Posted July 2, 2007 db_connect.php is included on every page <?php $mysql_user = "******"; $host = "*******"; $password = "*******"; $db = "******"; $connection = mysql_connect($host,$mysql_user,$password) or die ("Couldn't connect to server."); $selectdb = mysql_select_db($db,$connection) or die ("Couldn't select Intern database."); function query_db($query) { global $result; $result = mysql_query($query) or die (mysql_error()); return $result; } function query_db2($query2) { global $result2; $result2 = mysql_query($query2) or die (mysql_error()); return $result2; } ?> Link to comment https://forums.phpfreaks.com/topic/58041-solved-data-from-database-lag/#findComment-287794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.