-4

I want retrieve data from mysql database and store in an array. Later I would display the data in html.

Below is my code snippet:

select co_no from faculty_co where course_code='$course1_code';

The output will display a total 5 co_no values. I want to store this values in an array and display as dropdown menu in html using select tag.

I am new to php. Please tell me how do I retrieve and store it.

3

2 Answers 2

0

I'm 'old school', and not much of a programmer, so I tend to do things procedurally.

I do it something like this:

include('path/to/connection/stateme.nts'); // the connection is a variable '$db'

$query = "my query";

$result = mysqli_query($db,$query);

$rows = array(); //initialise array

while($row = mysqli_fetch_assoc($result)){
$rows[] = $row;
} 

Now you can store that as a json_encoded string or just retain it as an array for later use.

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

Comments

0

First off, php.net has a lot of documentation on mysql and other things and is pretty easy to understand.

Check out the documentation and examples here.

2 Comments

Generally, recommending a deprecated API is considered bad form.
@Strawberry Thanks for pointing that out. I probably should have stayed away from this one. I fixed the answer.

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.