Jump to content

[SOLVED] print only if required


s4salman

Recommended Posts

Hello

i have fields named "w1" , "w2" , "w3" , "w4" , "w5 " , "w6" in mysql table.

These field have data like :

 

"yes" or "no"

i want to print record only if fields have "yes".

for example if "w1" has "yes" and "w2" has "yes" but "w3" , "w4" , "w5", "w6" have "no".

only w1 and w2 should be printed and w3,w4,w5,w6 should not printed.

 

I am actually using this for wallpaper sizes like : 

 

640x480 , 800x600 , 1024x768, 1152x864 , 1600x1200 , 1280x1024 sizes wallpaper.w1, w2, w3, w4, w5, w6 are for these sizes. if a wallpaper is just for 800x600(w1) and 1024x768(w2) size , then only print a link to download wallpaper of these two sizes and not of others.

 

And if wallpaper is available for all sizes, print the links to all.You can see what i mean at this URL :

 

http://wallpaperscript.com/demo/yoseminte-wallpapers.html

 

Here the wallpaper is available to download for just 3 sizes.So the site just printed 3links.

But at http://desktop-wallpapers.ro/perfect_strawberry-wallpapers.html

wallpaper is available in 5  different pixels, so 5 links have been printed.

Can any body help me how to do this.

i save field data in this manner :

 

$w1 = $first=mysql_result($result,"first");

and so on.

 

I just know that we can do this using if... else statement. but not sure how to do this.

Can anyone help me out.

Link to comment
https://forums.phpfreaks.com/topic/144207-solved-print-only-if-required/
Share on other sites

You can do something like this...

 


<?php

$wallpaper = 23;

$result = mysql_query ( "SELECT w1, w2, w3, w4, w5, w6 FROM table WHERE wallpaper_id = '" . $wallpaper . "';" );

if ( mysql_num_rows ( $result ) > 0 )
{
$row = mysql_fetch_assoc ( $result );

/* get the values that only have yes */

$row = array_diff ( $row, array ( 'no' ) );

foreach ( $row AS $key => $value )
{
	switch ( $key )
	{
		case 'w1' :
		echo "<a href='/wallpaper/" . $wallpaper . "/w1/index.html'>link 1 (size 1600 x 1200)</a>\n<br />\n";
		break;
		case 'w2' :
		echo "/* another link type */";
		break;
		case 'w3' :
		echo "/* another link type */";
		break;
		case 'w4' :
		echo "/* another link type */";
		break;
		case 'w5' :
		echo "/* another link type */";
		break;
		case 'w6' :
		echo "/* another link type */";
		break;
	}
}
}

?>

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.