Help With an If/Else Statement Pelase

Discussion in 'PHP' started by bertamus11, Sep 30, 2009.

  1. #1
    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:
    
    <?
    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;
    
    }
    ?>
    
    Code (markup):
    As you can see, the only difference really is this code here: <img src="<?php echo "{$datadir[adpics]}/{$row[picfile]}"; ?>">

    Any help would be appreciated. Thank you.
     
    bertamus11, Sep 30, 2009 IP
  2. anhbloginc

    anhbloginc Well-Known Member

    Messages:
    1,288
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    175
    #2
    Which will storage content for "If what's in my row starts with "http://" then use a certain code. " ? If this is variable , using :

    $string;

    if($string == "http://")
    {
    // do
    }
    else
    {
    //do
    }
     
    anhbloginc, Sep 30, 2009 IP
  3. bertamus11

    bertamus11 Well-Known Member

    Messages:
    791
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Thanks for the reply anhbloginc, much appreciated.

    The storage is actually being called from {$row[picfile]}
    In the picfile column in mysql it can contain either a whole url to a picture or the picture name.

    So, in the if, I need to say if {$row[picfile]} starts with http:// then display my code.
    Else, display another piece of code.

    I hope I explained it right. Thanks again.
     
    bertamus11, Sep 30, 2009 IP
  4. K1llswitch

    K1llswitch Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
  5. bertamus11

    bertamus11 Well-Known Member

    Messages:
    791
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    130
    #5
    Thanks K1llswitch, unfortunately, it looks like chinese to me.

    But, thanks for the thought.
     
    bertamus11, Sep 30, 2009 IP
  6. marshall_26

    marshall_26 Peon

    Messages:
    82
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    don't use preg_match that's a waste...


    
    <?php
    if(substr($row['picfile'], 0, 7) == 'http://')
    {
    #yep do something here
    }
    
    else{
    #nope do something else
    }
    ?>
    
    PHP:
     
    marshall_26, Sep 30, 2009 IP