-
Posts
1,893 -
Joined
-
Last visited
-
Days Won
8
Everything posted by AbraCadaver
-
stop for loop when if statement executes
AbraCadaver replied to calmchess's topic in PHP Coding Help
OK and break works or no? -
stop for loop when if statement executes
AbraCadaver replied to calmchess's topic in PHP Coding Help
I'm not sure what your code is doing but to get out of a loop use break. for($i=0;$i<count($arr0);$i++){ $arr1=explode(":",$arr0[$i]); if($arr1[0]==$_POST['uname']){ array_splice($arr0,$i,1); $ser_arr0 = serialize($arr0); $sql1 = "update yahvid.tracku set serdata='$ser_arr0' where modname='$_POST[modname]'"; $retval1 = mysql_query( $sql1, $conn ); break; } } -
You can use var, but better public, private or protected. But if it is not a constant value (can't be another variable), then do as PFMaBiSmAd said and assign in the constructor: class user { var $id; function __construct() { $this->id = $_SESSION['id']; // etc... } }
-
That's totally the wrong code. strftime needs a unix timestamp and you're giving it the result of is_string which is probably true. Depending on what $row["timestamp"] looks like you probably need this: date('Y', strtotime($row["timestamp"])); Or use the MySQL date functions to just return the year from the query, depending on if you need the whole date later or not.
-
You are only fetching one row into $row1 and then displaying it multiple times. Try this instead: //$row1 = mysql_fetch_array($result); // delete this //for($i = 0; $i < $rows1; $i++){ // replace this with while($row1 = mysql_fetch_array($result)) { Also, you start using $result1 and then switch to using just $result.
-
You can't have any output, spaces HTML anything before a header() call. You do here: <?php require_once("includes/function.php"); ?> these two blank lines are interpretted as HTML whitespace and sent to the browser, because they aren't in php tags <?php session_start(); Should be: <?php require_once("includes/function.php"); session_start(); Your other server must have had output buffering turned on in php.ini that buffered the output before the header.
-
You'll have to elaborate more on what you want.
-
Read the file into a string with file_get_contents(), make changes to the string and then write it back out with file_put_contents().
-
What does this produce: function RemoveMultibyte($text) { $new = $text; echo $new . '<br>'; $new = preg_replace('~[^\\pL0-9_]+~u', '-', $new); echo $new . '<br>'; $new = trim($new, "-"); echo $new . '<br>'; $new = strtolower($new); echo $new . '<br>'; $new = preg_replace('~[^-a-z0-9_]+~', '', $new); echo $new . '<br>'; return $new; }
-
I you do your inputs the way I showed, then you would remove all the $chxN = $_POST['chxN'] and replace all of your echo $chxN with: foreach($_POST['check'] as $chx) { echo $chx; }
-
Yes, and you can also create an array of checkboxes so that you only operate on the ones that are set: <input type='checkbox" name="check[1]" value="something"> <input type='checkbox" name="check[2]" value="something else"> Then: foreach($_POST['check'] as $key => $value) { //do stuff with $key and/or $value }
-
What do you mean they don't work? Care to post some code and the results?
-
Ha the default case. Yes, I skipped right over that!
-
Your switch looks fine but not the if. Try this: if( isset($_GET['user']) ) { $xid = strtolower($_GET['user']; } else { $xid = 'default'; }
-
Yes, an you should be using urlencode() on text that you put in the URL. This will do that for you.
-
It's hard to tell what you're doing, but file() reads a file, plus you are assigning the data to an array first. Try: $mybyte = $_POST['myfilebyte']; file_put_contents('/path/to/file', $mybyte);
-
Your link can have something like ?lang=EN and then you can get it with $_GET['lang'] and use it how you wish.
-
I'm not positive how you want to do this, but this is one way: ob_start(); include("test.php"); $output = ob_get_clean();
-
http://us2.php.net/manual/en/language.types.string.php Read the single and double quote sections.
-
You may have a space or something else that is outputting which would make the header fail. Try adding this up top: error_reporting(E_ALL); ini_set('display_errors', '1');
-
Add this to the top of the page: error_reporting(E_ALL); ini_set('display_errors', '1');
-
One problem at least is this (you only want the first one): mysql_query("UPDATE table SET col8='Y' WHERE id='$id'"); mysql_query("UPDATE table SET col8='Y' "); Secondly, do you really have a column called id in the table that has a unique id for each row?
-
You probably need to show several lines before and after this line.
-
It may sometimes work with a relative one, but the Location header requires an absolute URL.