0

How do I fetch and echo in php some data from a database called "somename", table "options", column "value" from all the rows which have the "name" starting with "dt_"

database name: "somename" database table: "options" database existing columns: "name", "value" database existing rows: "something1", "something2", "dt_option1", "dt_option2", "dt_option3"

database column i want: "value" database rows i want: "dt_option1", "dt_option2", "dt_option3"

I want the result to look like:

dt_option1 - 3432

dt_option2 - on

dt_option3 - off

dt_option_something - value

I tried and googled everywhere, I can't figure it out cause I am new to this.. Thank you for any help..

P.S. I just need the query and the echo..

3 Answers 3

1

To fetch the value of the rows: select name, value from options where name like "dt_%"

In PHP build a normal mysqli qry and then use a while-loop

// Note: Don't have the mysqli_* syntax 100% in mind, perhaps you have to lookup the right syntax in PHP manual, but for the idea you should understand it

$result = mysqli_query("select name, value from options where name like 'dt_%'");

while($row = mysqli_fetch_assoc($result))
{
  echo $row['name'] . " - " . $row['value'];
}

edited cause asker changed question and also wants to see the name not only the value

Sign up to request clarification or add additional context in comments.

1 Comment

I tried but I get this error: Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/x/public_html/api.php on line 15 Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /home/x/public_html/api.php on line 17 Warning: mysql_fetch_row() expects parameter 1 to be resource, null given in /home/x/public_html/api.php on line 22 null
1

Did you try anything like this? SELECT name, value FROM options WHERE name LIKE 'dt_%'

Edited since the asker changed the question

Comments

1

Do you mean something like:

SELECT name, value FROM somename.options WHERE name LIKE "dt_%"

Comments

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.