Quick php/sql question

Discussion in 'PHP' started by Funk-woo10, Oct 31, 2007.

  1. #1
    Hi,

    When I am using echo to display the result it gives only 1 'result', what i want is say 5 results.

    How could I do this ?

    Ta.
     
    Funk-woo10, Oct 31, 2007 IP
  2. Indian_Webmaster

    Indian_Webmaster Banned

    Messages:
    1,289
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #2
    from where these results coming?
     
    Indian_Webmaster, Oct 31, 2007 IP
  3. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?
    $numcomments=0;
    $nomember=false;
    $case=0;
    if(empty($username))
    {
    	$sql="select * from members,photos where members.username=photos.username and active=1 and approved='Y' ORDER BY DESC LIMIT 1";
    }
    else
    {
    	$sql="select * from members where username='$username' and active=1";
    	$case=1;
    }
    
    $res=mysql_query($sql);
    
    {
    	$username=$obj->username;
    
    }
    else
    {
    	$nomember=true;
    	$msg="No Pictures Exist!";
    	if($case==1)$msg="No member exists with that username";
    }
    if(!$nomember)
    {
    	$sql="select * from photos where username='$username' and approved='Y' order by upldate desc";
    	$res=mysql_query($sql);
    	$num=0;
    	if(mysql_num_rows($res)!=0)
    	{
    		$rnum=rand(0,mysql_num_rows($res)-1);
    	}
    	else
    	{
    		$nomember=true;
    		$msg="No Pictures Exist for that username!";
    	}
    
    	while($obj=mysql_fetch_object($res))
    	{
    		if($obj->url=="")
    		{
    			$dpic="<img border=0 width=100 height100 src='pics/$obj->filename'>";
    		}
    		else
    		{
    			$dpic="<img src='$obj->url'>";
    		}
    		if((empty($phid)&&($num==$rnum))||($phid==$obj->photosid))
    		{
    			$photoid=$obj->photosid;
    			$pic=$dpic;
    			$allpics=$allpics."<b>".($num+1)."</b>&nbsp;";
    
    		}
    		else
    		{
    			$allpics=$allpics."<a href='index.php?username=$username&phid=$obj->photosid'>".($num+1)."</a>&nbsp;";
    		}
    		$num++;
    	}
    }
    
    echo $dpic;
    
    ?>
    PHP:
     
    Funk-woo10, Oct 31, 2007 IP
  4. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #4
    well, for one if you check your SQL query it has LIMIT 1
     
    Lordy, Oct 31, 2007 IP
  5. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have change it 5 thats how many I want. And I just get 1 picture back. I want the last 5 uploaded arranged in a table
     
    Funk-woo10, Oct 31, 2007 IP
  6. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Any1 got any suggestions ? Kinda stuck here. ..
     
    Funk-woo10, Oct 31, 2007 IP
  7. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #7
    you have to put the echo $dpic into the while loop
     
    bobb1589, Oct 31, 2007 IP
  8. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #8
    What should I do I need the last 5 pics that have been uploaded display at the mo the echo $pic just gives me 1 pic
     
    Funk-woo10, Oct 31, 2007 IP
  9. 9450184

    9450184 Peon

    Messages:
    30
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    As bobb1589 said, you need to put the $dpic inside the while loop. To do so, put $dpic BEFORE $num++;

    echo $dpic;
    $num++;
     
    9450184, Nov 2, 2007 IP
  10. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #10
    OK, I have done this..BUT...I just get 1 result even when I LIMIT 5
     
    Funk-woo10, Nov 2, 2007 IP