Page 1 of 1
Two mysql arrays with limits on one page...
Posted: Tue Dec 28, 2010 4:42 pm
by polishvalor
Seems to conflict with each other. Information from two different tables on the same database with two different limits, 5 and 3. The limit 3 information(blog) is executed first. The 5 limit(uploads) is executed afterwards. Here's the problem, blog shows up fine with proper information and limit. Uploads...well it seems to count off the first 3 items, not display them, and then display the remaining two. this only occurs on main blog page. can anyone offer some insight on how to fix this...
Re: Two mysql arrays with limits on one page...
Posted: Wed Dec 29, 2010 8:15 am
by social_experiment
If you paste the offending code you will probably get a solution much faster

I doubt telepaths hang out here

Re: Two mysql arrays with limits on one page...
Posted: Mon Jan 03, 2011 7:56 pm
by polishvalor
whoops sorry i've been on vacation. it's quite a bit of code here...and it may be messy
Code: Select all
// CONNECT STUFF UP HERE
$blogshortmembers = mysql_query("SELECT * FROM blog WHERE category='members' ORDER by blogId DESC LIMIT 3");
$blognumshortmembers = mysql_num_rows($blogshortmembers);
$blogrowshortmembers = mysql_fetch_array($blogshortmembers);
$uploadshort = mysql_query("SELECT * FROM uploads ORDER by id DESC LIMIT 5");
$uploadshortnum = mysql_num_rows($uploadshort);
$uploadshortrow = mysql_fetch_array($uploadshort);
$row=0;
<?php
while($row<$uploadshortnum)
{
$user=mysql_result($uploadshort,$row,"user");
$date=mysql_result($uploadshort,$row,"date");
$type=mysql_result($uploadshort,$row,"type");
$filename=mysql_result($uploadshort,$row,"filename");
?>
<body>
<p id="title"><a href="http://www.site.com/uploads/<?php echo $filename; ?>"><?php echo $filename; ?></a></p>
<?php
$row++;
}
?>
<p align=right>
<a href="http://www.sitecom/uploads.php">view uploads >></a>
</p>
<?php
while($row<$blognumshortpublic)
{
$title=mysql_result($blogshortpublic,$row,"title");
$date=mysql_result($blogshortpublic,$row,"date");
$editdate=mysql_result($blogshortpublic,$row,"editdate");
$content=mysql_result($blogshortpublic,$row,"content");
$poster=mysql_result($blogshortpublic,$row,"poster");
$blogId=mysql_result($blogshortpublic,$row,"blogId");
?>
<body>
<p id="title"><a href="http://www.site.com/viewblog.php?blogId=<?php echo $blogId; ?>"><?php echo $title; ?></a></p>
<p id="date"><?php echo $date; ?></p>
<?php if($editdate != ' '){ ?>
<p id="edit">last edited on: <?php echo $editdate; ?></p>
<?php } ?>
<p id="content"><?php echo $content; ?></p>
<!-- if logged in user posted this, then show edit/delete -->
<?php if($lia == $poster || $userlevel == "2"){ ?>
<p id="delete"><a href="http://www.site.com/editblog.php?blogId=<?php echo $blogId; ?>">edit</a>
<a href="http://www.site.com/delete.php?blogId=<?php echo $blogId; ?>">delete</a></p><?php } ?>
<br />
<?php
$row++;
}
?>
<p align=right>
<a href="http://www.site.com/blogs.php">view more blogs >></a>
</p>
Re: Two mysql arrays with limits on one page...
Posted: Mon Jan 03, 2011 9:12 pm
by Neilos
Just quickly looked at this and it looks like you define some php variables outside of php tags, is there a reason for that.
Otherwise I'm not sure I totally understand the problem, could you clarify it a bit please?
Re: Two mysql arrays with limits on one page...
Posted: Mon Jan 03, 2011 11:22 pm
by polishvalor
no thats just a bunch of files crunched into a small single file. blogshort, most recent blogs, has a limit of 3 and upload short has a limit of 5, most recent uploads. the blogs come out okay, but the first 3 uploads are omitted and only the next 2 are displayed on this page. any ideas?
Re: Two mysql arrays with limits on one page...
Posted: Tue Jan 04, 2011 2:48 am
by social_experiment
Change the second instance of $row to something like $num and see what happens. Where do you define this variable $blognumshortpublic?
Re: Two mysql arrays with limits on one page...
Posted: Tue Jan 04, 2011 3:59 pm
by polishvalor
for some reason anything but $row does not work. >.< any other suggestions? i have it written in 3 files: include.php which has the connects and deffinitions including $row=0. then i have the memberblog.php and then side.php. these are all included in the page using the include() function.
Re: Two mysql arrays with limits on one page...
Posted: Tue Jan 04, 2011 4:10 pm
by social_experiment
polishvalor wrote:for some reason anything but $row does not work
It won't if you don't innitialize the new variable first. If you use $num, you have to assign $num a value of 0 somewhere.
polishvalor wrote:include.php which has the connects and deffinitions including $row=0
Why did you redeclare it inside your script?
Re: Two mysql arrays with limits on one page...
Posted: Tue Jan 04, 2011 4:39 pm
by polishvalor
** to clarify this is NOT the actual script just copied from different sources and repasted. and lol i do know that it's just no other variable besides $row will work, i don't know if this is just a var that the program itself recognizes...
Ok it works just forgot to rename all $rows to $nums. thanks
Re: Two mysql arrays with limits on one page...
Posted: Tue Jan 04, 2011 4:50 pm
by social_experiment

Strange but it might be true. I think it's probably where you should start looking at the problem. Good luck with it
