CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Help with MySQL / PHP problem (http://www.codingforums.com/showthread.php?t=286744)

Vernk 01-30-2013 04:59 PM

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!

TFlan 01-30-2013 05:14 PM

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.

Vernk 01-30-2013 05:16 PM

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

TFlan 01-30-2013 05:35 PM

So then what's your question? You seem to already know the answer

Vernk 01-30-2013 07:34 PM

Yea but I don't know how to do it

TFlan 01-30-2013 09:17 PM

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

Fou-Lu 01-30-2013 10:16 PM

: 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


Old Pedant 01-30-2013 10:26 PM

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.


All times are GMT +1. The time now is 08:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.