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 11-12-2007, 03:34 PM   PM User | #1
psykx
New Coder

 
Join Date: Apr 2007
Posts: 89
Thanks: 1
Thanked 2 Times in 2 Posts
psykx has a little shameless behaviour in the past
Comparing a variable against an array and outputting data from a directly proportiona

Comparing a variable against an array and outputting data from a directly proportional array I can't see why the code isn't working. I have tried echoing variables at almost all stages but I can't get my head around it.

This code populates the arrays.
PHP Code:
$sqlquery "SELECT forum_name, forum_id FROM phpbb_forums";
$result $db->sql_query($sqlquery);
$f_num 0;
$forumid = array();
$forumname = array();
   while ( (
$row $db->sql_fetchrow($result)))
    {
    
$forumid[$f_num] = $row["forum_id"];
    
$forumname[$f_num] = $row["forum_name"];
    ++
$f_num;
    }
$db->sql_freeresult($result); 
then another query is performed which is most of the output is generated. then this is the code that I'm having problems with

PHP Code:
            while ( $f_num )
            {
                if ( 
$row["forum_id"] == $forumid[$f_num] )
                {
                   
$f_name $forumname[$f_num];
                   
$f_id_num $f_num;
                }
                
$f_num--;
            } 
This code needs to replace $row['forum_id'] with the correct variable from the $forumname[] array each time "while ( ($row = $db->sql_fetchrow($result)))" runs.
psykx is offline   Reply With Quote
Old 11-12-2007, 07:19 PM   PM User | #2
phpBuddy
New Coder

 
Join Date: Nov 2007
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
phpBuddy is an unknown quantity at this point
in the first case $f_num is 0-5
in the second case $f_num is 5->1. Not = 0.

In my code below,
when $f_count is = 5, the indexes will be:
0,1,2,3,4
PHP Code:
<?php

// a new variable, that holds number of forumid
$f_count count($forumid);

$f_num 0;
while ( 
$f_num $f_count )
            {
                if ( 
$row["forum_id"] == $forumid[$f_num] )
                {
                   
$f_name $forumname[$f_num];
                   
$f_id_num $f_num;
                }
                
$f_num++;
            }

?>
__________________
echo "PHP 5.2.5";
exit ( "Script End" );
phpBuddy is offline   Reply With Quote
Old 11-13-2007, 01:02 AM   PM User | #3
psykx
New Coder

 
Join Date: Apr 2007
Posts: 89
Thanks: 1
Thanked 2 Times in 2 Posts
psykx has a little shameless behaviour in the past
a shorter way of doing the same is
PHP Code:
while ( $f_num >= )
{
etc...

this was part of the problem, cheers the next bit is going to be to get the while loop to change a different variable leaving $f_num intact for the next row.
psykx 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 06:38 PM.


Advertisement
Log in to turn off these ads.