greggustin Posted September 2, 2006 Share Posted September 2, 2006 I have a small DB (id, groupID, title, MSG , etc)I have 2 forms of input (via html form = Both work as desired)one form does edit any field in GroupIDone form does add a new row (can put in any GroupID)[[[1st question - as of now - I have only 3 different GroupID possibilitieshow do I ensure the user does not have a typo and make a new (ie 4th GroupID)I do no want to use radio or drop down - because I do not want the users to see the 'names' of the other groups]]]2nd question:here is the hard part (for me)I have a small php page that prints a table using the field values in the DBthe ROW it picks is GroupID dependentit works GREAT // Except when there are TWO (2) rows with the SAME GroupIDso . . . . how do I just select the row that is MOST recent(ie had highest id# (which is auto increment)and yes, if there are 2 rows with the same GroupIDI get 2 tables (only want 1)The value of 'pick1' is determined by a small html radio form with 3 choices (one for each GroupID)I imagine the code to fix this is simple - but I have not deduced it yetthanks[code]<?phpinclude 'loginSTSAlertDB.php';$like=$_POST['pick1'];$server = MySQL_connect($host, $username, $password) or die(MySQL_error());$connection = MySQL_select_db($database, $server) or die (MySQL_error());$result = MySQL_query("SELECT * FROM Alert Where GroupID like '$like' ") ;while($row = MySQL_fetch_array( $result )){ echo " <table border=1 cellspacing=2 cellpadding=2 height=240>"; echo " <tr height=60>"; echo " <td colspan=3>" ; echo " <IMG SRC=$row[Logo]>"; echo " </td>"; echo " </tr>"; echo " <tr>"; echo " <td colspan=3>"; echo " $row[Title]"; echo " </td>"; echo " </tr>"; echo " <tr>"; echo " <td colspan=3>"; echo " $row[MSG]"; echo " </td>"; echo " </tr>"; echo " <tr>"; echo " <td>"; echo " OK"; echo " </td>"; echo " <td>"; echo " <A HREF=\"http://www.".$row[MsgURL]."\" target=_blank>More</A>"; echo " </td>"; echo " <td>"; echo " Later"; echo " </td>"; echo " </tr>"; echo"</table>";}[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 $result = MySQL_query("SELECT * FROM Alert Where GroupID like '$like' order by GroupID DESC") ;or$result = MySQL_query("SELECT * FROM Alert Where GroupID like '$like' order by GroupID ASC") ;change this while($row = MySQL_fetch_array( $result )){towhile($row = MySQL_fetch_assoc( $result )){if that issnt enough you can also limit the amount of information seen.limit 1or 1 - 3231231323 what ever ok. Quote Link to comment Share on other sites More sharing options...
greggustin Posted September 2, 2006 Author Share Posted September 2, 2006 well _ tried itstill made 2 tablesthen I changed the [i]order by GroupID ascii[/i] to[i]order by id asci [/i] (thinking GroupID (which is a text string) does not vary between like rows)any other guesses?pslooked up the string => "$row = MySQL_fetch_assoc"seems to return a row, not an array?guess that is good?alsoI do not understand his suggestion ==>[quote]if that issnt enough you can also limit the amount of information seen.limit 1or 1 - 3231231323 what ever ok.[/quote]thanks Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 2, 2006 Share Posted September 2, 2006 [code] ... ORDER by id DESC LIMIT 1";[/code]That'll display a single data set with the highest value of id. Quote Link to comment Share on other sites More sharing options...
greggustin Posted September 2, 2006 Author Share Posted September 2, 2006 ok will try . . . intuitively - would have guess [b] asc [/b]to pick the highest value?but guess intuition is not always the norm in programming ::) Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 2, 2006 Share Posted September 2, 2006 ASC = ascending order, so the first one would be the [i]lowest[/i] number. Quote Link to comment Share on other sites More sharing options...
greggustin Posted September 2, 2006 Author Share Posted September 2, 2006 worked !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :-* :-* :-* :-* Quote Link to comment Share on other sites More sharing options...
greggustin Posted September 2, 2006 Author Share Posted September 2, 2006 [quote author=AndyB link=topic=106640.msg426659#msg426659 date=1157220789]ASC = ascending order, so the first one would be the [i]lowest[/i] number.[/quote]understood - guess that means the whole array was 'analyzed' [i]BEFORE [/i] it was fetched (ie in the DB))I would have guess it had to be 'fetched' [i]before [/i]it was analyzed no matter - as long as it us understood -thanks againpsGREAT forum !!!!!!!!!! Quote Link to comment 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.