Two mysql arrays with limits on one page...
Moderator: General Moderators
-
polishvalor
- Forum Newbie
- Posts: 13
- Joined: Sat Nov 06, 2010 10:45 pm
Two mysql arrays with limits on one page...
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...
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Two mysql arrays with limits on one page...
If you paste the offending code you will probably get a solution much faster
I doubt telepaths hang out here 
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
polishvalor
- Forum Newbie
- Posts: 13
- Joined: Sat Nov 06, 2010 10:45 pm
Re: Two mysql arrays with limits on one page...
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...
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?
Otherwise I'm not sure I totally understand the problem, could you clarify it a bit please?
-
polishvalor
- Forum Newbie
- Posts: 13
- Joined: Sat Nov 06, 2010 10:45 pm
Re: Two mysql arrays with limits on one page...
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?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Two mysql arrays with limits on one page...
Change the second instance of $row to something like $num and see what happens. Where do you define this variable $blognumshortpublic?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
polishvalor
- Forum Newbie
- Posts: 13
- Joined: Sat Nov 06, 2010 10:45 pm
Re: Two mysql arrays with limits on one page...
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.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Two mysql arrays with limits on one page...
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:for some reason anything but $row does not work
Why did you redeclare it inside your script?polishvalor wrote:include.php which has the connects and deffinitions including $row=0
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
polishvalor
- Forum Newbie
- Posts: 13
- Joined: Sat Nov 06, 2010 10:45 pm
Re: Two mysql arrays with limits on one page...
** 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
Ok it works just forgot to rename all $rows to $nums. thanks
Last edited by polishvalor on Tue Jan 04, 2011 5:06 pm, edited 1 time in total.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Two mysql arrays with limits on one page...
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering