Jump to content

nicelad_uk

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

nicelad_uk's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your help with this again, the only problem is the 2 new statements you have put in dont work on my script. The first one changes the select statement to WHERE manufacturer = "selected" and the second one doesnt show any results and doesnt change the select statement. Any ideas?
  2. Thanks jvrothjr, you've been a great help. All I need to do now is make it so when the page refreshes, it selects the actual selection that was made. At the minute, the menu just goes back to the 1st option in there, any ideas? <?php include 'header.php' ; ?> <!-- This is the main content table --> <table width="800" bgcolor="#808080" border="0" cellpadding="0" cellspacing="0" align="center" class="main"> <tr class="mainmargin"> <td> <br /><br /> <?php $username="root"; $password=""; $database="test"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $dropquery="SELECT DISTINCT(manufacturer) FROM products;"; $dropdownlist=mysql_query($dropquery); $query = 'SELECT * FROM products WHERE manufacturer = "'.$_POST['myselect'].'"'; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo $query; echo "<form name='form1' method='post' action='$PHP_SELF'>"; echo "<select name='myselect' onchange=form1.submit()>"; while($row=mysql_fetch_assoc($dropdownlist)) { echo "<option value=".$row[iD]; if ($_POST[myselect]==$row[iD]) {echo $row[manufacturer];} echo ">".$row[manufacturer]."</a></option>"; } echo "</select><br /><br />"; echo "</form>"; $i=0; while ($i < $num) { $prod_name=mysql_result($result,$i,"prod_name"); $category=mysql_result($result,$i,"category"); $manufacturer=mysql_result($result,$i,"manufacturer"); $description=mysql_result($result,$i,"description"); $retail_price=mysql_result($result,$i,"retail_price"); $picture=mysql_result($result,$i,"picture"); $stock_code=mysql_result($result,$i,"stock_code"); echo "Product: <b>$prod_name</b><br> Category: $category<br> Manufacturer: $manufacturer<br> Description: $description<br> Retail Price: £$retail_price<br> <img src=\"productimages/" . $picture . "\" border=0 alt=\"" . $picture . "\"><br> Code: $stock_code<br><hr><br>"; $i++; } ?> <br /><br /> </td> </tr> </table> <?php include 'footer.php' ; ?>
  3. Hello, I managed to get it to show something, but not the actual result that is selected. Can anyone point me in the right direction for this, so the select statement changes to what it is selected from the drop down menu, I think its something to do with the $_POST but I cant figure it out Thanks
  4. Just give this a try for me, dont know if it will work on MYSQL: $years= "SELECT DISTINCT(year) FROM table1,table2"; $qyears = mysql_query($years) or die(mysql_error()); ?> <select name="years"> <?php //don't know what do do here while($row = mysql_fetch_assoc($qyears)) { ?> <option value="<?php echo $row[$qyears]; ?>"><?php echo $row[$qyears]; ?></option> <?php } } ?> </select> [/quote]
  5. Thank for that, thats got the auto submitting working a treat, the only thing I cant do is get it to remember what selection was selected and query it in a SELECT statement. I had a bash at it last night and thoght I had it with your auto submit added, but no Could anyone point me in the right direction with this.... <?php include 'header.php' ; ?> <!-- This is the main content table --> <table width="800" bgcolor="#808080" border="0" cellpadding="0" cellspacing="0" align="center" class="main"> <tr class="mainmargin"> <td> <br /><br /> <?php $username="root"; $password=""; $database="test"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $dropquery="SELECT DISTINCT(manufacturer) FROM products;"; $dropdownlist=mysql_query($dropquery); $query = 'SELECT * FROM products WHERE manufacturer = "'.$_POST['myselect'].'"'; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<form name='form1' method='post'>"; echo "<select name='myselect' onchange=form1.submit()>"; while($row=mysql_fetch_assoc($dropdownlist)) { echo "<option value=".$row[iD]; if ($myselect==$row[iD]) {echo " SELECTED";} echo ">".$row[manufacturer]."</a></option>"; } echo "</select><br /><br />"; echo "</form>"; $i=0; while ($i < $num) { $prod_name=mysql_result($result,$i,"prod_name"); $category=mysql_result($result,$i,"category"); $manufacturer=mysql_result($result,$i,"manufacturer"); $description=mysql_result($result,$i,"description"); $retail_price=mysql_result($result,$i,"retail_price"); $picture=mysql_result($result,$i,"picture"); $stock_code=mysql_result($result,$i,"stock_code"); echo "Product: <b>$prod_name</b><br> Category: $category<br> Manufacturer: $manufacturer<br> Description: $description<br> Retail Price: £$retail_price<br> <img src=\"productimages/" . $picture . "\" border=0 alt=\"" . $picture . "\"><br> Code: $stock_code<br><hr><br>"; $i++; } ?> <br /><br /> </td> </tr> </table> <?php include 'footer.php' ; ?>
  6. From what I understand thats a relative path, an absolute path would have the address in like http://www.yourhostname.com/path1/path2/path3.php. Relative path would be like /path1/path2/path3.php. Someone correct me if Im wrong though
  7. Thanks jvrothjr, I don't know how to get this to reload the results though, this is the problem I'm having, its me that doesnt really know what im doing, id be better leaving it to the pros, but I only need this page. Could anyone help further, making this so when the drop down menu is selected, it brings through the results. This is what I have in total: <?php include 'header.php' ; ?> <!-- This is the main content table --> <table width="800" bgcolor="#808080" border="0" cellpadding="0" cellspacing="0" align="center" class="main"> <tr class="mainmargin"> <td> <br /><br /> <?php $username="root"; $password=""; $database="test"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM products ORDER BY prod_name;"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<select name=myselect>"; while($row=mysql_fetch_assoc($result)) { echo "<option value=".$row[iD]; if ($myselect==$row[iD]) {echo " SELECTED'";} echo ''>".$row[manufacturer]."</a></option>"; } echo "</select><br /><br />"; $i=0; while ($i < $num) { $prod_name=mysql_result($result,$i,"prod_name"); $category=mysql_result($result,$i,"category"); $manufacturer=mysql_result($result,$i,"manufacturer"); $description=mysql_result($result,$i,"description"); $retail_price=mysql_result($result,$i,"retail_price"); $picture=mysql_result($result,$i,"picture"); $stock_code=mysql_result($result,$i,"stock_code"); echo "Product: <b>$prod_name</b><br> Category: $category<br> Manufacturer: $manufacturer<br> Description: $description<br> Retail Price: £$retail_price<br> <img src=\"productimages/" . $picture . "\" border=0 alt=\"" . $picture . "\"><br> Code: $stock_code<br><hr><br>"; $i++; } ?> <br /><br /> </td> </tr> </table> <?php include 'footer.php' ; ?>
  8. Thanks, where is the best place to add this? I tried before the </select> but get the following error: Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in D:\Server\mncsolutions.com\database.php on line 31 Line 31 being if ($myselect==$row[iD]) {echo " SELECTED'";
  9. Sounds daft, but is your server PHP enabled? Some arent
  10. Hello everyone, I was wondering if anone could help with a query i'm finding hard, but I guess you will find easy. I'm rather new to PHP but in my job I use SQL to maintain DB2 databases, so I ok in that I guess. I'm developing a website and at the minute I'm trying to show a list of products I have for sale and have these stored in a database. At the moment they have the following fields: PROD_NAME MANUFACTURER PRICE DESCRIPTION STOCK_CODE I have used the following code to get the details to populate a 'Drop Down Menu': mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM products ORDER BY prod_name;"; $result=mysql_query($query); mysql_close(); /* Create The Drop Down Menus */ echo "<select name=myselect>"; while($row=mysql_fetch_assoc($result)) { echo "<option value=$row[iD] print ($myselect==$row[iD]) ? 'SELECTED' : ''>$row[manufacturer]</a></option>"; } echo "</select>"; And then some PHP Code to show the results from the above SELECT statement. What I am trying to do is depending what Manufacturer is selected from the Drop Down Menu, this then changes the select statment to show only the results with the Manufacturer selected. Thanks for reading this and I hope you can help. Rich
×
×
  • 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.