SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    For Loop using MS SQL and PHP

    Ok, I have a problem, here is my code:

    PHP Code:
                    <?
                    
    for ($num 1$num <= 5$num++)
                    {
                    
    ?>
                        <TR>
                            <TD WIDTH=500 ALIGN="LEFT" VALiGN="TOP">
                            <a name="section1"></a>
                            <FONT FACE="Arial" size=2 COLOR="#B50042"><b><?= $Row_c->section_heading[$num]?></b></font>
                            </TD>
                        </tr>
                        <tr>
                            <TD VALIGN="TOP">
                            <FONT FACE="Arial" size=2>
                            <?= $Row_c->section_content[$num?>
                            </FONT>
                            </TD>
                        </TR>
                        <tr>
                            <td>
                                <table WIDTH="100%" BORDER=0>
                                    <?
                                    $Query_i 
    = ("Select * from product_images WHERE language='$mode' AND title_url='$title_url' and section_number=$num");
                                    
    $Query_b = ("Select * from products_images_bubble WHERE language='$mode' AND title_url='$title_url' and section_number=$num");
                                    
    $Result_i=mssql_query($Query_i);
                                    
    $Result_b=mssql_query($Query_b);
                                    
    $Row_i mssql_fetch_object($Result_i);
                                    
    $Row_b mssql_fetch_object($Result_b);
                                    
    ?>
                                    <tr>
                                        <? if ($Row_i->image1){?>                                    
                                        <td  ALIGN="CENTER" width="30%"><IMG SRC="/images/<?= $Row_i->image1 ?>" ALT="<?= $Row_p->title_url ?>" BORDER=0>
                                        <br>
                                        <FONT FACE="Arial" size=1>
                                        <?= $Row_b->bubble1 ?>
                                        </font>
                                        </td>
                                        <?} if ($Row_i->image2){?>                                    
                                        <td  ALIGN="CENTER" width="30%"><IMG SRC="/images/<?= $Row_i->image2 ?>" ALT="<?= $Row_p->title_url ?>" BORDER=0>
                                        <br>
                                        <FONT FACE="Arial" size=1>
                                        <?= $Row_b->bubble2 ?>
                                        </font>
                                        </td>
                                        <?} if ($Row_i->image3){?>                                    
                                        <td  ALIGN="CENTER" width="30%"><IMG SRC="/images/<?= $Row_i->image3 ?>" ALT="<?= $Row_p->title_url ?>" BORDER=0>
                                        <br>
                                        <FONT FACE="Arial" size=1>
                                        <?= $Row_b->bubble3 ?>
                                        </font>
                                        </td>
                                        <?}?>
                                    </tr>
                                </table>                        
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><FONT FACE="Arial" size=2><a href="#TOP">Back to Top</a></font></td>
                        </tr>
                    <!-- Section1 End -->
                    <?
                    
    }
                    
    ?>
    Now my problem is that I keep getting error messages for these type of variable:

    PHP Code:
    <?= $Row_c->section_content[$num?>
    Is there a different way of adding on the $num section because I am using MS SQL. If I had a MySQL db, this code would work.

    Thanks.
    I have two tickets to the Crows, sweet.

  2. #2
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well...what kind of error messages are you getting ? cross post, btw... http://www.sitepointforums.com/showt...threadid=61854
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  3. #3
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the error I am getting:
    PHP Code:
    WarningUndefined property 
    And I know that it does exist in the database. Its just not recognising/accepting the variable with $num at the end of it!
    I have two tickets to the Crows, sweet.

  4. #4
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well...it could be this: bear in mind that array indices start at 0, not 1. try changing you for loop accordingly
    PHP Code:
    for ($num 0$num <= 4$num++) 
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  5. #5
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope I tried that, I think is something to do with the way I am declaring the variable

    PHP Code:
    <?= $Row_c->section_content[$num?>
    Anybody know another way of doing this?
    I have two tickets to the Crows, sweet.

  6. #6
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I saw that

    $Row_c->section_heading[$num]

    gives no error, while

    $Row_c->section_content[$num]

    yes.

    Php reports that "section_content" properties does not exists.
    I think that you have to check that section_content is a valid column or "column alias".
    You said that it exists ( that column ),
    so maybe you had not selected that column with your query.

    I think you have to check the query that you did to obtain $Row_c.

    ---
    hth
    Last edited by pippo; May 30, 2002 at 04:04.
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  7. #7
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope $Row_c is fine. I personally feel it has something to do with delaring variables using MS SQL. I think that until I come across some one who has actually done this, I will persist with my feeling that it is the whole MS SQL problem.

    Thanks for the advice.

    And pippo, are Italy going to win the world cup this year?
    I have two tickets to the Crows, sweet.

  8. #8
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    >>And pippo, are Italy going to win the world cup this year?

    eh eh, I hope so...I have a far memory of 1982...Go Italy but also Go Chievo too!

    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  9. #9
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think they have a great chance, and especially because everybody is talking about France and Argentina.

    Who are what is Chievo?
    I have two tickets to the Crows, sweet.

  10. #10
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chievo ( in local slang Ceo ) is the small quartier of Verona that has ranked the 5th position in our football championship.
    Last edited by pippo; May 30, 2002 at 05:13.
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


Bookmarks

Posting Permissions

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