Jump to content

[SOLVED] data from database lag


bluebyyou

Recommended Posts

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

  • Replies 52
  • Created
  • Last Reply

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.

 

 

 

 

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 ";

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 "&nbsp";}?>
</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");
?>

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){

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){

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;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.