ChadNomad
Members-
Posts
46 -
Joined
-
Last visited
Never
Everything posted by ChadNomad
-
[SOLVED] Using function variables outside a class?
ChadNomad replied to ChadNomad's topic in PHP Coding Help
Haha I'm an idiot. Nevermind! Thanks, all your suggestions worked it was me being stupid. -
[SOLVED] Using function variables outside a class?
ChadNomad replied to ChadNomad's topic in PHP Coding Help
Heres the setup. Maybe this will make more sense. I'm trying to use a variable from a function inside a class and use that in a completely different page where the class file is included. login.class.php class Login() { function ProcessLogin($username, $password) { $this->MyVar = "Hello"; } } $login = new Login(); $login->ProcessLogin($username, $password) login.php include("login.class.php"); echo $login->MyVar; // <- This is my problem. Doesn;t work... I've tried using "global" to no avail... -
Using your code... <?php $checked = $_POST["foo"]; if ($checked == "checked") { $value = 0; // It's checked so make it 0 } else { $value = 1; // It isn't checked, value is 1 } echo "The value is ".$value; ?> HTML: <form method="post"> <input type="checkbox" name="foo" /> <input type="submit" name="submit" /> </form> Why are you using things such as ternary conditions as a noob? Keep it simple and easily readable! I haven't tried the code above but it should work.
-
Are you trying to check a checkbox? If so... $checked == $Active ? "checked='checked'" : ""; This always return true as your making $checked equal to $Active and not "is equal to?". To compare use == $checked = $Active ? "checked" : "";
-
How do you use a variable outside a class? I've included a class on a page and I want to echo a string made within a function. Thanks.
-
[SOLVED] PHP / SQL - getting the auto_increment variable
ChadNomad replied to HughbertD's topic in PHP Coding Help
"Auto Increment" automatically increments . The number is automatically assigned and placed into the table, you don't need to add it to your SQL query. I think that's what your thinking about anyway. -
[SOLVED] Can't access my PHP files through Apache.
ChadNomad replied to DavidGS's topic in PHP Installation and Configuration
I didn't mean in your browser I meant in your config. I stand corrected anyway, Apache uses forward slashes. Ignore me! -
[SOLVED] Can't access my PHP files through Apache.
ChadNomad replied to DavidGS's topic in PHP Installation and Configuration
This is http:// which always uses forward slashes. When navigating through Windows Explorer you use backslashes. That's to do with the web client, not the web server. It may not make a difference but surely it's worth a try? I use XAMPP for Windows but learning to install PHP/Apache could be good experience for the future! -
[SOLVED] Can't access my PHP files through Apache.
ChadNomad replied to DavidGS's topic in PHP Installation and Configuration
On Windows don't paths use backslashes (\)? Just a thought... -
Passing variables from function-function in class
ChadNomad replied to ChadNomad's topic in PHP Coding Help
Thanks. Function to function is fine now. Still... I'm now trying to use a variable outside of both the function and class. echo $registration->errorString; The above does nothing. I've included the class in an external file. At the bottom of the class file I have: $registration = new Registration(); Am I doing something wrong?? -
Hi, I'm still pretty new to OOP and have just started writting my first registration class. Everything is going well except I can't seem to pass a variable from one function to another. For example if in function a() $test = "hello" it won't work if I use it in function b(). How do I make them "global"? I don't quite understand the what global vars actually are but apparently it's bad practice and I haven't had much luck in my tests with them. I also only want it to be "global" in the class I've created. Hope that wasn't too confusing! Would $this-> work? <- only just thought of that after posting. Thanks
-
[SOLVED] Easiest Way to check string is Alpha-Numeric
ChadNomad replied to ChadNomad's topic in PHP Coding Help
Excellent, thanks. -
What's an easy way to check that a string is alpha-numeric? Are there any built-in PHP functions to do this? Thanks!
-
I did mean that. Also why is it nonsense? AND works fine...
-
Hey. I've just started using the ternary operator to shorten my code and make it more readable. I'm curious to know if you can have more than one result returned and how (if you can). I've currently got this: $password == $passwordConfirm ? $valid[3] = 1 : $valid[3] = 0; I'd like to add $vError++ as well in the "else" part if it's possible. Thanks.
-
The simple things are always the hardest to find on the net. Thanks!!!!
-
How can I read specific lines from a file? For example I have a text file with 100 lines and want to read only lines 80-90. Thanks
-
Wouldn't it be: setcookie("remember1","", time()-60*60*24*14,"/",$domain,0); setcookie("remember2","",time()-60*60*24*14,"/",$domain,0); It looks like your doing (60*60*24*14 - 3600) which won't expire the cookie. That's not long enough right?
-
I'm trying to find matching pages by searching two arrays against each other. The arrays get the keywords from the current page and others stored in a database. I'm not very good with PHP but what I'm doing at the moment is actually working, except it's only printing one found keyword when there are more. Heres what I have: $q1 = mysql_query("SELECT * FROM $table WHERE category='$section' ORDER BY time DESC LIMIT 5") or die (mysql_error()); $table = "the_table"; $qX = mysql_query("SELECT keywords FROM $table WHERE id='$id'") or die (mysql_error()); $rX = mysql_fetch_array($qX) or die (mysql_error()); $keywordThis = ereg_replace(" ","",$rX[keywords]); $keywordThis = explode(",",$keywordThis); $a = 0; $i = 0; $x = 0; $y = 0; $z = 0; $qY = mysql_query("SELECT * FROM $table WHERE id!='$id'") or die (mysql_error()); $rows = mysql_num_rows($qY); while ($rY = mysql_fetch_array($qY)) { $getKeyword = $getKeyword.$rY[keywords].","; $getID = $getID.$rY[id].","; $getTitle = $getTitle.$rY[title].","; $getCategory = $getCategory.$rY[category].","; $x++; } $getKeyword = ereg_replace(" ","",$getKeyword); $getKeyword = explode(",",$getKeyword); $getID = explode(",",$getID); $getTitle = explode(",",$getTitle); $getCategory = explode(",",$getCategory); while ($getKeyword[$y] != "") { if ($getKeyword[$y] == $keywordThis[$y]) { $result = $result + 1; } $y = $y + 1; } if($result < 1) { echo ' No similar pages found...'; } else { while ($getKeyword[$z] != "") { if ($getKeyword[$z] == $keywordThis[$z]) { echo '<div id="result_line"><a href="index.php?go='.$getCategory[$z].'&id='.$getID[$z].'" class="result" title="'.$getTitle[$z].'">'.substr($getTitle[$z],0,30).'...</a></div>'; $result = $result + 1; } $z = $z + 1; } } Hope someone can help, sorry if the code is messy.