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.

 

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.

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!

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.

  • 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

 

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

Archived

This topic is now archived and is closed to further replies.

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