Jump to content

Recommended Posts

hi . am editting a code i have on a gallery script. so its has a download function for users and also a hits counter.

my hits counter and downloading code works perfect but am struggling with the while loop and how to get it so the link shows under each picture .

At present its showing the first picture then the download links for all 5 pictures that is displaying.

quick  pictorial example below as to what the output is .

[] <<< pic 1

link for pic 1

link for pic 2

link for pic 3

link for pic 4

link for pic 5

[] <<< pic 2

[] <<< pic 3

[] <<< pic 4

[] <<< pic 5

Thats what the page looks like . I do like to try to give you guys as much info as possible lol

 

if($action=="males")
{
  addonline(getuid_sid($sid),"Male Gallery","");
echo "<head>";
echo "<title>Gallery Pics</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
echo "</head>";
echo "<body>";
  
  echo "<p align=\"center\"><small>";
  echo "<i><b><u>Male Users From $sitename</u></b></i>";
  echo "<br/><br/>";
  echo "</small></p>";
   //////ALL LISTS SCRIPT <<
   $uid1 = getuid_sid($sid); 
$mid = $_GET["mid"];
    if($page=="" || $page<=0)$page=1;
    $noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM dave_usergallery WHERE sex='M'"));
$num_items = $noi[0]; //changable
    $items_per_page= 5;
    $num_pages = ceil($num_items/$items_per_page);
    if(($page>$num_pages)&&$page!=1)$page= $num_pages;
    $limit_start = ($page-1)*$items_per_page;
$sql = "SELECT uid, id, imageurl FROM dave_usergallery WHERE sex='M' ORDER BY id DESC LIMIT $limit_start, $items_per_page";
///////////////////// part of the added code also. 
$result = mysql_query($sql) or die("Error: " . mysql_error()); 
////
echo "<p>";
    $items = mysql_query($sql);
    echo mysql_error();
    if(mysql_num_rows($items)>0)
    {
    while ($item = mysql_fetch_array($items))
    {
        $sql = "SELECT rating FROM dave_usergallery_rating WHERE imageid='".$item[1]."'";        
        $imginfo = mysql_query($sql);
        echo mysql_error();
        if(mysql_num_rows($imginfo)>0)
        {
           while ($imginfos = mysql_fetch_array($imginfo)){ 
              $ratingtotal = $ratingtotal + $imginfos[0];}
        }
        if($totalcomments<1){$totalcomments=0;}         
        $norm = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM dave_usergallery_rating WHERE imageid='".$item[1]."'"));
        if ($norm[0]>0){
        $rating = ceil($ratingtotal/$norm[0]);
        }else{$rating=0;}
        $rated = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM dave_usergallery_rating WHERE byuid='".$uid1."' and imageid ='".$item[1]."'"));
        $totalcomments = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM dave_usergallery_rating WHERE imageid ='".$item[1]."' and commentsyn ='Y'"));
        $userinfo = mysql_fetch_array(mysql_query("SELECT name FROM dave_users WHERE id='".$item[0]."'"));
        echo "<a href=\"index.php?action=viewuser&who=$item[0]&sid=$sid\"><b><i><u>$userinfo[0]</u></i></b></a><small>";
        if(canratephoto($uid1, $item[0]) and ($rated[0]==0))
        {
         echo "<br/><a href=\"usergallery.php?action=rate&sid=$sid&whoimage=$item[1]\">Rate This Photo</a>";
        }
        if(ishost(getuid_sid($sid))||((isowner(getuid_sid($sid))||((isheadadmin(getuid_sid($sid)))))))
        {
         echo " / <a href=\"usergallery.php?action=del&sid=$sid&whoimage=$item[1]\">Del</a>";
        }
        if($uid1==$item[0])
        {
        echo " / <a href=\"usergallery.php?action=del&sid=$sid&whoimage=$item[1]\">Del</a>";
        }
         if($uid1==$item[0])
        {
         echo "<br/><a href=\"genproc.php?action=upavg&sid=$sid&avsrc=$item[2]\">Use As profile pic</a>";
        }
       
        echo "</small><br/><img src=\"$item[2]\" alt=\"$userinfo[0]\"/><br/>";
        echo "<small>Rating: $rating/10 (<a href=\"usergallery.php?action=votes&sid=$sid&whoimage=$item[1]\">$norm[0]</a> Votes)<br/><a href=\"usergallery.php?action=comments&sid=$sid&whoimage=$item[1]\">Comments</a>($totalcomments[0])";
        echo "</small><br/><a href=\"$item[2]\" alt=\"$userinfo[0]\"/>Download<br/>";
////////////////////////my problem part
while($row = mysql_fetch_array($result)){
echo "<br/><a href=\"getpics.php?file=$row[id]&sid=$sid\">Download test</a>";
<br/>";
}
////////////////////////
        echo "</small><br/><br/>";
        $ratingtotal = 0;
        
    }
    }
    
    echo "</p>";
    echo "<p align="center\">";
    if($page>1)
    {
      $ppage = $page-1;
      echo "<a href=\"usergallery.php?action=males&sid=$sid&page=$ppage\">«Prev</a> ";
    }
    if($page<$num_pages)
    {
      $npage = $page+1;
      echo "<a href=\"usergallery.php?action=males&sid=$sid&page=$npage\">Next»</a>";
    }
    echo "<br/>$page/$num_pages<br/>";
    if($num_pages>2)
    {
      $rets = "<form action=\"usergallery.php\" method=\"get\"><p align=\"center\">";
    
    $rets .= "<input name=\"page\" style=\"-wap-input-format: '*N'\" size=\"3\"/>";
    $rets .= "<input type=\"hidden\" name=\"sid\" value=\"$sid\"/>";
    $rets .= "<input type=\"hidden\" name=\"action\" value=\"$action\"/>";
    $rets .= "<input type=\"hidden\" name=\"view\" value=\"$view\"/>";
    $rets .= "<input type=\"Submit\" value=\"Go To Page\" Name=\"Submit\"/></form>";

        echo $rets;
    }
    echo "</p>"; 
  ////// UNTILL HERE >> 
    echo "<p align=\"center\">";
   echo "<br/><br/><a href=\"usergallery.php?action=main&sid=$sid\">«Back to Gallery</a><br/>";
    echo "<a href=\"index.php?action=main&sid=$sid\"><img src=\"images/home.gif\" alt=\"*\"/>";
echo "Home</a>";
  echo "</p>";
echo"</body>";
exit(); 

i have pointed out the bits i have added and tried to work it out.

 

i also appreciate the codings not that clean. am no coder this was given to me. but i can add bits here and there to things .

Its just am stuck on this  .

 

 

really hope u guys can help.

Link to comment
https://forums.phpfreaks.com/topic/246583-problem-with-while-loop/
Share on other sites

The issue seems to be caused by the double-query / double-loop thing you have going on. First you have the $sql variable which is being processed twice:

 

<?php
$sql = "SELECT uid, id, imageurl FROM dave_usergallery WHERE sex='M' ORDER BY id DESC LIMIT $limit_start, $items_per_page";
//...
$result = mysql_query($sql) or die("Error: " . mysql_error()); 
//...
$items = mysql_query($sql);
?>

 

 

Then you have two while loops, one to process $items and the other to process $result. The code should work fine if you just remove the second while loop. Try changing this:

 

<?php
echo "</small><br/><a href=\"$item[2]\" alt=\"$userinfo[0]\"/>Download<br/>";
while($row = mysql_fetch_array($result)){
     echo "<br/><a href=\"getpics.php?file=$row[id]&sid=$sid\">Download test</a>";
     echo "<br/>";
}
echo "</small><br/><br/>";
?>

 

 

To this (note that I changed $row to $item):

 

<?php
echo "</small><br/><a href=\"$item[2]\" alt=\"$userinfo[0]\"/>Download<br/>";
echo "<br/><a href=\"getpics.php?file=$item[id]&sid=$sid\">Download test</a>";
echo "<br/>";
echo "</small><br/><br/>";
?>

firstly thanks for your informative help.  posted this on 2 other forums also and just got negative comments. so thanks .

 

and secondly i resolved the problem without even using a loop. and i also changed $row to $item .

 

 

No problem, I totally understand the frustration of only receiving negative comments. Glad to hear that the issue was resolved. 8)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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