php mysql results displaying one less record than in database

I am working on a cms app, where i give the end user the ability to create posts and then assign galleries to their posts.

In the page where they are uploading the images, the images are displayed using a select query, and at the same time the post related to the gallery is displayed and is non-editable [i take care of being able to edit the post in a separate process.]

Here is the problem, if the end user uploads 1 image, no images are displayed. If they upload a second image the first image is displayed, and so.

what could be the problem?

Check the code below -- it is the entire page which contains the select queries for displaying the article post, the images, and the form which calls "uploader.php" [the script that uploads and writes the image data into the db].

thank you in advance for any help.
Jason


<?php
require_once('auth.php');
include('../includes/conn_mysql.inc.php');
include('../includes/corefuncs.php');
$conn = dbConnect('query');
$siteid = mysql_real_escape_string($_GET['pageid']);
$imgarticleid = mysql_real_escape_string($_GET['articleid']);
$articleid = mysql_real_escape_string($_GET['articleid']);
$sql = "SELECT pageid, pagename, url FROM pages ORDER BY pagename";
$result = mysql_query($sql) or die(mysql_error());
$sql3 = "SELECT pageid, pagename, url FROM pages WHERE pageid='".$siteid."' LIMIT 1";
$conn = dbConnect('admin');

	$sqlimgselect = "SELECT galleryimgs.imgid, galleryimgs.articleid AS imgarticleid, galleryimgs.title, galleryimgs.img FROM galleryimgs WHERE articleid='".$imgarticleid."' "; //WHERE articleid='".$imgarticleid."'
  	$resultimgselect = mysql_query($sqlimgselect) or die (mysql_error());
  	$rowimgselect = mysql_fetch_assoc($resultimgselect);
	
// get details of selected record

//if ($_GET && !$_POST) {
  //if (isset($_GET['articleid']) && is_numeric($_GET['articleid'])) {
    //$articleid = $_GET['articleid'];
	//}
 // else {
  //  $articleid = NULL;
//	}
 // if ($articleid) {
    //$sql = "SELECT * FROM annualdinnerpage WHERE article_id = $article_id"; //create join with annualdinnergalleryimgs
	//$sqlselect = "SELECT articles.*, galleryimgs.articleid AS imgarticleid, galleryimgs.img, galleryimgs.title AS imgtitle 
	//FROM articles LEFT JOIN galleryimgs ON articles.articleid = galleryimgs.articleid
	//WHERE galleryimgs.articleid='".$imgarticleid."' AND articles.articleid='".$imgarticleid."' ";
	//ORDER BY imgarticleid "; //create join with galleryimgs
	$sqlarticle = "SELECT  articles.* FROM articles WHERE articleid='".$articleid."' ";
  $resultarticle = mysql_query($sqlarticle) or die (mysql_error());
  $rowarticle = mysql_fetch_assoc($resultarticle);
//	}
 // }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CMS Gallery</title>
<link href="journal.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="../images/bsoc_icon.ico" />
<?php // include('xinha.inc.php'); ?>
</head>

<body>
<div id="navigation">
<?php
$result3 = mysql_query($sql3) or die(mysql_error());
if($row=mysql_fetch_assoc($result3)){
 echo "<h1>".$row['pagename']." Gallery</h1>";
}
?>
<?php include('includes/topnav.inc.php'); ?>
</div>
<div id="contentwrapper">
<div id="content">
<div id="contentleft">
<?php include('includes/menunav.inc.php'); ?>
</div>
<div id="contentright">
<?php echo $rowarticle['article'] ?>
<br />

<form id="form1" name="form1" method="post" action="uploader.php?articleid=<?php echo $articleid; ?>&pageid=<?php echo $siteid; ?>" enctype="multipart/form-data">
        <table>
        <tr>
        <td>Title</td>
        <td>Path</td>
        <td>Upload</td>
        </tr>
        <tr>
        <!--<input type="hidden" name="MAX_FILE_SIZE" value="100000" />-->
        <input type="hidden" name="articleid" id="articleid" value="<?php echo $rowarticle['articleid']; ?>" />
        <td><input type="text" name="title" id="title" /></td>
        <td><input type="file" name="uploadedfile" id="uploadedfile" /></td>
        <td><input type="submit" name="insert" value="Upload File" /></td>
        </tr>
        </table>
</form>
<br />
	
    <?php
	while($rowimgselect = mysql_fetch_assoc($resultimgselect)) {
	?>
    <img src="uploads/thumbs/<?php echo $rowimgselect['img']; ?>" alt="<?php echo $rowimgselect['title']; ?>" title="<?php echo $rowimgselect['title']; ?>" />
	<?php } ?>


<div class="push"></div>
</div>
<hr class="cleaner" />
</div>
</div>
</body>
</html>

Open in new window

jsvb1977Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jsvb1977Author Commented:
oh yeah -- sorry about all the commented code - i have been experimenting to figure this out.

Jason
0
phpsalesCommented:
The PHP mysql_fetch_assoc module will increment the row pointer in the MySQL result set each time it's called. Looks like you fetch an associate array for the first row then loop threw the rest of the rows further down.

Comment out line # 16 if you don't need the first row:

$rowimgselect = mysql_fetch_assoc($resultimgselect);

OR, Add the following before line # 88:

mysql_data_seek($resultimgselect,0);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jsvb1977Author Commented:
I went with solution number two -- thank you for the explanation as well. Much appreciated.
Jason
0
jsvb1977Author Commented:
I went with solution number two -- thank you for the explanation as well. Much appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.