Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Posts
    5

    Unanswered: Help with select query

    Hello, with the code below I am taking in the ClothingCode identifier using 2 search methods which already work. I have established a static connection already.

    I am trying to query the same table for the field that contains the rest of the information about the identifier ClothingCode then display them, however it is not assigning the information from the other fields correctly. It then assigns all the php variables ($ItemType, $AvailableSizes, etc..) the same as ClothingCode and not the data in their respective table fields.

    Can you help?

    here is the code:

    <?php

    $conn = mysql_connect('$localhost','$username','$password' );

    //Select the MySQL database

    $db = mysql_select_db('$dbname', $conn);

    //Issue SQL SELECT Statement

    $sql = "SELECT ClothingCode,Description,ItemType,Price,AvailableS izes,AvailableColours FROM Clothing WHERE ClothingCode = '$ClothingCode'";

    //Execute the SQL Statement and create a recordset

    $rs = mysql_query($sql,$conn);


    //Assign Records

    $Description= mysql_result($rs,"Description");
    $ItemType = mysql_result($rs,"ItemType");
    $Price = number_format(mysql_result($rs,"Price"),2);
    $AvailableSizes = mysql_result($rs,"AvailableSizes");
    $AvailableColours = mysql_result($rs,"AvailableColours");


    ?>


    <img src="images/products/<?php echo $ClothingCode; ?>.jpg" align="left" style="margin-right:30px">
    <span class="head1"><?php echo $Description; ?></span><br/>
    <span class="head4">ClothingCode: <?php echo $ClothingCode; ?></span><br/>
    <span class="head4">Price: $<?php echo $Price; ?></span>
    <p><?php echo "Available Sizes: " . $AvailableSizes; ?></p>
    <p><?php echo "Available Colours: " . $AvailableColours; ?></p>
    Last edited by psycho wolvesbane; 12-19-07 at 21:00.

  2. #2
    Join Date
    Dec 2007
    Posts
    23
    Hi

    $sql = "SELECT ClothingCode,Description,ItemType,Price,AvailableS izes,AvailableColours FROM Clothing WHERE ClothingCode = ".$ClothingCode;

    or

    $sql = "SELECT ClothingCode,Description,ItemType,Price,AvailableS izes,AvailableColours FROM Clothing WHERE ClothingCode = ' ".$ClothingCode." ' ";

    :P

    Salu2

  3. #3
    Join Date
    Dec 2007
    Posts
    5
    Hi thanks for replying, yet I've solved this problem and will be creating a new one soon most likely.

    The way I solved it in the end (courtesy of another forum) was to use the MySQL Fetch Associate function like so:

    $rs = mysql_query($sql,$conn);

    $record = mysql_fetch_assoc($rs);

    //Assign Records

    $Description= $record['Description'];
    $ItemType = $record['ItemType'];
    $Price = number_format($record['Price'],2);
    $AvailableSizes = $record['AvailableSizes'];
    $AvailableColours = $record['AvailableColours'];

    Thanks for trying anyway as no one else has replied since I posted it a week ago.

Posting Permissions

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