richardk1 Posted October 1, 2009 Share Posted October 1, 2009 Hi there, I need to make an if/else statement and I'm stumped. Here's what I want the code to do: If what's in my row starts with "http://" then use a certain code. Else, use a another code. Kind of like this: Code: <? if (CODE TO USE IF THIS ROW CONTAINS "HTTP://") then display this: <img src="<?php echo "{$row[picfile]}"; ?>"> else: <?php if (@mysql_num_rows($pres)) { $i = 0; ?> <table class="adpics" width="100%"><tr><td> <?php while ($row = mysql_fetch_array($pres)) { $i++; $imgsize = GetThumbnailSize("{$datadir[adpics]}/{$row[picfile]}", $images_max_width, $images_max_height); ?> <img src="<?php echo "{$datadir[adpics]}/{$row[picfile]}"; ?>"> <?php } ?> </td></tr></table> <?php $imgcnt = $i; } ?> As you can see, the only difference really is this code here: <img src="<?php echo "{$datadir[adpics]}/{$row[picfile]}"; ?>"> I just need the the code for the if statement. What's in the else is fine Any help would be appreciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/ Share on other sites More sharing options...
khr2003 Posted October 1, 2009 Share Posted October 1, 2009 try this $var = strstr($link, 'HTTP://'); if($var) { // put your code here }else { //The else code here } Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-928123 Share on other sites More sharing options...
richardk1 Posted October 1, 2009 Author Share Posted October 1, 2009 Thank you for your help, I appreciate it. Unfortunately, it didn't work. Here's what I have so far: <? if (@mysql_num_rows($pres)) { $i = 0; ?> <?php $var = strstr($link, 'http://') elseif ($var) { ?> <img src="<?php echo "{$row[picfile]}"; ?>" id="adimg<?php echo $i; ?>" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>" alt="<?php echo $ad['adtitle']; ?>"> <?php } elseif { ?> <table class="adpics" width="100%"><tr><td> <? while ($row = mysql_fetch_array($pres)) { $i++; $imgsize = GetThumbnailSize("{$datadir[adpics]}/{$row[picfile]}", $images_max_width, $images_max_height); ?> <img src="<?php echo "{$datadir[adpics]}/{$row[picfile]}"; ?>" id="adimg<?php echo $i; ?>" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>" alt="<?php echo $ad['adtitle']; ?>"><br><br> <?php } ?> </td></tr></table> <?php $imgcnt = $i; } ?> Any ideas? Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-928170 Share on other sites More sharing options...
lucifersolutions Posted October 2, 2009 Share Posted October 2, 2009 What a coincidence... Right now I'm busy with if/else with preg_match() for time/date conversion into array's I suggest to use: <?php if (stristr("http://", $link)) { // IF True-code } else { // IF False-code } ?> If that doesn't work... <?php if (preg_match('/http\://///', $link)) { // IF True-code } else { // IF False-code } ?> If this doesn't work... Let me know and I will try it out for myself... (curious) Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-929380 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 I believe... if(preg_match("/^http:\/\//i", $link) { // if } else { // else } ... is probably the right preg_match, very similar to lucifersolutions's suggestion only ensuring it's at the start of the string and case insensitive. NB: I've not tested it though. Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-929398 Share on other sites More sharing options...
lucifersolutions Posted October 3, 2009 Share Posted October 3, 2009 I'm not really familiar with escaping and expression... www.php.net Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-929404 Share on other sites More sharing options...
.josh Posted October 3, 2009 Share Posted October 3, 2009 ...or you could like, use a different delimiter so you don't have to worry about escaping... Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-929418 Share on other sites More sharing options...
nicephotog Posted October 11, 2009 Share Posted October 11, 2009 <img src="<?php echo "{$row[picfile]}"; ?>" id="adimg<?php echo $i; ?>" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>" alt="<?php echo $ad['adtitle']; ?>"> <?php } elseif { ?> Reply #2 on: September 30, 2009, 11:16:25 PM Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-934757 Share on other sites More sharing options...
.josh Posted October 11, 2009 Share Posted October 11, 2009 <img src="<?php echo "{$row[picfile]}"; ?>" id="adimg<?php echo $i; ?>" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>" alt="<?php echo $ad['adtitle']; ?>"> <?php } elseif { ?> Reply #2 on: September 30, 2009, 11:16:25 PM why would you do something like that? Just wrap the whole thing in 1 php tag and make it 10x more readable. Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-934858 Share on other sites More sharing options...
nicephotog Posted October 12, 2009 Share Posted October 12, 2009 I was saying, shouldn't that be more like what follows here. elseif(...CONDITION HERE!!!...){.... Quote Link to comment https://forums.phpfreaks.com/topic/176133-need-help-with-an-ifelse-statement-please/#findComment-935159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.