Jump to content

shure2

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

shure2's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thanks for showing me a good technique and the right join, however there is no column lead.prodid so i get an error. the joining fields are - option.leadid - option.prodid do I need to somehow join both tables to the 'option' table? (i got a Not unique table/alias: 'option' when i tried it, obviously im doing it wrong!)
  2. well I need to display the product name, product code and product category for one product id, achieving what I have above but without the entries being repeated over an over. I have started to have a try at just a join, but get an error: $query = "SELECT product.prodid, product.prodname, product.prodcode, product.prodcategory FROM product, lead JOIN lead ON product.prodid ON lead.prodid JOIN `mct.`option` ON lead.leadid = `mct.`option`.leadid WHERE option.type = 'product' AND option.optionnumber = 1 AND option.leadid = 1 AND product.prodid = option.partid"; $result = @mysql_query($query, $connection) or die ("Unable to perform query.<br />$query<br/>".mysql_error()); Error: Not unique table/alias: 'lead' thanks so much for your help so far
  3. thanks! what sort of join type would you advise me to use?
  4. Hi, I want to select some product details and put them into a table. I do this by having a lead table, option table, and product table. There can be many options to a lead (so i store leadid in the option table), and many products to an option (i store the prodid in the option table) PROBLEM: I have the following statement, which somewhat works, but the same products are outputted into the table an infinite amount of times (see below for example table) Name Code Category Honda Jazz HJ1 Car Ducati monster DC1 Motorbike Honda Jazz HJ1 Car Ducati monster DC1 Motorbike Honda Jazz HJ1 Car Ducati monster DC1 Motorbike Honda Jazz HJ1 Car Ducati monster DC1 Motorbike Honda Jazz HJ1 Car Ducati monster DC1 Motorbike etc P.S. is 'option' a reserved name in sql, because when im referencing the option table I need to use my database name with it <?php require "connect.php"; $query = "SELECT product.prodname, product.prodcode, product.prodcategory FROM product, lead, `mct`.`option` WHERE option.leadid = 1 AND option.optionnumber = 1 AND product.prodid = option.partid AND option.type = 'product'"; $result = @mysql_query($query, $connection) or die ("Unable to perform query.<br />$query<br/>".mysql_error()); ?> <table border="1"> <tr> <th>Name</th> <th>Code</th> <th>Category</th> </tr> <?php while($row= mysql_fetch_array($result)) { ?> <tr> <td ><?php echo $row['prodname']?></td> <td ><?php echo $row['prodcode']?></td> <td ><?php echo $row['prodcategory']?></td> </tr> <?php } ?> </table>
  5. I have created a listbox that populates the product names on a seperate page (seen below), but I want the two list boxes to be on the same page, I don't mind if the page refreshes when the category is selected (to avoid javascript) $query = "select * from product where prodcategory = '".$_GET['prodcategory']."' and userid = '".$_SESSION['userid']."'"; $result = @mysql_query($query, $connection)or die ("Unable to perform query<br>$query"); ?> <select name="dddd"> <?php while($row=mysql_fetch_array($result)) { echo '<option value="'.$row['prodid'].'">'.$row['prodname'].'</option>'; echo 'hello'; } //exit(); ?> </select>
  6. Hi, I have a list box that reads category names from the category table. I want to select a category name and populate the product list box with the names of products in the category. I have the code to populate the category listbox and the sql to populate the product listbox, but i'm not sure how to put them together (I guess calling a seperate php file and then passing the values back somehow using a form? - probably wrong!) CODE FOR SELECTING PRODUCT CATEGORY: <p>Select the product category:<br /> <select name="prodcategory" onchange="javascript: form.action='reportmanual_getcategoryproducts.php';"> <?php $selectProductCatQuery = "SELECT * FROM category where userid = '".$_SESSION['userid']."' ORDER BY catname"; $selectProductCatResult = mysql_query($selectProductCatQuery) or die(mysql_error()); while($row1ProductCat=mysql_fetch_array($selectProductCatResult)) { echo '<option value="'.$row1ProductCat['catname'].'">'.$row1ProductCat['catname'].'</option>'; } ?> </select> CODE FOR SELECTING PRODUCT (need help on this bit please): $query = "SELECT * FROM product where userid = '".$_SESSION['userid']."' and categoryname = '".$_GET['prodcategory']."' ORDER BY $result = mysql_query($query) or die(mysql_error()); //I need to get the values from the sql and pass them back to the product select box i have
  7. yes you are right, i started changing the code to reflect your advice but missed that variable, could you help me change the code like the other list box so that the session['leadname'] appears in the listbox as a default.
  8. Hi, This is the 1st time I have used a for each loop and I'm having a few issues. I have a leadproductdetail table that with the following structure: LEADPRODUCTDETAIL(leadproddetailid(pk), leadid, leadprodnumber, leadproddetailfield, leadproddetailvalue) It seems messy but all it really shows is the number of the product (say 1) and the product fields such as depth, height and their values. The leadid is in the table as a foreign key because there can be many leadproductdetails to one lead, basically a lead can have a number of products, and each of those products has details such as height, depth and a value. I am trying to use a for each loop to display the number of the product and the associated details with that product. So far I have the below code, but the while loop within the for loop only runs once and I need it to echo out the leadproddetailfield and leadproddetailvalue for each specific product number. $query = "select * from leadproductdetail where userid = '".$_SESSION['userid']."'"; $result = @mysql_query($query, $connection) or die ("Unable to perform query.<br />$query<br/>".mysql_error()); $query2 = "select * from leadproductdetail"; $result2 = @mysql_query($query2, $connection) or die ("Unable to perform query.<br />$query2<br/>".mysql_error()); $row1 = @mysql_num_rows($result2); ?> <?php for ($i=1; $i<=$row1; $i++) { echo $i //$i can represent the product number ?> <table border="1"> <tr> <th >Detail</th> <th >Value</th> </tr> <?php while($row= mysql_fetch_array($result)) //I need to have a condition like 'where leadprodid = $i so that in the 1 loop only the details and values are shown for the relevant product) { ?> <tr> <td><?php echo $row['leadproddetailfield']?></td> <td><?php echo $row['leadproddetailvalue']?></td> </tr> <?php } ?> </table> <?php }?> The output should look like this: Product number: 1 <table> Detail Value ***** ******** ****** ****** **** ***** </table> Product number: 2 <table> Detail Value ***** ******** ****** ****** **** ***** </table> etc
  9. thank you for the advice and better technique, I modified my code and it works great, however I have a combo box which is slightly different and I'm struggling to do what I have with you code above to it. <select name="leadid" onchange="showLeadName()"> <?php $userID = mysql_real_escape_string($_SESSION['userid']); $query = "SELECT * FROM lead where userid = '{$userID}' ORDER BY leadname"; $result = mysql_query($selectLeadQuery) or die(mysql_error()); while($record=mysql_fetch_array($result)) { ?> <?php echo '<option value="'.$record['leadid'].'">'.$record['leadname'].'</option>'; ?> <?php } ?> </select>
  10. I solved it by putting the value into a session variable when its added to the database and then used the following code: <select name="leadprodcategory"> <?php $selectLeadProductCatQuery = "SELECT * FROM category where userid = '".$_SESSION['userid']."' ORDER BY catname"; $selectLeadProductCatResult = mysql_query($selectLeadProductCatQuery) or die(mysql_error()); while($row1LeadProductCat=mysql_fetch_array($selectLeadProductCatResult)) { echo '<option value="' . $row1LeadProductCat['catname'].'"'; if( $row1LeadProductCat['catname'] == $_SESSION['leadProductCategory'] ) { //change 'select_name' to the value of your <select name=" echo ' selected="selected"'; } echo '>' . $row1LeadProductCat['catname'] . '</option>'; } ?> </select> hope this is useful for someone else!
  11. Hi, I have scoured the net and can't find an answer so I wondered if you guys can help. I have a combo box that selects data from a database, I can then add the selection of the combo box and other fields to another table, however when I do this with php the page refreshes and the value of the combo box changes back to the default order (where I want it to show the option I just added to the database) I have tried the below code, theoretically I thought it might work but it doesn't (the leadProductCategory is the combo box selection that I add to the database - it is set in the php file where I add to the database). $selectLeadProductCatQuery = "SELECT * FROM category where userid = '".$_SESSION['userid']."' ORDER BY .'".$_SESSION['leadProductCategory']."'; $selectLeadProductCatResult = mysql_query($selectLeadProductCatQuery) or die(mysql_error()); while($row1LeadProductCat=mysql_fetch_array($selectLeadProductCatResult)) { echo '<option value="'.$row1LeadProductCat['catname'].'">'.$row1LeadProductCat['catname'].'</option>'; }
  12. thanks for your advice, do you have any advice where I can start to do this in ajax or any similar examples?
  13. Hi, I am using javascript to populate a number of text boxes based on the data item selected in the 1st combo box. I am now working on making the selection of that combo box populate another combo box with items from another table. I can hard the sql code for the 2nd combo box so that when I select an option it populates more text boxes, but want the contents of the 2nd combo box to dynamically change depending on the selection of the 1st box. I would like this to do it without refreshing the page after each 1st combo box selection. any help would be massively appreciated as I been stuck on this for a while. The 2nd box does not populate with the below code as I guess the variable isn't populated, I can put '1' in and it selects products with that prodid, but as explained above i'd like it to read the prodid from the 1st combo box. <?php require "session_logincheck.php"; function selectProductAndPopulate() { require "product_details.php"; require "connect.php"; ?> <html> <script type="text/javascript"> var prodDetailsArray = new Array(); var prodSpecificDetailsArray = new Array(); <?php $selectProductQuery = "SELECT * FROM product ORDER BY prodname"; $selectProductResult = mysql_query($selectProductQuery) or die(mysql_error()); // build javascript array while ($prodrow1=mysql_fetch_array($selectProductResult)) { echo 'prodDetailsArray['.$prodrow1['prodid'].'] = new Array();'; echo 'prodDetailsArray['.$prodrow1['prodid'].']["prodcompid"] = "'.$prodrow1['prodcompid'].'";'; echo 'prodDetailsArray['.$prodrow1['prodid'].']["prodcode"] = "'.$prodrow1['prodcode'].'";'; echo 'prodDetailsArray['.$prodrow1['prodid'].']["prodname"] = "'.$prodrow1['prodname'].'";'; echo 'prodDetailsArray['.$prodrow1['prodid'].']["prodcategory"] = "'.$prodrow1['prodcategory'].'";'; echo 'prodDetailsArray['.$prodrow1['prodid'].']["produnitprice"] = "'.$prodrow1['produnitprice'].'";'; echo 'prodDetailsArray['.$prodrow1['prodid'].']["prodphoto"] = "'.$prodrow1['prodphoto'].'";'; echo 'prodDetailsArray['.$prodrow1['prodid'].']["proddescription"] = "'.$prodrow1['proddescription'].'";'; } $selectProductDetailsQuery = "SELECT * FROM productdetail ORDER BY proddetfield"; $selectProductDetailsResult = mysql_query($selectProductDetailsQuery) or die(mysql_error()); // build javascript array while ($proddetrow1=mysql_fetch_array($selectProductDetailsResult)) { echo 'prodSpecificDetailsArray['.$proddetrow1['proddetid'].'] = new Array();'; echo 'prodSpecificDetailsArray['.$proddetrow1['proddetid'].']["proddetvalue"] = "'.$proddetrow1['proddetvalue'].'";'; } ?> function showProductName() { var prodid = document.prodform.prodid.value; document.prodform.prodcompid.value = prodDetailsArray[prodid]["prodcompid"]; document.prodform.prodcode.value = prodDetailsArray[prodid]["prodcode"]; document.prodform.prodname.value = prodDetailsArray[prodid]["prodname"]; document.prodform.prodcategory.value = prodDetailsArray[prodid]["prodcategory"]; document.prodform.produnitprice.value = prodDetailsArray[prodid]["produnitprice"]; document.prodform.prodphoto.value = prodDetailsArray[prodid]["prodphoto"]; document.prodform.proddescription.value = prodDetailsArray[prodid]["proddescription"]; } function showProductSpecName() { var proddetid = document.prodform.proddetid.value; document.prodform.editproddetvalue.value = prodSpecificDetailsArray[proddetid]["proddetvalue"]; } window.onload=function() { showProductName(); //showProductSpecName(); } </script> <form name="prodform"> <div id="topl"> <div class ="toplpost"> <h1 class="title"> Select a product </h1> <div class="entry"> <select name="prodid" onchange="showProductName()"> <?php $selectProductQuery = "SELECT * FROM product where userid = '".$_SESSION['userid']."' ORDER BY prodname"; $selectProductResult = mysql_query($selectProductQuery) or die(mysql_error()); while($prodrow1=mysql_fetch_array($selectProductResult)) { echo '<option value="'.$prodrow1['prodid'].'">'.$prodrow1['prodname'].'</option>'; $productID = $prodrow1['prodid']; } ?> </select> </div> </div> </div> <div id="topm"> <div class ="topmpost"> <h1 class="title"> Select a product detail </h1> <div class="entry"> <select name="proddetid" onchange="showProductSpecName()"> <?php $selectProductDetailsQuery = "SELECT * FROM productdetail where prodid = '".$productID."' ORDER BY proddetfield"; $selectProductDetailsResult = mysql_query($selectProductDetailsQuery) or die(mysql_error()); while($proddetrow1=mysql_fetch_array($selectProductDetailsResult)) { echo '<option value="'.$proddetrow1['proddetid'].'">'.$proddetrow1['proddetfield'].'</option>'; } ?> </select> </div> </div> </div> <?php productDetails(); ?> </form> </html> <?php }?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.