[PHP] Re: holding values in a select list on a form
I worked it out by doing something like this... "; $toplist = mysql_query("select * from wr_country where wr_country_enabled = 1 "); echo "Select\n"; while(list($topicid, $topics) = mysql_fetch_row($toplist)) { if ($topicid==$topic) { $sel = "selected "; } echo "$topics\n"; $sel = ""; } ?> "Mark Bayfield" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Some help please... > > I am creating a select list from a database, and I am trying to hold the > value of what has been selected by a user, while I do some error checking. > It is searching a mysql db to pull out the list. It will then need to pass > values back into the database. The code I am using is this... > > "; >print "Select"; >for ($index = 0; $index < mysql_num_rows($query); $index++) { >$row = mysql_fetch_row ($query) or die (mysql_error()); >print "$row[1]"; >} >echo ""; >?> > > If there is an easier way, let me know > > Mark > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] holding values in a select list on a form
Some help please... I am creating a select list from a database, and I am trying to hold the value of what has been selected by a user, while I do some error checking. It is searching a mysql db to pull out the list. It will then need to pass values back into the database. The code I am using is this... "; print "Select"; for ($index = 0; $index < mysql_num_rows($query); $index++) { $row = mysql_fetch_row ($query) or die (mysql_error()); print "$row[1]"; } echo ""; ?> If there is an easier way, let me know Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Catagory list
Thanks man, this works great... "Basil Groman" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > If I understand what you are looking for, this should work for you: > > $indent_str = ' '; > $qry = 'SELECT * FROM test ORDER BY category'; > $result = mysql_query($qry); > $current_category = ""; > while ($r = mysql_fetch_array($result)){ > if ($r['category'] <> $current_category){ > //first time category > $current_category = $r['category']; > printf("%s\n",$current_category); > } > //Now just print the title in this row > printf("$indent_str%s\n",$r['title']); > } > > basil > > At 11:58 AM 3/31/2001 +1000, Mark Bayfield wrote: > >Thanks for the code. Its not doing exactly what I want, but with a little > >modification is is kind of working. > >The one problem is that it is putting the Title first and the catagory > >second. so it is coming up with: > > > >title1 > >title2 > >catagory > >title3 > >title4 > >catagory1 > > > >and the last catagory is droping off. I have modified the code as such (if > >you can help so that the catagory is first and the titles second it would be > >a great help): > > > >$result = mysql_query ("SELECT * from article ORDER BY catagory"); > >$temp = ""; > >while ($r = mysql_fetch_array($result)) > >{ > > if (empty($temp)) // will be fired only once! > > { > > $temp = $r["catagory"]; // get category name > >// echo "This is category " . $temp .", and it's titles are as > >following:"; //display it > > // echo "this is title " . $r["title"] . ""; > > } > > > > if ($temp != $r["catagory"]) // because it's sorted by category, this > >method will work! > > echo "This is category " . $temp. ", and it's titles are as > >following:"; //display it > > // update last category name > > > > $temp = $r["catagory"]; > > // echo "This is category " . $temp. ", and it's titles are as > >following:"; > > echo "this is title " . > >$r["title"] . ""; > > > >} > > > > > > > >""elias"" <[EMAIL PROTECTED]> wrote in message > >9a246s$mcv$[EMAIL PROTECTED]">news:9a246s$mcv$[EMAIL PROTECTED]... > > > please try this: > > > - > > > I didn't really get what you mean, but i can see that you have a table > >such: > > > > > > Table fields: category, fieldx, fieldy, fieldz, title > > > > > > and you want to display it's data as: > > > > > > category 1 > > >title1 (belonging to cat1) > > >title2 (...) > > >title3 () > > >title4 (...) > > > cat2 > > >titlex > > >titley > > > titlez > > > > > > that what you said, right? > > > okay, try this: > > > > > > ** > > > > > > $result = mysql_query ("SELECT * from article ORDER BY catagory"); > > > $temp = ""; > > > while ($r = mysql_fetch_array($result)) > > > { > > > if (empty($temp)) // will be fired only once! > > > { > > > $temp = $r["category"]; // get category name > > > echo "This is category $temp, and it's titles are as following:"; > >// > > > display it > > > } > > > > > > if ($temp != $r["category"]) // because it's sorted by category, this > > > method will work! > > > echo "This is category $temp, and it's titles are as following:"; > >// > > > display it > > > // update last category name > > > $temp = $r["category"]; > > > echo "this is title " . $r["title"] . ""; > > > > > > } > > > ** > > > - > > > ""Mark Bayfield"" <[EMAIL PROTECTED]> wrote in message > > > 9a1u3q$k81$[EMAIL PROTECTED]">news:9a1u3q$k81$[EMAIL PROTECTED]... > > > > I am trying to make a catagory list that displays a distinct catagory, > >and > > > > then listing titles und
Re: [PHP] Catagory list
Thanks for the code... I got it to do what I wanted, by modifying it to this $result = mysql_query ("SELECT * from article ORDER BY catagory"); $temp = ""; while ($r = mysql_fetch_array($result)) { if (empty($temp)) // will be fired only once! { $temp = $r["catagory"]; // get category name echo "" . $temp .""; //display it } if( $temp != $r["catagory"]) // because it's sorted by category, this method will work! // echo "This is category2 " . $temp. ", and it's titles are as following:"; //display it // update last category name if ($temp = $r["catagory"]) echo "" . $temp . ""; echo " " . $r["title"] . ""; } ""Mark Bayfield"" <[EMAIL PROTECTED]> wrote in message 9a3d8o$e2l$[EMAIL PROTECTED]">news:9a3d8o$e2l$[EMAIL PROTECTED]... > Thanks for the code. Its not doing exactly what I want, but with a little > modification is is kind of working. > The one problem is that it is putting the Title first and the catagory > second. so it is coming up with: > > title1 > title2 > catagory > title3 > title4 > catagory1 > > and the last catagory is droping off. I have modified the code as such (if > you can help so that the catagory is first and the titles second it would be > a great help): > > $result = mysql_query ("SELECT * from article ORDER BY catagory"); > $temp = ""; > while ($r = mysql_fetch_array($result)) > { > if (empty($temp)) // will be fired only once! > { > $temp = $r["catagory"]; // get category name >// echo "This is category " . $temp .", and it's titles are as > following:"; //display it > // echo "this is title " . $r["title"] . ""; > } > > if ($temp != $r["catagory"]) // because it's sorted by category, this > method will work! > echo "This is category " . $temp. ", and it's titles are as > following:"; //display it > // update last category name > > $temp = $r["catagory"]; > // echo "This is category " . $temp. ", and it's titles are as > following:"; > echo "this is title " . > $r["title"] . ""; > > } > > > > ""elias"" <[EMAIL PROTECTED]> wrote in message > 9a246s$mcv$[EMAIL PROTECTED]">news:9a246s$mcv$[EMAIL PROTECTED]... > > please try this: > > - > > I didn't really get what you mean, but i can see that you have a table > such: > > > > Table fields: category, fieldx, fieldy, fieldz, title > > > > and you want to display it's data as: > > > > category 1 > >title1 (belonging to cat1) > >title2 (...) > >title3 () > >title4 (...) > > cat2 > >titlex > >titley > >titlez > > > > that what you said, right? > > okay, try this: > > > > ** > > > > $result = mysql_query ("SELECT * from article ORDER BY catagory"); > > $temp = ""; > > while ($r = mysql_fetch_array($result)) > > { > > if (empty($temp)) // will be fired only once! > > { > > $temp = $r["category"]; // get category name > > echo "This is category $temp, and it's titles are as following:"; > // > > display it > > } > > > > if ($temp != $r["category"]) // because it's sorted by category, this > > method will work! > > echo "This is category $temp, and it's titles are as following:"; > // > > display it > > // update last category name > > $temp = $r["category"]; > > echo "this is title " . $r["title"] . ""; > > > > } > > ** > > - > > ""Mark Bayfield"" <[EMAIL PROTECTED]> wrote in message > > 9a1u3q$k81$[EMAIL PROTECTED]">news:9a1u3q$k81$[EMAIL PROTECTED]... > > > I am trying to make a catagory list that displays a distinct catagory, > and > > > then listing titles under that catagory. > > > Unfortunatly all the data is in one table, and the catagory field is not > > set > > > catagories, so there is duplicates in that field. > > > The code so far is (but I am probably going about it the wrong way, if > you > > > can see whats wrong with my code plase help, or point me in some > > direction), > > > > > > $query = mysql_query("SEL
Re: [PHP] Catagory list
Thanks for the code. Its not doing exactly what I want, but with a little modification is is kind of working. The one problem is that it is putting the Title first and the catagory second. so it is coming up with: title1 title2 catagory title3 title4 catagory1 and the last catagory is droping off. I have modified the code as such (if you can help so that the catagory is first and the titles second it would be a great help): $result = mysql_query ("SELECT * from article ORDER BY catagory"); $temp = ""; while ($r = mysql_fetch_array($result)) { if (empty($temp)) // will be fired only once! { $temp = $r["catagory"]; // get category name // echo "This is category " . $temp .", and it's titles are as following:"; //display it // echo "this is title " . $r["title"] . ""; } if ($temp != $r["catagory"]) // because it's sorted by category, this method will work! echo "This is category " . $temp. ", and it's titles are as following:"; //display it // update last category name $temp = $r["catagory"]; // echo "This is category " . $temp. ", and it's titles are as following:"; echo "this is title " . $r["title"] . ""; } ""elias"" <[EMAIL PROTECTED]> wrote in message 9a246s$mcv$[EMAIL PROTECTED]">news:9a246s$mcv$[EMAIL PROTECTED]... > please try this: > - > I didn't really get what you mean, but i can see that you have a table such: > > Table fields: category, fieldx, fieldy, fieldz, title > > and you want to display it's data as: > > category 1 >title1 (belonging to cat1) >title2 (...) >title3 () >title4 (...) > cat2 >titlex >titley >titlez > > that what you said, right? > okay, try this: > > ** > > $result = mysql_query ("SELECT * from article ORDER BY catagory"); > $temp = ""; > while ($r = mysql_fetch_array($result)) > { > if (empty($temp)) // will be fired only once! > { > $temp = $r["category"]; // get category name > echo "This is category $temp, and it's titles are as following:"; // > display it > } > > if ($temp != $r["category"]) // because it's sorted by category, this > method will work! > echo "This is category $temp, and it's titles are as following:"; // > display it > // update last category name > $temp = $r["category"]; > echo "this is title " . $r["title"] . ""; > > } > ** > - > ""Mark Bayfield"" <[EMAIL PROTECTED]> wrote in message > 9a1u3q$k81$[EMAIL PROTECTED]">news:9a1u3q$k81$[EMAIL PROTECTED]... > > I am trying to make a catagory list that displays a distinct catagory, and > > then listing titles under that catagory. > > Unfortunatly all the data is in one table, and the catagory field is not > set > > catagories, so there is duplicates in that field. > > The code so far is (but I am probably going about it the wrong way, if you > > can see whats wrong with my code plase help, or point me in some > direction), > > > > $query = mysql_query("SELECT DISTINCT catagory from article order by > > catagory"); > > $query2 = mysql_query ("SELECT * from article ORDER BY catagory"); > > > > for ($index = 0; $index < mysql_num_rows($query); $index++) { > > $Catagory = mysql_fetch_row ($query) or die (mysql_error()); > > $name1 = mysql_fetch_row ($query2) or die (mysql_error()); > > $x = $name1; > > $result1 = array_unique($Catagory); > > $result = array_merge($Catagory, $name1); > > > >print ("$result1[0]"); > >for ($x=0; $x == $result1[0]; $x++) { > >print (" > href='update.php?passed=$name1[0]'>$name1[2]\n"); > >} > > } > > > > I am trying everything to get it do just print the following: > > > > Catagory > > title1 > > title2 > > Catagory1 > > title3 > > title4 > > > > Please help me out > > > > thanks > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Catagory list
I am trying to make a catagory list that displays a distinct catagory, and then listing titles under that catagory. Unfortunatly all the data is in one table, and the catagory field is not set catagories, so there is duplicates in that field. The code so far is (but I am probably going about it the wrong way, if you can see whats wrong with my code plase help, or point me in some direction), $query = mysql_query("SELECT DISTINCT catagory from article order by catagory"); $query2 = mysql_query ("SELECT * from article ORDER BY catagory"); for ($index = 0; $index < mysql_num_rows($query); $index++) { $Catagory = mysql_fetch_row ($query) or die (mysql_error()); $name1 = mysql_fetch_row ($query2) or die (mysql_error()); $x = $name1; $result1 = array_unique($Catagory); $result = array_merge($Catagory, $name1); print ("$result1[0]"); for ($x=0; $x == $result1[0]; $x++) { print ("$name1[2]\n"); } } I am trying everything to get it do just print the following: Catagory title1 title2 Catagory1 title3 title4 Please help me out thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]