0

I've got two tables in my database, one like

**ID / muscle group name**  
1 / arms  
2 / chest  
3 / legs  

and another table like this

**ID / muscle_name / muscle_group_id**  
1 / biceps / 1  
2 / triceps / 1  
3 / extensor / 1  
4 / flexor / 1

How can I get the data from my database so that I can retrieve the information like

echo $result['arms'][0]

(to get muscle_group_id for arms)

and then iterate over all the muscles in the arm?

1 Answer 1

1

Here is a full example:

http://php.net/manual/en/function.mysql-fetch-array.php

1.Connect

2.Select database

3.Make query

4.Cycle on the result and fetch array to get the row

Here is example:

    <?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    printf("ID: %s  Name: %s", $row[0], $row[1]);  
}

mysql_free_result($result);
?>
Sign up to request clarification or add additional context in comments.

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.