SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Code not working

    I need some info dragged out of the DB and displayed in a table, heres my code:

    PHP Code:
    $Connect = mysql_connect('localhost', '****', '****');

    mysql_select_db('shadesofjapan', $Connect);

    $Result = mysql_query("SELECT 'ProductName', 'Finish', 'Size', 'Price', 'Quantity' FROM shoppinglist WHERE UserId = '{$_SESSION['UserId']}'");

    if (mysql_num_rows($Result))
    {

        while ($MyRow = mysql_fetch_row($Result))
        {
            ?>
              <table width="607"  border="1">
                  <tr>
                    <td>Product Name</td>
                    <td>Finish</td>
                    <td>Size</td>
                    <td>Price</td>
                    <td>Quantity</td>
                    <td>Action</td>
                  </tr>
                  <tr>
                    <td><? echo $MyRow['ProductName']; ?></td>
                    <td><? echo $MyRow[Finish]; ?></td>
                    <td><? echo  $MyRow[Size]; ?></td>
                    <td><? echo  $MyRow[Price]; ?></td>
                    <td><? echo  $MyRow[Quantity]; ?></td>
                    <td>Delete</td>
                  </tr>
                </table>
            
    <?php
        
    }
        
    }
    else
    {
        echo
    "You have not selected any items to order";
    }
    ?>
    The table displays but the info will not show up in the other rows, can someone plz help.

    Thanks in advance
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  2. #2
    orange pips! orange pips!
    Join Date
    Oct 2001
    Location
    Its all about location
    Posts
    652
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to have quotes in your array output, such as:
    PHP Code:
    //$MyRow[Finish]
    $MyRow["Finish"

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey krayziepjf,

    Thanks for coming to my aid (again )

    That however doesnt seem to solve the problem, any other ideas??
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  4. #4
    SitePoint Addict evilone's Avatar
    Join Date
    Oct 2004
    Location
    Estonia
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    PHP Code:
    <?php

    $connect 
    mysql_connect('localhost''****''****'); 
    mysql_select_db('shadesofjapan'$connect); 
    $result mysql_query("SELECT ProductName, Finish, Size, Price, Quantity FROM shoppinglist WHERE UserId = '" $_SESSION['UserId'] . "'"); 

    if (
    mysql_num_rows($result) != 0) { 
         while (
    $row mysql_fetch_row($result)) { 
    ?> 
              <table width="607"  border="1"> 
                  <tr> 
                    <td>Product Name</td> 
                    <td>Finish</td> 
                    <td>Size</td> 
                    <td>Price</td> 
                    <td>Quantity</td> 
                    <td>Action</td> 
                  </tr> 
                  <tr> 
                    <td><? echo $row['ProductName']; ?></td> 
                    <td><? echo $row['Finish']; ?></td> 
                    <td><? echo  $row['Size']; ?></td> 
                    <td><? echo  $row['Price']; ?></td> 
                    <td><? echo  $row['Quantity']; ?></td> 
                    <td>Delete</td> 
                  </tr> 
                </table> 
    <?php 
        

         
    } else { 
        echo
    "You have not selected any items to order"
    }
     
    ?>

  5. #5
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try changing
    PHP Code:
    $Result mysql_query("SELECT 'ProductName', 'Finish', 'Size', 'Price', 'Quantity' FROM shoppinglist WHERE UserId = '{$_SESSION['UserId']}'"); 

    //to

    $Result mysql_query("SELECT ProductName, Finish, Size, Price, Quantity FROM shoppinglist WHERE UserId = '{$_SESSION['UserId']}'") or die('Error: '.mysql_error()); 
    The quotes around your columnnames are not necessary, and "or die(mysql_error())" tells you if something with your query is wrong

    hth

  6. #6
    orange pips! orange pips!
    Join Date
    Oct 2001
    Location
    Its all about location
    Posts
    652
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, I didn't see that you were using mysql_fetch_row. Instead, use mysql_fetch_array. mysql_fetch_row returns a numbered array, instead of a column named array.

  7. #7
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YAYA well i mixed all the advice together and changed the mysql_fetch_row to mysql_fetch_array and hey presto.

    Thanks all
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  8. #8
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol, just did. greaty minds think alike
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"


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
  •