Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2003
    Proud She-Geek

    Got results, but not what I want...using one query to help another

    On the site I'm working I have a page that lists each "site" and each row has the screenshot, site title, category title, and the action to take (view, edit, delete).

    Everything shows up correctly except the category title. The category names are kept in a seperate table (categories), and are referenced in the "site" table by their ID number (1,2,3 and so on).

    Basically what I need to do is get the row for the "site" and then query the category table to display the name. All that is currently displaying now in the category cell is "Resource id #x", each incremented, even though the correct category id is selected in the database.

    Below is my code; any help would be appreciated
    PHP Code:
    require ('interface.php');

    $result mysql_query("SELECT id,title,category,image_name FROM sites",$db);
    <center><b><a href=update.php>Add New Site</a></b></center><br>
    <table width="100%"  border="1" cellspacing="0" cellpadding="4">
    <td width="45%"><strong>Title</strong></td>
    while ($result2 mysql_fetch_array($result)) {
    $mycat $result2['category'];
    $displaycat mysql_query("SELECT title FROM categories WHERE id=$mycat") or die(mysql_error());
    <tr><td><img src=<? echo SITE_URL?>/images/screenshots/<? echo $result2['image_name'?> width=125></td>
    <td><? echo $result2['title']; ?></td>
    <td><? echo $displaycat ?></td>
    <td><a href=view_sites.php>View</a>&nbsp;&nbsp;<a href=update.php?id=<? echo $myid?>>Edit</a>&nbsp;&nbsp;<a href=delete_sites.php?id=<? echo $myid?>>Delete</a></td>
    <? ?>
    <?php echo "Signature here"; ?>

  2. #2
    You didn't go trough while - mysql_fetch_array thingy with $displaycat.
    $displaycat is a resource pointing to result of a query and you're not echoing the results, you are echoing the pointer.
    Anyway, you could perform this with 1 query since it seems the tables are in 1:1 relationship.


    c.title as category
    sites s
    categories c
    s.category =

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts