Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2013, 04:59 PM   PM User | #1
Vernk
Regular Coder

 
Join Date: Oct 2011
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
Vernk is an unknown quantity at this point
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!
Vernk is offline   Reply With Quote
Old 01-30-2013, 05:14 PM   PM User | #2
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
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.
TFlan is offline   Reply With Quote
Old 01-30-2013, 05:16 PM   PM User | #3
Vernk
Regular Coder

 
Join Date: Oct 2011
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
Vernk is an unknown quantity at this point
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
Vernk is offline   Reply With Quote
Old 01-30-2013, 05:35 PM   PM User | #4
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
So then what's your question? You seem to already know the answer
TFlan is offline   Reply With Quote
Old 01-30-2013, 07:34 PM   PM User | #5
Vernk
Regular Coder

 
Join Date: Oct 2011
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
Vernk is an unknown quantity at this point
Yea but I don't know how to do it
Vernk is offline   Reply With Quote
Old 01-30-2013, 09:17 PM   PM User | #6
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
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..
TFlan is offline   Reply With Quote
Old 01-30-2013, 10:16 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,661
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
: 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
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-30-2013, 10:26 PM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,247
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:22 AM.


Advertisement
Log in to turn off these ads.