Russia Posted October 22, 2009 Share Posted October 22, 2009 I am looking for a php if statement that is basicly like this: Like if the value of a row in a column table is 1 then show this, if the value is 2 then show this. Can someone help me out and make one for me. I think its simple and not many lines. +---------+ | P_style | +---------+ | 2 | +---------+ Like if its that value then echo something. If the value is 1 for P_style then display something else. Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/ Share on other sites More sharing options...
Russia Posted October 22, 2009 Author Share Posted October 22, 2009 Like a Switch Statement type of thing... Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942434 Share on other sites More sharing options...
Russia Posted October 22, 2009 Author Share Posted October 22, 2009 So I edited to fit my style. <?php include("inc/config.php"); $result = mysql_query("SELECT style FROM website") or die(mysql_error()); $row = mysql_fetch_row($result); $col = $row[0]; switch($col) { case 1: echo "value1"; case 2: echo "value2"; } ?> Now If someone can make a dropdown for me that edits the value on it. Like this: <select> <option value="1">First</option> <option value="2">second</option> <option value="3">third</option> </select> and the value that you pic will be updated in the database. So if you pick third and click submit, the value that will be in the database would be 3. Can someone help me out with that? Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942447 Share on other sites More sharing options...
indigo diingo Posted October 22, 2009 Share Posted October 22, 2009 [/code] $m = mysqli_connect('localhost','root',''); $result = mysqli_query($m,"SELECT p_style FROM mydatabase.mytable"); while($row = mysqli_fetch_assoc($result)) array_push($return,$row); $p_style = $return[0]['p_style']; if($p_style === 1) echo 'yeah, the magical numbers is .... 1'; else if($p_style === 2) echo 'to bad, we've got a just a second'; [/code] If p_style can only be one of TWO numbers you better use 0 and 1 instead of 1 and 2. The mysqli stuff is just typed out of my head so there could be some errors. Check the php manual for more info. Greets Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942449 Share on other sites More sharing options...
Russia Posted October 22, 2009 Author Share Posted October 22, 2009 I know I figured that out. Now I need help with the second thing, a dropdown to update the value in the row. Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942452 Share on other sites More sharing options...
Russia Posted October 22, 2009 Author Share Posted October 22, 2009 Thanks. So I edited to fit my style. <?php include("inc/config.php"); $result = mysql_query("SELECT style FROM website") or die(mysql_error()); $row = mysql_fetch_row($result); $col = $row[0]; switch($col) { case 1: echo "value1"; case 2: echo "value2"; } ?> Now If someone can make a dropdown for me that edits the value on it. Like this: <select> <option value="1">First</option> <option value="2">second</option> <option value="3">third</option> </select> and the value that you pic will be updated in the database. So if you pick third and click submit, the value that will be in the database would be 3. Can someone help me out with that? Does anyone know how to do that? Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942458 Share on other sites More sharing options...
Russia Posted October 22, 2009 Author Share Posted October 22, 2009 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942465 Share on other sites More sharing options...
mikesta707 Posted October 22, 2009 Share Posted October 22, 2009 http://www.phpfreaks.com/forums/index.php/topic,200925.0.html Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942485 Share on other sites More sharing options...
Russia Posted October 23, 2009 Author Share Posted October 23, 2009 bump i still need support Quote Link to comment https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942883 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.