Results 1 to 1 of 1

Thread: Correct Syntax

  1. #1
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Correct Syntax

    Hi all,

    This one has been really doin my head in, I am wonderin if anyone could help, am I using the correct syntax to return data from mysql, mybe my query is at fault, its not getting any data echoed correctly? displaying all data, rather that just the data relating to the category, products and images.

    The DB:

    category:

    id (primery key)
    category_id (index)

    products:

    id (foriegn key to category_id)
    name
    description
    measurements
    img_id (index)

    images

    image_id (foriegn key to img_id)
    name
    filename
    thumbnail




    Code:
    <?php
    
    // query db
    if (isset($_GET['id'])) {
        $sql = "SELECT * FROM `category` WHERE category_id = '" . mysql_real_escape_string($_GET['id']) . "'"; // from category get id
        if ($result = mysql_query($sql)) {
          if (mysql_num_rows($result)) {
            $row = mysql_fetch_assoc($result);
            echo "<h2>" . $row['category_id'] . "</h2>";
    		} else {
    		echo "Something is wrong!";
          }
        }
      }
    ?>
    	<div class="datadivleftcontent">
    
    
    
    <?php // queries DB and echo results relating to products & images
    // query db
    if (isset($_GET['id'])) {
        $query = "SELECT products.*, images.image_id, images.filename,  images.thumbnail FROM products, images WHERE image_id = '" . mysql_real_escape_string($_GET['id']) . "'";
    
        if ($result = mysql_query($query)) {
          if (mysql_num_rows($result)) {
           while ($row = mysql_fetch_assoc($result)) {
    
            echo "<h4>" . $row['name'] . "</h4>"; // echo date results as format "h4"
    		echo "<p>" . $row['description'] . "</p>"; // echo content as p format "body text"
    		echo "<h5>Measurements: " . $row['measurements'] . "</h5>"; // echo content as p format "body text"
    
    
    
    echo "<a href='img/products/{$row['filename']}' rel='lightbox' title='{$row['name']}'>"; 
    
    echo "<img src='img/products/thumbnails/{$row['filename']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";
    
    }
    		} else {
    		echo "Something is wrong!";
          }
        }
      }
    ?>
    Hope some of this makes sense, Thanks you for any help and suggestions.
    Last edited by john0611; 12-03-2009 at 04:13 AM.

Bookmarks

Posting Permissions

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