zazu Posted March 18, 2017 Share Posted March 18, 2017 Hello guys, I have a page named compare.php with two dropdown lists wich are populated with same values from a specific table. Now what i want to do is when a user is selecting one value from the first dropdown and another value from the secound dropdown to be redirected to a page lets say compare-items.php?id=1&id=2 and here in two different cols to get the values for the items, in the first col the values for the first item, and in the secound col the values from the sec item. How can i achive that? Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/303487-comparing-values-of-2-rows-from-the-same-table-in-one-page/ Share on other sites More sharing options...
NigelRel3 Posted March 18, 2017 Share Posted March 18, 2017 You will have to rename one of the fields as having 2 fields called id isn't that helpful. As for how to compare two values passed into a script - it would be better for you to attempt something and post where you are struggling rather than just ask 'how can I achieve that'! This is something fairly trivial and should be quick to work out from almost any example using parameters. Quote Link to comment https://forums.phpfreaks.com/topic/303487-comparing-values-of-2-rows-from-the-same-table-in-one-page/#findComment-1544343 Share on other sites More sharing options...
zazu Posted March 18, 2017 Author Share Posted March 18, 2017 I've done something similar but with only one select dropdown list. The code is below <form action="oras.php" method="get"> <div class="form-group"> <?php $result = mysqli_query($conn, "SELECT * FROM orase_disponibile ORDER BY titlu_oras ASC"); echo "<select name='id' id='id' class='form-control' required>"; echo "<option value='' disabled selected>Alegeti un oras...</option>"; while($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['id_oras'] . "'>" . $row['titlu_oras'] . "</option>"; } echo "</select>"; ?> </div> <p><button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> Caută dupa oras</button></p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/303487-comparing-values-of-2-rows-from-the-same-table-in-one-page/#findComment-1544351 Share on other sites More sharing options...
thinsoldier Posted March 18, 2017 Share Posted March 18, 2017 (edited) compare-items.php?id[]=1&id[]=2 $_GET['id'] will be an array with 2 items. Loop over those 2 Fetch the data and echo a table for each Use css to get the 2 tables to be side by side ( won't work well if any text in the table cells is multiple lines long for one id but only 1 line long for the other id ) Or use a more complicated html/php mixture to make a single table with all first cells from the first id and all second cells from the second id. Edited March 18, 2017 by thinsoldier Quote Link to comment https://forums.phpfreaks.com/topic/303487-comparing-values-of-2-rows-from-the-same-table-in-one-page/#findComment-1544359 Share on other sites More sharing options...
zazu Posted March 21, 2017 Author Share Posted March 21, 2017 <?php $result = mysqli_query($conn, "SELECT * FROM user_pers_juridica WHERE categorie='marci'"); echo "<form action='compara-marci.php' method='get'>"; echo "<div class='form-group'>"; echo "<select name='id' id='id' class='form-control'>"; echo "<option value='' disabled selected>Alegeti un judet...</option>"; while($row = mysqli_fetch_array($result)) { echo "<option value='" . $row['id_companie'] . "'>" . $row['nume_companie'] . "</option>"; } echo "</select>"; echo "</div>"; echo "<p><button type='submit' class='btn btn-primary'><i class='fa fa-search'></i> Caută</button></p>"; echo "</form>"; $result = mysqli_query($conn, "SELECT nume_companie FROM user_pers_juridica WHERE id_companie = '$id'"); while($row = mysqli_fetch_array($result)) { echo $row['nume_companie']; } ?> This is the code for the first select. Now after submit my url looks like this compara-marci.php?id=23. How can i add anouter select in this script and on submit button to show me the valus from the rows with the selected id and the url to be like compara-marci.php?id=2&id=3? Quote Link to comment https://forums.phpfreaks.com/topic/303487-comparing-values-of-2-rows-from-the-same-table-in-one-page/#findComment-1544453 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.