Jump to content

[SOLVED] php and if statement


MDanz

Recommended Posts

on mysql i have this field known as type, which i save as a varchar 1 character.  And the 4 selections are I, V, F and M standing for Image, video, file and music.

 

now the dilemna is If statements.  I have the graphics hyperlink represent these 4 selections e.g. www.something.com/Video.jpg

 

how do i use an if statement to say..

 

If type V chosen then attach hyperlink (www.something.com/Video.jpg)

 

 

srry if it sounds complicated

Link to comment
Share on other sites

<?php 

$type = $row['type']; // or whatever

switch ($type) {
    case 'I':
        echo "EEMAYGE";
        break;
    case 'V':
        echo "VIDYA";
        break;
    case 'F':
        echo "FIYLE";
        break;
    case 'M':
        echo "MUSAK";
        break;
    default:
       echo "OON KNEWN TYPE!";
}

 

or you could use several if statement

 

<?php 

$type = $row['type']; // or whatever


if ($type == 'I') {
        echo "EEMAYGE";
} elseif ($type == 'V') {
        echo "VIDYA";
} elseif ($type == 'F') {
        echo "FIYLE";
} elseif ($type == 'M') {
        echo "MUSAK";
} else {
       echo "OON KNEWN TYPE!";
}

Link to comment
Share on other sites

  $hyperlink = $_POST['hyperlink'];

$currency = $_POST['currency'];

$name = $_POST['name'];

$image = $_POST['image'];

$info = $_POST['info'];

$keywords = $_POST['keywords'];

$type = $_POST['type'];

 

      // Create the query and insert

      // into our database.

      $query = "INSERT INTO Upload ";

      $query .= "(`image`, `hyperlink`,`currency`,`name`,`info`,`keywords`,`type`) VALUES ('$image','$hyperlink','$currency','$name','$info','$keywords','$type')";

 

      $results = mysql_query($query, $link);

 

heres the code for when i upload it

 

 

how do i add an if statement to say..

 

If Type = V then http://www.something.com/Video.jpg

 

and it inserts that link into the database.. I've already changed the field type in the database varchar to 200 characters

Link to comment
Share on other sites

<?php 

$type = $row['type']; // or whatever

switch ($type) {
    case 'I':
        echo "EEMAYGE";
        break;
    case 'V':
        echo "VIDYA";
        break;
    case 'F':
        echo "FIYLE";
        break;
    case 'M':
        echo "MUSAK";
        break;
    default:
       echo "OON KNEWN TYPE!";
}

 

thx i'll try this out

Link to comment
Share on other sites

ok, but you won't need this line

 

$type = $row['type']; // or whatever

 

because you'll already have defined type as...

 

$type = $_POST['type'];

 

also, if you're testing it...

 

instead of

 

$results = mysql_query($query, $link);

 

just use

 

echo $query;

 

to see what SQL query it would do... just saves you from removing loads of useless results (unless you're going to flush the table before you use it properly?)

 

---------

 

if you're doing what I tihnk you're doing...

 

if it's a video display a picture of a camcorder

if it's a picture a picture of a camera

a file picture of a file

image, picture of an image...

 

just leave it as I F V M in the database then use the code I sent on the code that GETS and PRODUCES the request...

otherwise if your site.com changes... you'll have to change ALL the data in the table :)

Link to comment
Share on other sites

$name = $runrows['name'];

        $image = $runrows['image'];

        $hyperlink = $runrows['hyperlink'];

        $currency = $runrows ['currency'];

        $info = $runrows ['info'];

        $type = $runrows ['type'];

 

 

 

      echo "<table><tr><td>

 

if ($type == 'I') {

        echo '<img src='http://www.u-stack.com/Image.jpg'>';

} elseif ($type == 'V') {

        echo '<img src='http://www.u-stack.com/Video.jpg'>';

} elseif ($type == 'F') {

        echo '<img src='http://www.u-stack.com/File.jpg'>';

} elseif ($type == 'M') {

        echo '<img src='http://www.u-stack.com/Music.jpg'>';

}

      </td></tr></table>";

 

 

I tried it it seems to be echoing all the images and shows the if code behind them??

Link to comment
Share on other sites

    echo "<table><tr><td>";

 

if ($type == 'I') {

        echo '<img src="http://www.u-stack.com/Image.jpg">';

} elseif ($type == 'V') {

        echo '<img src="http://www.u-stack.com/Video.jpg">';

} elseif ($type == 'F') {

        echo '<img src="http://www.u-stack.com/File.jpg">';

} elseif ($type == 'M') {

        echo "<img src="http://www.u-stack.com/Music.jpg">';

}

      echo "</td></tr></table>";

Link to comment
Share on other sites

<?php

//get data

 

 

 

 

$button = $_GET['submit'];

$search = $_GET['search'];

 

if

 

(!$button)

echo "You didn't submit a keyword";

 

else

{

if (strlen($search)<=2)

echo "search term too short";

else

{

echo "<br><br><font color=white>you searched for <b>$search</b></font><hr size='1'>";

}

mysql_connect("localhost", "Master", "password");

mysql_select_db("ustackc1_Login");

 

 

//explode our search term

$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each)

{

//construct query

$x++;

if($x==1)

        $construct .= "keywords LIKE '%$search_each%'";

        else

        $construct .= "OR keywords LIKE '%$search_each%'";

}

 

                  //echo out $construct

$construct = "SELECT * FROM Upload WHERE $construct";

}              $run = mysql_query($construct);

                $foundnum =  mysql_num_rows($run);

 

if  ($foundnum==0)

echo "No Stacks Found";

else

{

    echo "$foundnum Stacks Found!<p>";

 

 

    while ($runrows = mysql_fetch_assoc($run))

    {

              //get data

        $name = $runrows['name'];

        $image = $runrows['image'];

        $hyperlink = $runrows['hyperlink'];

        $currency = $runrows ['currency'];

        $info = $runrows ['info'];

        $type = $runrows ['type'];

 

 

 

      echo "<table><tr><td>";

 

if ($type == 'I') {

        echo '<img src="http://www.u-stack.com/Image.jpg">';

} elseif ($type == 'V') {

        echo '<img src="http://www.u-stack.com/Video.jpg">';

} elseif ($type == 'F') {

        echo '<img src="http://www.u-stack.com/File.jpg">';

} elseif ($type == 'M') {

        echo '<img src="http://www.u-stack.com/Music.jpg">';

}

      echo "</td></tr></table>";

 

 

    }

}

 

?>

Link to comment
Share on other sites

        $currency = $runrows ['currency'];

        $info = $runrows ['info'];

        $type = $runrows ['type'];

 

replace that for

 

        $currency = $runrows['currency'];

        $info = $runrows['info'];

        $type = $runrows['type'];

      echo "Type: $type";

 

save and upload then see what happens

Link to comment
Share on other sites

        $currency = $runrows ['currency'];

        $info = $runrows ['info'];

        $type = $runrows ['type'];

 

 

should be

 

        $currency = $runrows['currency'];

        $info = $runrows['info'];

        $type = $runrows['type'];

 

thats identical apart from the spacing.. i changed the spacing still the images aren't appearing

Link to comment
Share on other sites

        $currency = $runrows ['currency'];

        $info = $runrows ['info'];

        $type = $runrows ['type'];

 

replace that for

 

        $currency = $runrows['currency'];

        $info = $runrows['info'];

        $type = $runrows['type'];

      echo "Type: $type";

 

save and upload then see what happens

 

k i did that now it displays, represent my two images

 

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