Need help with php

Hmm this is really hard to explain…Basically i have two tables, one is entitled catagory and the other one is entitled tutorials. In the catagory table it has 2 fields id and catagoryname, in tutorials it has 6 fields… but in this problem only 1 is needed, catagory. On a tutorials.php, it gets all the catagories from the table catagory and makes the catagories into a variable,$catagoryname. Then it gets everything from the tutorial table where catagory=$catagoryname, and then i want it to display the tutorial catagory name and how many tutorials came up… ex:

Tutorials:
Photoshop 7.0 (3)

[code] $q=mysql_query(‘SELECT * FROM catagory ORDER BY id DESC’); //Gets all the tutorials in the data base
while($l=mysql_fetch_array($q)){
$catagoryname=$l[“name”];

                $q2=mysql_query('SELECT * FROM tutorials WHERE catagory=$catagoryname');

               
               } [/code]

that is what i have so far… any help would be great!

Thanks,

Justin

how about something like:

SELECT DISTINCT catagoryName FROM catagory ORDER BY catagoryName DESC;

This will return all the distinct catagory names form the table and list them alphabetically from a - z.

I like for loops so:

$type = array();
run the query;
get the number of results returned (mysql_num_rows)
for ($i=0; $i<$num; $i++)
{
    array_push($type, mysql_fetch_row($result));
}

The array $type now holds the tutorial catagories. You can cycle through them to create links (using $_GET) to a page listing the tutorials for that catagory (use your query 2).

Is that basically what you were asking?

Sponsor our Newsletter | Privacy Policy | Terms of Service