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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question if then elseif - who knows?

    Can't get this to work, been searching for hours can't get a fix!
    I would like to display the images that are in different folders using the same table,
    Is this possible?

    Playing with this code but can't think anymore.
    PHP Code:
    <?php
    if ($row_rsimage['choice'] == "left") {
    ?>
        <img src="../uploads/left/<?php echo $row_rsimage['imagename']; ?>" alt="">
    <?php
    } elseif ($row_rsimage['choice'] == "right") {
    ?>
        <img src="../uploads/right/<?php echo $row_rsimage['imagename']; ?>" alt="">
    <?php
    } else {
        
    //think about becoming rich one day...
    }
    ?>
    Any ideas?

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    The code you show should be working.

  • #3
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Yes,
    but for some odd reason I only get two images displayed?

  • #4
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If your problem is the number of images then it is obviously the WHILE loop you didn't post...

  • #5
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    I've got this:

    Code:
    <?php do { ?>
    
    the code
    
    <?php } while ($row_rsimage = mysql_fetch_assoc($rsimage)); ?>

  • #6
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    ...if you didn't catch my hint I meant post the WHOLE code

    Also, use a WHILE loop not a DO WHILE.

    So instead of
    PHP Code:
    <?php do { ?>

    the code

    <?php } while ($row_rsimage mysql_fetch_assoc($rsimage)); ?>
    Do

    PHP Code:
    <?php while ($row_rsimage mysql_fetch_assoc($rsimage)) { ?>

    the code

    <?php ?>

  • #7
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    WTF is up with all these innappropriately used do-while loops? Do people even comprehend the difference between while and do-while?

  • #8
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Cool,
    will try it now with your method.

    Doesn't work - still shows 2 images with one red X
    Before it showed 2 images and another 2 with red X's
    Last edited by student101; 02-14-2008 at 09:45 PM.

  • #9
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    My method probably won't solve it, just that it will solve potential problems and it is the correct method to loop through mysql_fetch arrays.

  • #10
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    What is the best method here?
    I have tried to create two seperate tables from the same the table and I get the same results.

    "rsright" and "rsleft" with the same select statement but no luck.

  • #11
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Man I'm trying to be nice here but understand you need to post the whole code INCLUDING the frigging SELECT statement.

    Jeepers...

  • #12
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Left out HTML parts.

    PHP Code:
    mysql_select_db($database_cnevents, $cnevents);
    $query_rsimage = "SELECT * FROM homeimage ORDER BY sortorder ASC";
    $rsimage = mysql_query($query_rsimage, $cnevents) or die(mysql_error());
    $row_rsimage = mysql_fetch_assoc($rsimage);
    $totalRows_rsimage = mysql_num_rows($rsimage);


    <table width="380" border="0" cellpadding="0" cellspacing="2" class="normaltext">
      <tr>
        <td><strong>Image</strong></td>
        <td><strong>Sort</strong></td>
        <td><strong>Side</strong></td>
        <td><strong>Delete</strong></td>
      </tr>
      <?php do { ?>
        <tr>
          <td><?php
    if ($row_rsimage['choice'] == "left") {
    ?>
              <img src="../uploads/left/<?php echo $row_rsimage['imagename']; ?>" alt="">
              <?php
    } elseif ($row_rsimage['choice'] == "right") {
    ?>
              <img src="../uploads/right/<?php echo $row_rsimage['imagename']; ?>" alt="">
              <?php
    } else {
        
    //do nothing
    }
    ?>
          </td>
          <td><?php echo $row_rsimage['sortorder']; ?></td>
          <td><?php echo $row_rsimage['choice']; ?></td>
          <td>[<a href="topimagedel.php?imgid=<?php echo $row_rsimage['imgid']; ?>" onClick="tmt_confirm('Are%20you%20sure%20you%20want%20to%20DELETE%20this%20record?');return document.MM_returnValue"><font color="#FF0000"><strong>DELETE</strong></font></a>]</td>
        </tr>
        <?php } while ($row_rsimage mysql_fetch_assoc($rsimage)); ?>
    </table>

  • #13
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    I have even tried replacing these parts from the database
    Code:
    <img src="../uploads/left/<?php echo $row_rsimage['imagename']; ?>" alt="">
    Like this
    Code:
    <img src="../uploads/<?php echo $row_rsimage['choice']; ?>/<?php echo $row_rsimage['imagename']; ?>" alt="">

  • #14
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Get rid of this line
    PHP Code:
    $row_rsimage mysql_fetch_assoc($rsimage); 
    Also, change from a DO WHILE loop to a WHILE loop as I explained in my earlier post.

    If neither of those work then you probably only have two rows in your table.

  • #15
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    I currently have 4 rows in the table like this:

    PHP Code:
    imgid,  imagename,                  choice,    sortorder
    38
    ,     ms-sa.jpg,                    left,                1
    37
    ,     front.jpg,                      right,              0
    39
    ,     Boxshot_ALZip_JB.png,    left,                2
    40
    ,     Boxshot_ALSong-01.pngright,               
    Will try that what you said


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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