0

I have a database table that contains a bunch of different options and their values. The table has 3 columns which are ID, menu_option, and value. So one row may have the following information: 1, "menu_color", "#AB324B".

I want to display the value of each option on the page so the user can edit the option. Right now, i'm creating a query to get the info for each specific option. Like so

SELECT * FROM menu_theme WHERE ID='1'
SELECT * FROM menu_theme WHERE ID='2'
SELECT * FROM menu_theme WHERE ID='3'
...

Instead of making a new query to get the info per row, how can I make 1 query and distinguish what row I want to get the data from and display the data using php?

I'm aware of how to use php while loops with an SQL query, but I can't see how that would work with selecting specific rows.

2 Answers 2

3

Maybe something like this

 SELECT * FROM menu_theme WHERE ID IN ('1','2','3')
Sign up to request clarification or add additional context in comments.

Comments

1

maybe something like this:

<?php
//select all the rows
$sqlSelect="SELECT ID,menu_option,value FROM menu_theme";
$result=mysqli_query($con,$sqlSelect);
while($row=mysqli_fetch_array($result))
{
    $id=$row['ID'];
    $opt=$row['menu_option'];
    $val=$row['value'];

    $menuId="input-".$id;

    //create the label for the input
    echo "<label for='".$menuId."'>".$opt."</label>";

    //pre-populate the input with the name,value,id
    echo "<input type='text' name='".$menuId."' id='".$menuId."' value='".$val."'/>";
}

?>

1 Comment

Thanks, this should actually work fine. I'll use this method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.