user3623300
user3623300

Reputation: 379

Retrieving information from multiple tables

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?

Upvotes: 0

Views: 30

Answers (1)

Faisal Shaikh
Faisal Shaikh

Reputation: 4138

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);
?>

Upvotes: 1

Related Questions