Jump to content

Need Help With an If/Else Statement Please


richardk1

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.