Alexhoward Posted June 11, 2008 Share Posted June 11, 2008 Hi Guys, I have a drop down populated from mysql... (these things have taken over all my time lately! ) Some how thou i would like to ignore certain values. e.g. say the table includes - a, b, c, d, e ... I would like to pull everything back apart from d can anyone help? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/109800-solved-ignore-value-from-mysql/ Share on other sites More sharing options...
wildteen88 Posted June 11, 2008 Share Posted June 11, 2008 Just use a condition in your where clause eg: SELECT * FROM your_table WHERE some_field !='d' Quote Link to comment https://forums.phpfreaks.com/topic/109800-solved-ignore-value-from-mysql/#findComment-563479 Share on other sites More sharing options...
Alexhoward Posted June 11, 2008 Author Share Posted June 11, 2008 Hi, Thanks for teh reply, i've just gave this a go and it's ignoring it, but now it's not bring everything else back, only one...? Quote Link to comment https://forums.phpfreaks.com/topic/109800-solved-ignore-value-from-mysql/#findComment-563482 Share on other sites More sharing options...
.josh Posted June 11, 2008 Share Posted June 11, 2008 Post some code please, particularly your query string. Quote Link to comment https://forums.phpfreaks.com/topic/109800-solved-ignore-value-from-mysql/#findComment-563486 Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 Are you retrieving the results properly? Show us your code. Quote Link to comment https://forums.phpfreaks.com/topic/109800-solved-ignore-value-from-mysql/#findComment-563488 Share on other sites More sharing options...
Alexhoward Posted June 11, 2008 Author Share Posted June 11, 2008 Hi Guys, Thanks for taking the time to look at this <?php //Select Category include("config.php"); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); //select the database mysql_select_db($db) or die ("Could not select database because ".mysql_error()); echo'<form><select name="cat" style="width:160px;">'; $res=mysql_query("select distinct cat from category WHERE cat !='Add_Category..?' order by cat"); if(mysql_num_rows($res)==0) echo "there is no data in table.."; else for($i=0;$i<mysql_num_rows($res);$i++) { $row=mysql_fetch_assoc($res); $selected = @$_GET['cat'] == $row['cat'] ? "selected" : ""; echo"<option value=".$row['cat']." $selected>".$row['cat']."</option>"; } echo'</select>'; echo'<input type="submit" value="select"></form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/109800-solved-ignore-value-from-mysql/#findComment-563493 Share on other sites More sharing options...
wildteen88 Posted June 12, 2008 Share Posted June 12, 2008 I'd recommend you to change for($i=0;$i<mysql_num_rows($res);$i++) { $row=mysql_fetch_assoc($res); $selected = @$_GET['cat'] == $row['cat'] ? "selected" : ""; echo"<option value=".$row['cat']." $selected>".$row['cat']."</option>"; } to while($row = mysql_fetch_assoc($res)) { $selected = ((isset($_GET['cat']) && $_GET['cat'] == $row['cat']) ? ' selected="selected"' : null; echo '<option value="'.$row['cat'].'"' . $selected .'>'.$row['cat']."</option>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/109800-solved-ignore-value-from-mysql/#findComment-564141 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.