<?php
$mysqli = mysqli_connect***;
$result = mysqli_query($mysqli, 'SELECT * FROM componnets LEFT JOIN fill ON componnets.id=fill.Uid') or die(mysqli_error(mysqli));
$resultCOM = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));
while ($rowCOM = mysqli_fetch_array($resultCOM)) {
echo "<input type='hidden' name='compo' value='".$rowCOM['compon']."'>".$rowCOM['compon']."";
echo "<select name='fill'>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='".$row['num']."'>".$row['num']."</option>";
}
echo "</select>";
}
// Free result set
mysqli_free_result($result);
/* close connection */
$mysqli->close();
?>
the question is this, i need to combine between 2 sql.
the result i need is that:
<input type='hidden' name='compo' value='decod'>decod
<select name='fill'><option value='100'>100</option>
</select>
<input type='hidden' name='compo' value='rg5.9'>rg5.9
<select name='fill'><option value='100'>100</option>
<select name='fill'><option value='100'>200</option>
<select name='fill'><option value='100'>300</option>
</select>
i try all combins and nothing..
the output in now is like this
<input type='hidden' name='compo' value='decod'>decod
</select>
<input type='hidden' name='compo' value='rg5.9'>rg5.9
<select name='fill'><option value='100'>100</option>
<select name='fill'><option value='100'>300</option>
</select>
the mysql is bulld like this
fill - num uid
100 3
300 1
componnets - id compon
1 decod
2 rg59
3 rg6
thx for help.
Related
I have an issue in a simple PHP MySQL project. When I try to fetch a record from a select option, it only gives me the id. I want the value from the select to be passed too.
<form class="form-style-9" method="POST" action="function.php?type=updatedistrict">``
<ul>
<li>ID:
<input type="hidden" name="dist_id" class="field-style field-full align-none" value="<?php echo $ids;?>" readonly />
</li>
<li>District Name:
<input type="text" name="name" class="field-style field-full align-none" value="<?php echo $names;?>" />
</li>
<li>Postal Code:
<input type="text" name="code" class="field-style field-full align-none" value="<?php echo $codes;?>"/>
</li>
<li>Province
<select name="province_id" class="form-control">
<option value="">Select Province</option>
<?php
$sql = mysqli_query($conn, "SELECT id, province From province");
$row = mysqli_num_rows($sql);
while ($row = mysqli_fetch_array($sql)){
echo "<option value='". $row['id'] ."'>" .$row['province'] ."</option>" ;
}
?>
</select>
<li>
<input type="submit" value="Update" name="submit" />
</li>
</ul>
</form>
This is the update function code:
case 'updateprovince':
if (isset($_POST['submit'])) {
$id = $_POST['dist_id'];
$prov_id= $_POST['province_id'];
$query=$conn->query("UPDATE province SET province='$prov_id' where id='$id'");
if ($query) {
echo '<script> window.location.replace("province.php");
</script>';
}
else
{
echo "issue";
}
}
break;
You can post your province name instead of the id this way:
echo "<option value='". $row['province'] ."'>" .$row['province'] ."</option>" ;
Your $_POST['province_id'] will then contain the province value instead of the current id.
A way to pass along both the id and the value (in case you need to retain the id for some additional processing) through your option would be this:
echo "<option value='". $row['id'] . '|'. $row['province'] ."'>" .$row['province'] ."</option>" ;
Then after the submit, you'd simply split the two by the '|' delimiter.
if (isset($_POST['submit'])) {
$id = $_POST['dist_id'];
$province = explode('|', $_POST['province_id']);
$province_id = $province[0]
$province_name = $province[1]
I am trying to create an advanced search system for a simple auction site I am building. I want to have a 'Mozilla Thunderbird' style search system where upon a certain option being selected in a form causes another form to appear with specific select options itself to allow a more narrow search.
For those unfamiliar with the search system I have attatched a picture which should hopefully help provide some context:
Mozilla Thunderbird Advanced Search
This is the code I have so far for this:
<html>
<body>
<?php {
$servername = "";
$username = "";
$password = "";
$dbname ="";
$conn = new mysqli($servername, $username, $password, $dbname);
if($conn->connect_error) {
die("connection failed: " . $conn->connect_error);
}
$sql = "SELECT DISTINCT `category` FROM `iBayItems`";
$Category = $conn->query($sql);
if($Category->num_rows > 0) {
echo "<h2>Advanced Search</h2>
<p>Searching for items where: </p>";
/*First parameters*/
echo "<form action='TestAdvanced.php' method='POST'>
<select name='advancedSearch'>
<option value=''>Select Search...</option>
<option value='TitleSearch'>Title</option>
<option value='CategorySearch'>Category</option>
<option value='PriceSearch'>Price</option>
<option value='AddressSearch'>Address</option>
<option value='TimeLeftSearch'>Time Left</option>
</select>
</form>";
(isset($_POST["advancedSearch"])) ? $searchOption = $_POST["advancedSearch"] : $searchOption="";
/*Operators for first parameters*/
/*Title Operators*/
if ($searchOption == '') {
} else if ($searchOption == 'TitleSearch') {
echo "<form>
<select name='TitleOperators'>
<option value=''>Select Operator...</option>
<option value='LIKE'>is</option>
<option value='NOT LIKE'>is not</option>
</select>
</form>";
echo "<form>
<input type='text' required pattern='[A-Za-z0-9]{0,42}' name='Title'>
</form>";
} else if($searchOption == 'CategorySearch') {
/*Category Operators*/
echo "<form>
<select name='CategoryOperators'>
<option value=''>Select Operator...</option>
<option value='LIKE'>is</option>
<option value='NOT LIKE'>is not</option>
</select>
</form>";
echo "<form>
<select name='Category'>
<option value=''>Select Category...</option>";
while($row = $Category->fetch_assoc()) {
echo "<option value='";
echo $row["category"];
echo "' required>";
echo $row["category"];
echo "</option>";
}
echo "</select>
</form>";
} else if($searchOption == 'PriceSearch') {
/*Price Operators*/
echo "<form>
<select name='PriceOperators'>
<option value=''>Select Operator...</option>
<option value='='>equals</option>
<option value='<='>less than or equal to</option>
<option value='>='>greater than or equal to</option>
<option value='<'>less than</option>
<option value='>'>greater than</option>
</select>
</form>";
echo "<form>
<input type='number' required name='price' min='0' step='0.01'>
</form>";
} else if($searchOption == 'AddressSearch') {
/*Address Operators*/
echo "<form>
<select name='AddressOperators'>
<option value=''>Select Operator...</option>
<option value='LIKE'>near to</option>
<option value='NOT LIKE'>not near</option>
</select>
</form>";
echo "<form>
<input type='text' placeholder='E.g. NR18 9JJ' required name='postcode' pattern='[A-Za-z0-9]{0,42}'>
</form>";
} else if($searchOption == 'TimeLeftSearch') {
/*Time Operators*/
echo "<form>
<select name='TimeOperators'>
<option value=''>Select Operator...</option>
<option value='='>equals</option>
<option value='<='>less than or equal to</option>
<option value='>='>greater than or equal to</option>
<option value='<'>less than</option>
<option value='>'>greater than</option>
</select>
</form>";
echo "<form>
<input type='number' required name='days' min='0' step='1'>
<p> days</p>
</form>";
} ?>
</body>
</html>
The problem I am having is getting the secondary forms to appear, I have tried using "noscript" with a submit form but this isn't really what I need as I don't want the page to reload everytime an option is selected.
I am quite new to PHP so have tried to do as much as I can through research, an understanding of HTML and coding practices and blind luck.
I have used these links so far to help me:
Using $_POST to get select option value from HTML
http://www.vasiljevski.com/blog/2012/01/17/how-to-set-the-selected-option-of-select-tag-from-the-php/
But alas these only got me so far.
As you can see from the picture Thunderbird allows you to have multiple possible searches, this is something I would like to implement myself after I have resolved the current issue I am having.
Any help that you can provide would be absolutely fantastic!
Alex
I am trying to create some code to do a list of components in mysql.
Something like this
decod - 1,2,3,4,5
and to make it in drop-down listlike this
decod (dorplist) 1
2
3
4
5
I tried this one:
<?php
$mysqli = mysqli_connect("host", "username", "password", "name");
$result = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));
while ($row = mysqli_fetch_array($result)) {
$org = str_replace("," , "'>", $row['fill']."");
$replace = str_replace("," , "
".$org."</option><option value='", $row['fill']."'>");
echo "<input type='hidden' name='compo' value='".$row['compon']."'>".$row['compon']."";
echo "<select name='fill'>";
echo "<option value='".$replace."'>".$replace."</option>";
echo "</select>";
}
// Free result set
mysqli_free_result($result);
/* close connection */
$mysqli->close();
?>
and do make it output to an XML
but I don't know how! I output like this
<input type='hidden' name='compo' value='DECODERS'>DECODERS
<select name='fill'>
<option value='1010'>20'>30'>40</option>
<option value='2010'>20'>30'>40</option>
<option value='3010'>20'>30'>40</option>
<option value='40'>'>1010'>20'>30'>40</option>
<option value='2010'>20'>30'>40</option>
<option value='3010'>20'>30'>40</option><option value='40'></option>
</select>
<input type='hidden' name='compo' value='DECODERS'>DECODERS
<select name='fill'>
<option value='10'>10</option>
</select>
First create the <select> outside the while loop. Then iterate over the rows to add the elements.
I'm not sure what you're trying to accomplish with your str_replace calls, so I removed them.
Something like this might get you started in the right direction:
<?php
$result = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));
echo "<select name='fill'>";
echo "<input type='hidden' name='compo' value='".$row['compon']."'>".$row['compon']."";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='".$row['fill']."'>".$row['fill']."</option>";
}
echo "</select>";
mysqli_free_result($result);
$mysqli->close();
?>
I need to edit values in the database using forms, i am successful with it, however,
<form method='post' action='update_inv.php?id=".$row['prod_id']."'><button type='submit'>Edit</button>
Wont work, it only throws prod_id=1 even when i press prod_id=2 and so on, it only shows 1.
and here in my update_inv.php i have this. but still, only prod_id=1. how do i fix it?
$itemid = $_GET['id'];
$qry = "SELECT * FROM inventory where prod_id = ".$itemid;
mysql_set_charset("UTF8");
$result = #mysql_query($qry);
Here are the complete codes for update_inv.php
<?php
session_start();
$conn = #mysql_connect("localhost","root","12148qx3er");
$db = #mysql_select_db("buybranded");
$itemid = $_GET['id'];
$qry = "SELECT * FROM inventory where prod_id = ".$itemid;
mysql_set_charset("UTF8");
$result = #mysql_query($qry);
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
echo "<div id='page-wrap'>
<h1>Edit a Product</h1>";
while ($row=mysql_fetch_array($result)){
$prodbrand = $row['prod_brand'];
$prodname = $row['prod_name'];
$prodcategory = $row['prod_category'];
$prodprice = $row['prod_price'];
$proddesc = $row['prod_desc'];
$prodpic = $row['prod_pic'];
$prodquantity = $row['prod_quantity'];
echo "<form enctype='multipart/form-data' method='post'>";
echo "<label for='prod_brand'>Product Brand:</label><br />
<input name='prod_brand' id='prod_brand' type='text' maxlength='150' class='col1' placeholder='Auto Complete Form' value='$prodbrand'/>
<div class='clear'></div>";
echo "<label for='prod_name'>Product name:</label><br />
<input name='prod_name' id='prod_name' type='text' maxlength='150' class='col1' value='$prodname'/>
<div class='clear'></div>";
echo "<label for='prod_category'>Category:</label><br />
<select name='prod_category' class='col1'>".$row['prod_category']."
<option>Select Category</option>
<option>Compression</option>
<option>Headwear</option>
<option>Shorts</option>
<option>Yoga</optino>
<option>Swimming</option>
<option>Fitness Training</option>
<option>Water Bottles</option>
<option>Sports Socks</option>
<option>Sports Bags</option>
<option>Protein Shaker</option>
<option>Gloves</option>
<option>Splash Guards</option>
<option>Massagers</option>
<option>Sun Blocks</option>
<option>Sports Cleaners</option>
</select>
<div class='clear'></div><br>";
echo "<label for='prod_price'>Price:</label><br />
<input name='prod_price' id='prod_price' type='text' maxlength='10' class='col1' value='$prodprice'/>
<div class='clear'></div>";
echo "<label for='prod_desc'>Description: (HTML Codes are allowed)</label><br />
<textarea name='prod_desc' id='prod_desc' class='col2'>".$row['prod_desc']."</textarea>
<div class='clear'></div>";
echo "<label for='prod_pic'>Upload Image:</label><br />
<input type='file' name='prod_pic' class='col2' value=''/>
<div class='clear'></div><br>";
echo "<label for='prod_quantity'>Quantity: </label><br />
<input name='prod_quantity' id='prod_quantity' type='text' maxlength='4' class='col2' value='$prodquantity'/>
<div class='clear'></div>";
echo "<form method='post' action='updating_inv.php?id=$itemid'><button>Update this Entry!</button>";
echo '<button>Go back</button>';
echo "</form>";
}
echo "</div>";
?>
You have method='post' and $itemid = $_GET['id'];
You should be using $itemid = $_POST['id'];
I get the following form my database which contain for year 2011 week 1 to week 20 and for year 2012 currently week 1. I want my user to choose 2011 first and then call the week to choose for example so that they dont choose for example week 10 and year 2012( which are not yet available).Any help most welcome.
<form name="myform" action="http://www.website.com/displaybook.php" method="get">
<select size="1" name="d">
<?
$sql=mysql_query("SELECT DISTINCT (Week) FROM data ORDER BY Week ASC");
while($row = mysql_fetch_array($sql))
{
echo "<option value='". $row['Week']."'>Week - ". $row['Week']."</option>";
}
?>
</select>
<select size="1" name="y">
<?
$sql=mysql_query("SELECT DISTINCT (Year) FROM data ORDER BY Year Desc");
while($row = mysql_fetch_array($sql))
{
echo "<option value='". $row['Year']."'>Season - ". $row['Year']."</option>";
}
?>
</select>
<input type="submit" value="Get data">
</form>
You need to put the year select before the day select... It will ajust the GET string automaticaly... Then, you create a little javascript to enable the second select when the first is selected, like this:
<script type="text/javascript">
function getWeek()
{
if (document.getElementById('y').value != '')
{
document.getElementById('d').disabled = ''; // this will enable the select
}
}
</script>
And in your HTML:
<form name="myform" action="http://www.website.com/displaybook.php" method="get">
<select size="1" name="y" onchange="getWeek()">
<?
$sql=mysql_query("SELECT DISTINCT (Year) FROM data ORDER BY Year Desc");
while($row = mysql_fetch_array($sql))
{
echo "<option value='". $row['Year']."'>Season - ". $row['Year']."</option>";
}
?>
</select>
<select size="1" name="d" id="d" disabled="disabled">
<?
$sql=mysql_query("SELECT DISTINCT (Week) FROM data ORDER BY Week ASC");
while($row = mysql_fetch_array($sql))
{
echo "<option value='". $row['Week']."'>Week - ". $row['Week']."</option>";
}
?>
</select>
<input type="submit" value="Get data">
</form>
Something like this should work great!