eves
Members-
Posts
26 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
eves's Achievements
Newbie (1/5)
0
Reputation
-
do this to your select box [code] <select name='cmbSelect'> <?php $sel_options = ""; $result = mysql_query("SELECT dept_id, department FROM tbl_departments ORDER BY department ASC "); while ($row = mysql_fetch_assoc($result)) { $selected = ""; if ($dept_ds[$ctr]==$selectedDepartment) $selected = " selected "; $sel_options .= "<option value='".$row['dept_id']."' $selected>".$row['department']."</option>"; } echo $sel_options; ?> </select> [/code] just made up the fields on the SQL above, what it does is it selects the previously chosen department
-
Extracting information from a string and replacing it again
eves replied to thehigherentity's topic in PHP Coding Help
use str_replace to deal with variations of [mytag] something like [code] $open_tag = "[mytag]"; $close_tag ="[/mytag]"; $str = "blah blah blah [mytag] info needed 1 [/mytag]blah blah blah[mytag]info needed 2[/mytag]blah blah blah[mytag]info needed 3[/mytag] blah blah blah"; $var_open = array('[MyTag]','[myTag]','[MYTAG]');// include other variations $var_close = array('[/MyTag]','[/myTag]','[/MYTAG]');// include other variations $limit = count($variations); for($ctr=0;$ctr<$limit;$ctr++) { $str = str_replace($variations[$ctr],$open_tag,$str); $str = str_replace($variations[$ctr],$close_tag,$str); } [/code] then use explode to separate into chunks, retrieve the text in between the tags edit them, then use the implode function to join them up something like: [code] $str_temp = explode('[mytag]',$str); $ret_val = ""; $limit = count($str_temp); for($ctr=0;$ctr<$limit;$ctr++) { if (strpos($str_temp[$ctr],$close_tag)===false) { $ret_val .= $str_temp[$ctr]; } else { $tmp = explode($close_tag,$str_temp[$ctr]); $tmp[0] .= '(edited)'; // do your edit part here, $tmp[0] contains the text between the tags $ret_val .= $open_tag . implode($close_tag,$tmp); //join them up, append the open tag at the beginning } } [/code] hope that helps -
SELECT * FROM mydb WHERE (Goods='lappy' OR Date LIKE '%25') AND (Dept IS NOT NULL OR Dept!='')
-
you might want to check for the following: 1. FORM method is POST and not GET 2. select box is named "cmbSelect" (I know, but just in case ;]) 3. say you have this links to move to the next page: Page 1 2 3 4 ..... do you link them as <a href='<?echo $_SERVER["PHP_SELF"]."?page=$ctr"?>'> if yes, then your passing your next page in a query string, so test for it using GET something like [code] $selectedDepartment = 1; // default value if ($_SERVER['REQUEST_METHOD']=='POST' && isset($_POST['cmbSelect'])) { $selectedDepartment = intval($_POST['cmbSelect']); } elseif ($_SERVER['REQUEST_METHOD']=='GET' && isset($_GET['page'])) { $selectedDepartment = intval($_GET['page']); } if ($selectedDepartment ==0) $selectedDepartment = 1; //just in case something went wrong above [/code]
-
the problem probably lies on the part where you populate $list[] you might want to post that
-
[code] $result=mysql_query($query); [/code] you missed that part
-
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] According to that it means that using $_SESSON['variable'] or $_REQUEST['variable'] should have the same affect [/quote] this is incorrect, the $_REQUEST only consist of the contents of $_GET, $_POST, and $_COOKIE this will never be true: $_SESSON['variable'] == $_REQUEST['variable'] (unless of course, they change the implementation on PHP [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] ) for getting the value of the game id, test for the variable if it is set and has something on it, something like this: [code] if ($_SERVER['REQUEST_METHOD']=='POST' && isset($_POST['game_id']) && trim($_POST['game_id'])!='') { //just included the strip_tags() to clean posted entry //you might want to add some more $game_id = strip_tags($_POST['game_id']); } else { $game_id = $_SESSION['game_id']; } [/code]
-
[code] $result = mysql_query("SELECT rate_1, rate_2, rate_3, rate_4, rate_5 FROM (TABLE) WHERE (CONDITION) "); $row = mysql_fetch_row($result); // use mysql_fetch_row to get an array with a numeric index // get the max value in the fields (rate_1, teate_2, rate....) and search for it in the array $row // array_keys will return an array based on the search made, thus you access it as $index[0] $index = array_keys($row,max($row)); //determine which field is the highest //order on this part depends on the order of the fields in the select query switch ($index[0]) { case 0: //rate_1 is the highest break; case 1: //rate_2 is the highest break; case 2: //rate_3 is the highest break; case 3: //rate_4 is the highest break; default: //rate_5 is the highest break; } [/code] hope that helps
-
[code] $words = array("zero","one","two","three","four","five","six","seven","eight","nine"); echo $words[rand(0,(count($words)-1))]; [/code] store some words on an array, then just generate a random index from zero to max index of array ( (count($words)-1)) )
-
[code] $updateyourstats="update km_users set skillpts='".($skillpts+$ptsgained)."',honor='".($honor+1)."',curexp='".($curexp+100)."' where playername='$player'"; [/code] do that with the other query too.
-
can you post the codes on the page where it is posted from? also you might want to check if the checkbox is named as "Name[]"
-
check the manual: [a href=\"http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server\" target=\"_blank\"]http://www.php.net/manual/en/reserved.vari...ariables.server[/a]
-
are you only using a single table (lyricstable)? if yes, you should normalize it first before proceeding if not, please post the structure of the other tables
-
you might want to try these: assuming you have this fields on your cart table tbl_cart(cart_id, prod_id, qty, unit_price, pri_shipping, sec_shipping, initial, client_id) - would greatly ease computation if you store primary and secondary shipping on the table - pri_shipping - primary shipping cost of product - sec_shipping - additional shipping cost of product [code] $result = mysql_query("select * from tbl_cart where client_id='$CLIENT_ID'"); $shipping = 0; while($row=mysql_fetch_assoc($result)) { if ($row['qty']>1) { if ($row['initial']==1) //get primary shipping cost first then add secondary costs { $shipping += $row['pri_shipping']; $shipping += ($row['qty']-1)*$row['sec_shipping']; } else { $shipping += ($row['qty'])*$row['sec_shipping']; } } else { // since only 1 qty, should be the main product, thus primary shipping cost apply $shipping += $row['pri_shipping']; } } [/code] the initial field is etheir 1 or 0, 1 if its the main product being pruchased, else 0 you might want to check for some syntax or typos, just basically made it up on this site's editor [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] hope that helps
-
[!--quoteo(post=376014:date=May 22 2006, 08:33 PM:name=karl19)--][div class=\'quotetop\']QUOTE(karl19 @ May 22 2006, 08:33 PM) [snapback]376014[/snapback][/div][div class=\'quotemain\'][!--quotec--] [code]<a href="#" onclick="mooShows['myShow'].jumptoImage(4);"/a>[/code] [/quote] couldn't really understand the code you provided but here's a shot of what I think your trying to do [code] $limit = 10; //total number of images for($ctr=0;$ctr<$limit;$ctr++) { echo "<a href='#' onclick='jumptoImage($ctr,'".mooShows['myShow']."');'><img src='".$image[$ctr]."' height=100 width=100></a><br>"; } [/code] the jumptoImage() javascript function take 2 parameters, first a counter that will serve as an indentifier for the image and second, the name of the page that will be opened. I'm just assuming that you would be opening mooShows['myShow'] in a new page or a pop up