Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/178666-php-if-statement/
Share on other sites

 

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?

Link to comment
https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942447
Share on other sites

[/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

Link to comment
https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942449
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/178666-php-if-statement/#findComment-942458
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.