...

View Full Version : if then elseif - who knows?



student101
02-14-2008, 09:20 PM
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
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?

aedrin
02-14-2008, 09:24 PM
The code you show should be working.

student101
02-14-2008, 09:27 PM
Yes,
but for some odd reason I only get two images displayed?

Andrew Johnson
02-14-2008, 09:30 PM
If your problem is the number of images then it is obviously the WHILE loop you didn't post...

student101
02-14-2008, 09:35 PM
I've got this:



<?php do { ?>

the code

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

Andrew Johnson
02-14-2008, 09:38 PM
...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 do { ?>

the code

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


Do



<?php while ($row_rsimage = mysql_fetch_assoc($rsimage)) { ?>

the code

<?php } ?>

kbluhm
02-14-2008, 09:41 PM
WTF is up with all these innappropriately used do-while loops? Do people even comprehend the difference between while and do-while?

student101
02-14-2008, 09:42 PM
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

Andrew Johnson
02-14-2008, 09:44 PM
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.

student101
02-14-2008, 09:47 PM
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.

Andrew Johnson
02-14-2008, 09:48 PM
Man I'm trying to be nice here but understand you need to post the whole code INCLUDING the frigging SELECT statement.

Jeepers...

student101
02-14-2008, 09:51 PM
Left out HTML parts.



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>

student101
02-14-2008, 09:53 PM
I have even tried replacing these parts from the database

<img src="../uploads/left/<?php echo $row_rsimage['imagename']; ?>" alt="">
Like this

<img src="../uploads/<?php echo $row_rsimage['choice']; ?>/<?php echo $row_rsimage['imagename']; ?>" alt="">

Andrew Johnson
02-14-2008, 09:55 PM
Get rid of this line


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

student101
02-14-2008, 10:02 PM
I currently have 4 rows in the table like this:



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.png, right, 2


Will try that what you said

student101
02-14-2008, 10:06 PM
Sorry,
same result I had without those changes.

student101
02-14-2008, 10:15 PM
It loops through the code fine, but doesn't display the data?
This is odd.

student101
02-14-2008, 10:21 PM
It works now!

This is retarded!!!
I went to have a smoke, came back and now it's displayed as needed.
F' that I know I'm not F'n crazy

Thank you, for your taking your time here.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum