Jump to content

if else echo, need a little help..


dgnzcn

Recommended Posts

Hi;

I have this codes simple showing photos and infos  from database...

 

I want this : if photo not found from databese then echo : no photo found..

and,  if info not found from database then echo : no info found

 

how can i do it..?

 

 

<?php do { ?>
                  <div style="float:left;">
                    <table border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td colspan="2" align="center" valign="middle"><img src="images/transparent_line.gif" width="12" height="3" /></td>
                      </tr>
                      <tr>
                        <td width="130" height="135" align="center" valign="middle" bgcolor="#FFFFFF"><a href="urun_res/<?php echo $row_res['file2']; ?>" class="highslide" id="thumb3" onclick="return hs.expand(this)"><img src="urun_res/<?php echo $row_res['file2']; ?>" alt="<?php echo $row_res['info']; ?>" width="100" height="100" title="Büyüt" /></a><a class="highslide" onclick="return hs.expand(this)"></a></td>
                        <td width="15" align="center" valign="middle"> </td>
                      </tr>
                      <tr>
                        <td colspan="2" align="center" valign="top"><img src="images/transparent_line.gif" width="12" height="2" /></td>
                      </tr>
                      <tr>
                        <td colspan="2" align="center" valign="top"><img src="images/transparent_line.gif" width="12" height="10" /></td>
                      </tr>
                      <tr>
                        <td colspan="2" align="center" valign="top"><?php echo $row_res['info']; ?></td>
                      </tr>
                    </table>
                  </div>
                <?php } while ($row_res = mysql_fetch_assoc($res)); ?>

Link to comment
Share on other sites

I am not sure how you managed everything with your DB but, you could place some code above your script with the if statements and also fetch the stuff you have from your database to give.

 

//$file_from_db = ;  // get your stuff from your database
//$info_from_db = ; // get your stuff from your database

//if-statement for $info
if($info_from_db!= NULL){ // or any value you want
$info = 'this will contain your database stuff';
}else{ 
$info = 'no info found...';
}

//if-statement for $file
if($file_from_db!= NULL){ // or any value you want
$file2 = 'path to file';// atleast that is what you store in your database i assume
}else{ 
$info = 'path to a default empty image or a text you like, i would use an empty picture';
}

 

 

 

Link to comment
Share on other sites

There are more ways i think to do this and it depends on the way your fields in the database are filled ofc, but this gives a good impression of one way of doing it. Hope it helps :)

In this case I am expecting your database fields are Set to NULL if the user has not done anything. You can ofcourse take any value as long as you adjust the check.

-edit i saw an error in my script in the second if statement i used $text instead of $file

//$file_from_db = ;  // get your stuff from your database (prolly a path to file)
//$info_from_db = ; // get your stuff from your database

//if-statement for $info
if($info_from_db!= NULL){ // or any value you want
$info = 'this will contain your database stuff';
}else{ 
$info = 'no info found...';
}

//if-statement for $file
if($file_from_db!= NULL){ // or any value you want
$file2 = 'path to file';// atleast that is what you store in your database i assume
}else{ 
$file2 = 'path to a default empty image or a text you like, i would use an empty picture';
}

Link to comment
Share on other sites

You gotta dump the tables in your code man, thats been depreciated for many, many years now. Its an important step if you are to have any chance at all as we shift into HTML5...

 

As you write your code you can have anything you want placed in a conditional statement:

$query = "SELECT * FROM my_db WHERE your_variable='$your_desired_data'";
// do all the standard query protocol then place your images, conditionally 
if(isset($row['image_x'])){
  echo '<img src="'.$row['image_x'].'" width="100" height="100" alt="dont forget your alt text">';
}
else{
  echo 'No image available';
}

 

Link to comment
Share on other sites

ok. really thanks for the answers.. I have another problem.

 

 

 <?php $found= include "inc-indirimliurunler.php" ; 
      if($found == ''){
      echo ('no product found');
      }
      else {
        echo include "inc-indirimliurunler.php".$found." ;
      }
      ?>

 

where is the wrong code ?

Link to comment
Share on other sites

You gotta dump the tables in your code man, thats been depreciated for many, many years now.

 

That's not exactly true. Tables have not been depreciated, they are still need for data tables.

 

And will continue to be relevant for many many years too; though school's and Colleges alike are now starting to favour CSS & divs. BUT there will always be someone using an old browser & frontpage somewhere!

 

I must admit though, I am completely div css now; though this was just to see if I could produce something exactly the same with div's/css as I can with tables, which I can!

 

Cheers,

Rw

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.