MDanz Posted August 6, 2009 Share Posted August 6, 2009 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 Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 <?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!"; } Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 $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 Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 <?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 Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 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 Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 $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?? Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 this what happens on my site http://www.u-stack.com/search.php?search=Basketball&submit=search It should just show two I ... coz i only got 2 images in the whole database Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 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>"; Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 thx for help but now the page is empty even though it has found two results http://www.u-stack.com/search.php?search=Basketball&submit=search Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 is it within the while statement... post the whole search.php code Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 <?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>"; } } ?> Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 $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 Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 $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 Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 $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: Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 ummmmmmmm then the column 'type' has nothing in it check your database! Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 use this echo nl2br(str_replace(' ',' ',print_r($runrows,true))); instead of echo "Type: $type"; it will print out the data structure of the whole array Quote Link to comment Share on other sites More sharing options...
MDanz Posted August 6, 2009 Author Share Posted August 6, 2009 Thanks, i got it working... lol i started type with a capital T in my database... thx alot Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 awesome, but http://www.u-stack.com/search.php?search='' so so safe quotes or w/e it's called and instead of if (strlen($search)<=2) put if(!isset($search) || strlen($search)<=2) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.