php - MySQL Select box Duplicate - Duplicating one field option but not the other (Queries Identical) -


i creating database upload system - using select box limit number of categories added database.

<select name="category"> <?php $conn = mysqli_connect("localhost", "blah", "blah") or die ("no connection");  mysqli_select_db($conn, "upload") or die("db not open");  $query = "select category details group category";  $result = mysqli_query($conn, $query) or die("invalid query");  while($row = mysqli_fetch_array($result)) {                 echo "<option value=\"" . $row[0] . "\">" . $row[0] . "</option>";                 }                             mysqli_close($conn);             ?>      </select>      <select name="reaction">             <?php             $conn = mysqli_connect("localhost", "blah", "blah") or die ("no connection");              mysqli_select_db($conn, "upload") or die("db not open");              $query = "select reaction details group reaction";              $result = mysqli_query($conn, $query) or die("invalid query");              while($row = mysqli_fetch_array($result)) {                 echo "<option value=\"" . $row[0] . "\">" . $row[0] . "</option>";                 }                             mysqli_close($conn);             ?> 

while 2 queries same - category (the top query) stopping form repeating multiple data db. when database - finding (which have hunch may problem).

insert `details` (`name`, `category`, `reaction`, `photo`, `date_added`) values ('mase laughing', 'funny', 'laugh\n', 'mase-laugh.gif', '2013-05-01 07:16:26'), ('movie wink', 'cheeky', 'wink\n', 'movie-wink.gif', '2013-05-02 12:33:12'), ('tarzan giggle', 'funny', 'wink\r\n', 'tarzan-laugh.gif', '2013-05-02 01:33:00'); 

beside reactions getting these strange \r\n letters - have ideas? in advance.

these "carriage return" (\r) , "newline" (\n) characters. these commands telling computer go end of line , new line.

to stop page showing duplicate categories, change this:

$query = "select category details group category"; 

into this:

$query = "select distinct category details group category"; 

it not prevent database storing duplicate categories (which no want, otherwise able save 1 (one) line of details per categorie, prevent dropdown (select) showing duplicates. so, details showed, give dropdown values 'funny' , 'cheecky', both of them showing once. add "distinct" other sql statement have reactions de-duplicated too:

$query = "select distinct reaction details group reaction";  

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -