Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post

    Help with MySQL / PHP problem

    Hello,

    I have come across a problem that I believe that I need to use a for loop but I don't know how to use it here.

    Here is the code:

    PHP Code:
                    $q60 mysql_query("SELECT VotingSiteType FROM votingsite WHERE CheckedForVoting=1 AND userid='$uid'");
                            
    $q61 mysql_fetch_array($q60);
                            
    $usid3 $q61['VotingSiteType'];
                            
                            
    $q1 mysql_query("SELECT * FROM site_statuses WHERE id='$usid3'");
                            while (
    $q1d mysql_fetch_array($q1)) {
                            
                            
                            
    $status $q1d['status'];
                            if (
    $status == 1) { $input ' class="i-16-sonline"'$txt 'Working'; } 
                            if (
    $status == 3) { $input ' class="i-16-soffline"'$txt 'Broken'; } 
                            if (
    $status == 2) { $input ' class="i-16-smaintain"'$txt 'Maintainence'; } 
                            echo 
    '<a href="/panel-vote&id='.$q1d['id'].'" rel="tooltip-top" original-title="'.$txt.'"><li'.$input.'>'.$q1d['site'].'</li></a>
                                
                            '
    ;
                            } 
    The output is only 1 list of the site, instead there should be seven. The problem consists here.

    PHP Code:
    $q60 mysql_query("SELECT VotingSiteType FROM votingsite WHERE CheckedForVoting=1 AND userid='$uid'");
                            
    $q61 mysql_fetch_array($q60);
                            
    $usid3 $q61['VotingSiteType'];
                            
                            
    $q1 mysql_query("SELECT * FROM site_statuses WHERE id='$usid3'");
                            while (
    $q1d mysql_fetch_array($q1)) { 
    Instead of it just being like that it should get all the values not just the first one... I don't know how to explain it well but please help as much as you can.

    Thanks!

  • #2
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    Can you do a var_dump of the results?

    If the var_dump only shows 1 result, then it is a problem within your query statement or you don't have your data set right in your database.

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    Yea, no. The problem is the fetch_array is suppose to fetch more then 1 row. But It doesn't since there is no loop for it

  • #4
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    So then what's your question? You seem to already know the answer

  • #5
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    Yea but I don't know how to do it

  • #6
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    Ah! I understand what you're asking..

    PHP Code:
    $q60 mysql_query("SELECT `VotingSiteType` FROM `votingsite` WHERE `CheckedForVoting` = 1 AND `userid` = '".$uid."'"); 
    while(
    $q61 mysql_fetch_array($q60)){
        
    $usid3 $q61['VotingSiteType']; 

        
    $q1 mysql_query("SELECT * FROM `site_statuses` WHERE `id` = '".$usid3."'"); 
        while(
    $q1d mysql_fetch_array($q1)){
            
    $status $q1d['status'];
            switch(
    $status){
                case 
    1:
                    
    $input    ' class="i-16-sonline"';
                    
    $txt      'Working';
                break;
                case 
    2:
                    
    $input    ' class="i-16-smaintain"';
                    
    $txt      'Maintainence';
                break;
                case 
    3:
                    
    $input    ' class="i-16-soffline"';
                    
    $txt      'Broken';
                break;
            }
            echo 
    '<a href="/panel-vote&id='.$q1d['id'].'" rel="tooltip-top" original-title="'.$txt.'"><li'.$input.'>'.$q1d['site'].'</li></a>';
        }

    Maybe I understand what you're asking...
    Last edited by TFlan; 01-30-2013 at 09:20 PM.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    : squint :
    Why you have two queries there?
    Code:
    SELECT ss.status, ss.id, ss.site
    FROM site_status ss
    RIGHT JOIN votingsite v ON v.VotingSiteType = ss.id
    WHERE v.CheckedForVoting = 1 AND v.userid = $uid
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    I don't think he wants a RIGHT JOIN there.

    I think just an INNER JOIN.

    If you look at his while loop on the votingsite records, the only thing he does with it is get and ID to be used in the inside while loop. So he doesn't really care about any values from the votingsite table.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •