55 users online (1 members and 54 guests)  


  Results 1 to 13 of 13

Related

  1. Replies: 3
  2. IE specific gap at top of table    Forum: HTML Forum
    Replies: 0
  3. Looking for a very specific CMS feature    Forum: Website Scripts Forum
    Replies: 1
  4. Replies: 0
  5. Image tile across specific area!!    Forum: HTML Forum
    Replies: 4
  1. #1
    lozza's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    11

    specific data query issue

    Hello.

    I am new to PHP and having trouble calling up data from my database and making do what I want. I have the simple query below that calls up the thumbnails column from my table:
    <?php
    $result = mysql_query("SELECT * FROM jewelleryrings");

    while($row = mysql_fetch_array($result))
    {
    echo $row['thumbnails'];
    echo "<br />";
    }
    ?>

    What I need to do is - "SELECT * FROM jewelleryrings WHERE itemcode=$variable". In other words, I need to call all thumbnails images from fields whose "itemcode" column matches an unknown "itemcode" (so $variable). When I change the code from:
    <?php
    $result = mysql_query("SELECT * FROM jewelleryrings");
    >?

    to

    <?php
    $result = mysql_query( "SELECT * FROM jewelleryrings WHERE itemcode=$variable");
    ?>

    I get an error saying "Warning:MYSQL_FETCH_ARRAY(): supplied argument is not a valid MYSQL result resource in C:xampp/htdocs...etc."

    Any ideas of how I can call up specific results based ona changing variable?

    THanks loads for any help!!!

  2. #2
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: specific data query issue

    This is actually simple string manipulation. Think of the query as a string. Change it to:

    Code:
    $result = mysql_query( "SELECT * FROM jewelleryrings WHERE itemcode=" . $variable);
    and you should be good to go.

  3. #3
    lozza's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    11

    Re: specific data query issue

    I did exactly as you suggested but get the same error message. I also tried it with quotations around the variable as well, no dice.

    Is there a problem with the previously stated variables at the beginning of my page? They are:

    <?php

    $query_rsRings = "SELECT category, itemcode, colour, `size`, `description`, `shipping code`, `product name`, price, origin, thumbnails, `full images` FROM jewelleryrings ORDER BY itemcode ASC";

    $rsRings = mysql_query($query_rsRings, $connburapa) or die(mysql_error());

    $row_rsRings = mysql_fetch_assoc($rsRings);

    $totalRows_rsRings = mysql_num_rows($rsRings);

    ?>

    THanks for the speedy reply!
    Last edited by lozza; 09-05-2008 at 05:37 PM. Reason: typo

  4. #4
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: specific data query issue

    Are you setting the value of $variable? If not, that is why you are still getting the errors. Do NOT put the variable in quotes as that will put it within the string, and defeat the purpose. You need to set the variable.

    i.e.
    Code:
    $variable = 12345;
    Setting it to that value will result in the following query being sent to MySQL: SELECT * FROM jewelleryrings WHERE itemcode=12345

    If you do not set the value of $variable first, you will get the following string sent to MySQL: SELECT * FROM jewelleryrings WHERE itemcode=

    I am assuming that none of the products has a NULL itemcode, so your query will return no results and produce the error you are receiving.

  5. #5
    lozza's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    11

    Re: specific data query issue

    Hey again Jthayne...

    It works now - thanks for the input! The code that does the trick is below:

    <?php
    $productID=$row_rsRings['itemcode'];
    $sql="SELECT * FROM jewellery2 WHERE itemcode='$productID'";
    $result = mysql_query($sql);
    while($row_rsRings = mysql_fetch_array($result))
    {
    echo $row_rsRings['thumbnails'];
    }
    ?>

    I am now having difficult making each thumbnail link to a "details" page while sending on its primary key info in the url. I can get them to link as a "set" if I don't structure them in separate tables, but of course they then just share one link and all go to the same page (which is the first one in the set).

    When I create a table for each one, I then cannot make them link to another page at all for some reason (admittedly I am using a "Details Page" add-on for the link).

    The code below (with some tweaks in the future to make them display horizontally) would be ideal if only I could make them link to a details page to display that one product:

    <?php
    $productID=$row_rsRings['itemcode'];
    $sql="SELECT * FROM jewellery2 WHERE itemcode='$productID'";
    $result = mysql_query($sql);
    while($row_rsRings = mysql_fetch_array($result))
    {
    echo "<center>";
    echo "<table CELLPADDING=10 border =1 >";
    echo "<tr>";
    echo "<td>".$row_rsRings['thumbnails']."</td>";
    echo "</tr>";
    echo "</table>";
    }
    ?>

    Any suggestions from anyone would be great - I am nearing completion on this project - will be nice to have some time to study the code a bit more in depth.
    Last edited by lozza; 09-06-2008 at 02:14 PM. Reason: typo

  6. #6
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: specific data query issue

    You need to make the changes highlighted below:

    <?php
    $productID=$row_rsRings['itemcode'];
    $sql="SELECT * FROM jewellery2 WHERE itemcode='$productID'";
    $result = mysql_query($sql);
    while($row_rsRings = mysql_fetch_array($result))
    {
    echo "<center>";
    echo "<table CELLPADDING=10 border =1 >";
    echo "<tr>";
    echo "<td><a href='details.php?id=" . $row_rsrings['primary_key'] . "'>".$row_rsRings['thumbnails']."</a></td>";
    echo "</tr>";
    echo "</table>";
    }
    ?>
    With that, you need to change the details.php to whatever your details page is. Also, chage id to whatever your details page plugin needs as a variable name, and the primary_key to the name of the column you are referencing.

  7. #7
    lozza's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    11

    Re: specific data query issue

    FANTASTIC!!! Here is what I ended up with:

    <?php
    $productID=$row_rsRings['itemcode'];
    $sql="SELECT * FROM jewellery2 WHERE itemcode='$productID'";
    $result = mysql_query($sql);
    while($row_rsRings = mysql_fetch_array($result))
    {
    echo "<table>";
    echo "<td><a href='popupmockup.php?categories=".urlencode($row_rsRings['categories']) . "'>".$row_rsRings['thumbnails']."</a></td>";
    echo "</table>";

    }
    ?>

    I then created a variable and filtered it in the destination page so the "categories" column is picked up. Thanks a million - I had been messing with a variation of what you typed but I had too many comma's, or semi-colon's or something and it kept giving me errors.

    Appreciate your help a million-fold!!

  8. #8
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: specific data query issue

    I know how frustrating it can be. Glad you were able to get it working.

  9. #9
    lozza's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    11

    Re: specific data query issue

    Sorry to bring this up again...I thought things were squared away, and they are to some degree...only now all the other dynamic elements of the page don't work. The page I am putting the above code on is a detail page and as such has a product forwarded in the url...all the info on the page is populated from that.
    Now when I put the above code into my page to display other similiar products, it negates any of the dynamic forms and input that was generated from the URL forwarded product ID. I have toyed with things, and if I place the form or other elements (ie: ['itemcode']) in FRONT of the new code they work, placed after it's like they don't exist. I am thinking I need to insert a "DIE" phrase into my code perhaps? Or does the SELECT * FROM automatically negate the forwarded URL info? Any ideas or ideas of Literature I can look into?

    Appreciate any info

  10. #10
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: specific data query issue

    Without seeing the code, I cannot be certain, but it sounds to me like you are not closing your PHP script when you switch from PHP to HTML. Make sure you put

    ?>

    between the PHP code and the HTML code.

  11. #11
    lozza's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    11

    Re: specific data query issue

    Hey Jthayne. THanks for looking! I do have an ?> to close it off, it still doesn't work. I will post the code below, though it is a LOT - I have put in some comments about what doesn't work and what the problem code is...please let me know if it is indecipherable or too messy etc. (this is not the exact page I am working on but it IS the test page and is almostr exactlt the same and suffering the same problem. I am at school today so can't access my other PC).

    the code:


    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }

    $varProduct_rsRings = "1";
    if (isset($_GET['categories'])) {
    $varProduct_rsRings = $_GET['categories'];
    }
    mysql_select_db($database_connburapa, $connburapa);
    $query_rsRings = sprintf("SELECT jewellery2.categories, jewellery2.itemcode, jewellery2.colour, jewellery2.`size`, jewellery2.`description`, jewellery2.`shipping code`, jewellery2.`product name`, jewellery2.price, jewellery2.origin, jewellery2.thumbnails, jewellery2.fullimages FROM jewellery2 WHERE jewellery2.categories=%s", GetSQLValueString($varProduct_rsRings, "int"));
    $rsRings = mysql_query($query_rsRings, $connburapa) or die(mysql_error());
    $row_rsRings = mysql_fetch_assoc($rsRings);
    $totalRows_rsRings = mysql_num_rows($rsRings);

    $MM_paramName = "";

    // *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
    // create the list of parameters which should not be maintained
    $MM_removeList = "&index=";
    if ($MM_paramName != "") $MM_removeList .= "&".strtolower($MM_paramName)."=";
    $MM_keepURL="";
    $MM_keepForm="";
    $MM_keepBoth="";
    $MM_keepNone="";
    // add the URL parameters to the MM_keepURL string
    reset ($_GET);
    while (list ($key, $val) = each ($_GET)) {
    $nextItem = "&".strtolower($key)."=";
    if (!stristr($MM_removeList, $nextItem)) {
    $MM_keepURL .= "&".$key."=".urlencode($val);
    }
    }
    // add the Form parameters to the MM_keepURL string
    if(isset($_POST)){
    reset ($_POST);
    while (list ($key, $val) = each ($_POST)) {
    $nextItem = "&".strtolower($key)."=";
    if (!stristr($MM_removeList, $nextItem)) {
    $MM_keepForm .= "&".$key."=".urlencode($val);
    }
    }
    }
    // create the Form + URL string and remove the intial '&' from each of the strings
    $MM_keepBoth = $MM_keepURL."&".$MM_keepForm;
    if (strlen($MM_keepBoth) > 0) $MM_keepBoth = substr($MM_keepBoth, 1);
    if (strlen($MM_keepURL) > 0) $MM_keepURL = substr($MM_keepURL, 1);
    if (strlen($MM_keepForm) > 0) $MM_keepForm = substr($MM_keepForm, 1);
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/productdescriptionpage1.dwt" codeOutsideHTMLIsLocked="false" -->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Untitled Document</title>
    <!-- InstanceEndEditable -->
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
    <link href="cssstyles/productdescriptionpage.css" rel="stylesheet" type="text/css" />
    <!--[if IE 5]>
    <style type="text/css">
    /* place css box model fixes for IE 5* in this conditional comment */
    .twoColFixLtHdr #sidebar1 { width: 230px; }
    </style>
    <![endif]--><!--[if IE]>
    <style type="text/css">
    /* place css fixes for all versions of IE in this conditional comment */
    .twoColFixLtHdr #sidebar1 { padding-top: 30px; }
    .twoColFixLtHdr #mainContent { zoom: 1; }
    /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
    </style>
    <![endif]-->
    <link href="cssstyles/greytextcentered.css" rel="stylesheet" type="text/css" />
    <link href="spryassets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <link href="cssstyles/homefooter.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    body {
    background-image: url(root%20folder/images/headerandfooter/lotus.gif);
    background-repeat: repeat;
    }
    -->
    </style>
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <link href="cssstyles/productphoto.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    .style7 {font-size: 18px}
    -->
    </style>
    </head>

    <body class="twoColFixLtHdr">

    <div id="container">
    <div id="header">
    <table width="975" height="83">
    <tr class="greytextcentered">
    <th width="270" height="79" align="left" scope="col"><img src="root folder/images/headerandfooter/burapalogo186x90.jpg" width="186" height="90" alt="logo" /></th>
    <th width="359" class="greytextcentered" scope="col">Burapa imports only the finest home and personal style products from Thailand, Laos, Nepal, &amp; Tibet</th>
    <th width="71" scope="col">&nbsp;</th>
    <th width="131" scope="col"><p align="center"><img src="root folder/images/headerandfooter/45x39transparent.gif" width="45" height="39" alt="shopping" /></p>
    <p align="left" class="greytextcentered">my shopping bag</p></th>
    <th width="120" valign="top" class="greytextcentered" scope="col"><p><img src="root folder/images/headerandfooter/planesmallergreenback.jpg" width="50" height="37" alt="shipping" /></p>
    <p class="greytextcentered">shipping faqs</p></th>
    </tr>
    </table>
    <ul id="MenuBar1" class="MenuBarHorizontal">
    <li><a href="index.html">home</a> </li>
    <li><a href="#" class="MenuBarItemSubmenu">products</a>
    <ul>
    <li><a href="#">antiques</a></li>
    <li><a href="#">art,carvings,prints</a></li>
    <li><a href="#">furniture</a></li>
    <li><a href="#">gifts</a></li>
    <li><a href="#">home style</a></li>
    <li><a href="#">jewellery</a></li>
    <li><a href="#">pashmina/cashmere</a></li>
    <li><a href="#">silk</a></li>
    </ul>
    </li>
    <li><a href="#">testimonials</a> </li>
    <li><a href="#">wholesale</a></li>
    <li><a href="#">about us</a></li>
    </ul>
    <p>&nbsp;</p>
    <!-- end #header --></div>
    <!-- InstanceBeginEditable name="productimage" -->
    <div id="sidebar1">
    click on image for larger view<b /></b>
    <div class="productphoto"><!-- end #sidebar1 -->
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p></p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <!--call and display all items with same itemcode as detail page product
    This is the problem code-->
    <?php echo $row_rsRings['full images']; ?></div>
    <b /></b>
    <?php
    $itemID=$row_rsRings['itemcode'];
    $sql="SELECT * FROM jewellery2 WHERE itemcode='$productID'";
    $result = mysql_query($sql);
    while($row_rsRings = mysql_fetch_array($result))
    {

    echo "<a href='popupmockup.php?categories=".urlencode($row_rsRings['categories']) . "'>".$row_rsRings['thumbnails']."</a>";


    }
    ?>

    <p>&nbsp;</p>
    </div>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="productdescription" -->
    <div id="mainContent">

    <!--the below items such as size, colour etc, no longer are drawn from the database-->
    <?php
    $size = strtolower(mysql_real_escape_string($_POST['size']));
    $itemColour=$row_rsRings['colour'];
    $productID=$itemID.$itemColour.$size;
    ?>
    <?php echo $productID?>
    <h2 align="center"><?php echo $row_rsRings['product name']; ?></h2>
    <table width="530" class="greytextcentered">
    <tr>
    <th width="91" height="30" align="left" scope="col"><span class="style7">price:&nbsp;</span></th>
    <th colspan="3" align="left" scope="col"><?php echo $row_rsRings['price']; ?></th>
    <th width="138" colspan="2" rowspan="3" scope="col"><a href="&quot;http://www.beanstream.com/scripts/cart/add_item.asp?merchant_id=1082000&amp;itemcode=<?php echo $productID?>&amp;prod_name=['description']&amp;return=http://www.burapa.ca/index.php&quot;&gt;"><img src="root folder/images/headerandfooter/purplebuttonlightershadow140x70.jpg" alt="buy now button" width="140" height="70" /></a></th>
    </tr>
    <tr>
    <td height="30" align="left"><span class="style7">size:&nbsp;</span></td>
    <td colspan="3" align="left"><?php echo $row_rsRings['size']; ?></td>
    </tr>
    <tr>
    <td height="30" align="left"><span class="style7">code:&nbsp;</span></td>
    <td colspan="3" align="left"><?php echo $row_rsRings['itemcode']; ?></td>
    </tr>


    <tr>
    <td colspan="6" align="left"><p><span class="style7">description:</span> <?php echo $row_rsRings['description']; ?></p>
    <p>&nbsp;</p></td>
    </tr>
    <!--this form does not function, although the HTML aspects of it still appear - the button does not even show-->
    </table>
    <form id="form1" name="form1" method="post" action="productdescriptionpage.php">
    <p>Size
    <?php
    $static = "Select Size";
    if ($row_rsRings['size'] != "") {
    $myfields = $row_rsRings['size'];
    $myarray = explode(";", $myfields);
    ?>
    <select name="size">
    <?php if ($static != "") {
    ?>
    <option value="" selected="selected"><?php echo $static ?></option>
    <?php }
    for ($i=0; $i<sizeof($myarray); $i++) {
    ?>
    <option value="<?php echo $myarray[$i] ?>"<?php $i==0 && $static=="" ? print " selected" : print ""; ?>> <?php echo $myarray[$i] ?>
    </option>
    <?php } ?>
    </select>
    <?php } else {
    echo "<input type=\"hidden\" name=\"size\">";}
    ?>
    </p>
    <p>
    <input type="submit" name="button" id="button" value="Submit" />
    </p>
    </form>
    <?php
    $size = strtolower(mysql_real_escape_string($_POST['size']));
    echo "<b>You have selected <i>$size</i></b>";
    ?>
    </div>
    <!-- end #mainContent -->
    <!-- InstanceEndEditable -->
    <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
    <div class="homefooter" id="footer">
    <p>copyright 2008 Burapa Asian Perspective&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contact&nbsp;&nbsp;<img src="root folder/images/headerandfooter/Mail1.gif" alt="contact" width="38" height="23" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phone: 613-296-0963</p>
    <!-- end #footer --></div>
    <!-- end #container --></div>
    <script type="text/javascript">
    <!--
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
    //-->
    </script>
    </body>
    <!-- InstanceEnd --></html>
    <?php
    mysql_free_result($rsRings);
    ?>

    THanks again!
    Last edited by lozza; 09-10-2008 at 03:26 PM. Reason: erased connect data

  12. #12
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: specific data query issue

    I took a quick look and wasn't able to determine the cause. I will try and look more this evening, but I cannot guarantee it. We are an evacuation center for Hurricane Ike, so I won't be very reliable for the next few days as our resources (gas, etc.) begin to dwindle and we prepare for the onslaught.

  13. #13
    lozza's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    11

    Re: specific data query issue

    Hey Jthayne - no worries at all, you've been more than helpful so far! Hope all goes well with the hurricane (as in, hope it is not a really bad one). Look forward to hearing your take on the problem.

    Good luck!



Tags for this Thread