Jump to content

Search the Community

Showing results for tags 'variables'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. My login script stores the user's login name as $_SESSION[ 'name'] on login. For some unapparent reason, i'm getting errors stating that $user and $priv are undefined variables, though I've attempted to define $user as being equal to $_SESSION['name'], using $user to look up the the user's privilege level (stored as the su column ) in the SQL table, and then where the result of the sql query is $priv which is then evaluated in an if statement. I can't seem to figure out why this might not be working. The code I'm using: <?php session_start(); function verify() { //verify that the user is logged in via the login page. Session_start has already been called. if (!isset($_SESSION['loggedin'])) { header('Location: /index.html'); exit; } //if user is logged in, we then lookup necessary privleges. $_SESSION['name'] was written with the login name upon login. Privleges // are written in db as a single-digit integer of of 0 for users, 1 for administrators, and 2 for special users. $user === $_SESSION['name']; //Connect to Databse $link = mysqli_connect("127.0.0.1", "database user", "password", "database"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } //SQL Statement to lookup privlege information. if ($result = mysqli_query($link, "SELECT su FROM accounts WHERE username = $user", MYSQLI_STORE_RESULT)) { //LOOP TO CYCLE THROUGH SQL RESULTS AND STORE Privlege information as vairable $priv. while ($row = $result->fetch_assoc()) { $priv === $row["su"]; } } // close SQL connection. mysqli_close($link); // Verify privleges and take action. Only a privlege of "1" is allowed to view this page. A privlege of "2" indicates special //accounts used in other scripts that have certain indermediate additional functions, but are not trusted administrators. if ($priv !== 1) { echo $_SESSION['name']; echo "you have privlege level of $priv"; echo "<br>"; echo 'Your account does not have the privleges necessary to view this page'; exit; } } verify(); ?>
  2. Hey! I want to create a website that can test your counting pace. I’ll make colored, square div that change color after 10 to 30 seconds when you hover over it, and then you’ll type down how long you think it took in a form to check if you’re right. My solution to do this is to create the PHP variable $time = rand(10,30), and in CSS get the div:hover transition-delay to be $time. Then, after the form, I need the same variable for if($_POST[timeguess] = $time) {echo “Correct!”}. I have no idea how to access the same variable in both the CSS and HTML, so I hope some of you can help me out! Thanks
  3. Help Please! I'm trying to pass variables in a URL and use them in a HTML email. When test1.php calls Test2.php, test2.php should send two HTML emails but nothing happens. I get this error for test2.php: [24-Feb-2016 16:20:42 UTC] PHP Parse error: syntax error, unexpected end of file in /home/my/public_html/test2.php on line 114 HTML - call test1.php <!DOCTYPE html> <html lang="en-US"> <head> <meta charset="utf8" /> <title>Testform.html</title> </head> <body bgcolor="tan" text ="black"> <form action="test1.php" method="POST" > <table> <tr> <th> ~ Test ~ <br /> </th> </tr> </table> <br /> <table> <tr> <td> * </td> <td> <strong> Required Fields </strong> </td> <tr> </table> <table> <tr> <td> <strong>Title: </strong> </td> <td> <select name="Title" size="1" > <option value="" selected>Please Choose</option> <option value="Mr."> Mr.</option> <option value="Ms."> Ms.</option> <option value="Mrs."> Mrs.</option> </select> </td> </tr> <tr> <td> <strong> First Name: </strong> </td> <td> <input type="text" name="Fname" maxlength="30" /> </td> </tr> <tr> <td> <strong> Last Name: </strong> </td> <td> <input type="text" name="Lname" maxlength="30" /> </td> </tr> <tr> <td> <strong> Suffix: </strong> </td> <td> <select name="Suffix" size="1"> <option value=""> Please Choose </option> <option value="Sr."> Sr.</option> <option value="Jr."> Jr.</option> <option value="III"> III</option> <option value="IV"> IV</option> <option value="V, "> V</option> </select> </td> </tr> <tr> <td> <strong> Address: </strong> </td> <td> <input type="text" name="Address" maxlength=40 /> </td> </tr> <tr> <td> <strong> City, State: </strong> </td> <td> <select name="CityState"> <option value=""> Please Choose </option> <option value="Hometown, CA"> Hometown, CA</option> <option value="My City, CA"> My City, CA</option> <option value="Beautiful, CA"> Beautiful, CA</option> </select> </td> </tr> <tr> <td> <strong> Zip Code: </strong> </font> </td> <td class="td2"> <input type="text" name="Zip" placeholder="99999" maxlength=10 /> </td> </tr> </table> <table> <tr> <th> <strong> Comments: </strong> </th> </tr> </table> <table> <tr> <td> <textarea rows="8" cols="60" name="Comments" wrap="hard"> </textarea> </td> </tr> </table> <table> <tr> <td> <input id="shiny" type="submit" value="Submit Form" /> </td> </tr> </table> </form> </body> </html> TEST1.PHP <?php //###Process testform.html //### Error Reporting error_reporting(E_ALL); //### Create Random Number srand((double) microtime() * 1000000); //### Define Variable(s) $random_number = rand(); $Test_number = "$random_number"; $Date = date("D d M Y - H:i:s "); $path = "/home/mypath/public_html/"; $myfile = "test1.txt"; $file = $path.$myfile; $fh = fopen($file, "a+") or die("Couldn't open $myfile"); //### Get Data From Form if ($_SERVER["REQUEST_METHOD"] === "POST") { if(isset($_POST["Title"])) { $Title = $_POST["Title"]; } if(isset($_POST["Fname"]) && !empty ($_POST["Fname"])) { $Fname = $_POST["Fname"]; if(preg_match("/[^a-zA-Z]*$/",$Fname)){ //### Upper Case First Letter of First Name $FnameUc = ucfirst($Fname); } else { echo"<strong>The First Name you entered is not valid.</strong>". PHP_EOL; echo "<br />\n"; exit; } } if(isset($_POST["Lname"]) && !empty ($_POST["Lname"])) { $Lname = $_POST["Lname"]; if(preg_match("/[^a-zA-Z]*$/",$Lname)){ //### Upper Case First Letter of Last Name $LnameUc = ucfirst($Lname); } else { echo"<strong>The Last Name you entered is not valid.</strong>". PHP_EOL; echo "<br />\n"; exit; } } if(isset($_POST["Suffix"]) && !empty ($_POST["Suffix"])) { $Suffix = $_POST["Suffix"]; } if(isset($_POST["Address"]) && !empty ($_POST["Address"])) { $Address = $_POST["Address"]; } else { echo "<br />\n"; } if(isset($_POST["CityState"]) && !empty ($_POST["CityState"])) { $CityState = $_POST["CityState"]; } else { echo " <strong> You didn't choose a City, State </strong> "; echo " <br /> "; die(); } if(isset($_POST["Zip"]) && !empty ($_POST["Zip"])) { $Zip = $_POST["Zip"]; } else { echo "<strong>You didn't enter Zip Code</strong>"; echo " <br /> "; die(); } if(isset($_POST["Email"]) && !empty ($_POST["Email"])) { $Email = trim($_POST["Email"]); //### check if e-mail address is well-formed if (!filter_var($Email, FILTER_VALIDATE_EMAIL)) { echo $Email . " <strong>is not a valid email address</strong>"; } } } //### Call Functions test1_1(); test1_2(); function test1_1(){ //### Write order to file appointment.txt global $Test_number, $Date, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; if(is_readable($file)) { echo " "; } else { echo '<strong>The file is not readable</strong>\n\n'; die(); } if(is_writable($file)) { echo " "; } else { echo '<strong>The file is not writable</strong>'; die(); } //### Open file if(!$fh) { die("couldn't open file <i>$myFile</i>"); } else { $str = "\r\n"; $str.= "Test1 - $Test_number\r\n"; $str.= "Date: $Date\r\n"; $str.= "Name:\r\n"; $str.= "\t\t $Title $FnameUc $LnameUc $Suffix\r\n"; $str.= "Address:\r\n"; $str.= "\t\t $Address\r\n"; $str.= "City, State:\r\n"; $str.= "\t\t $CityState $Zip\r\n"; $str.= "\t\t $Email \r\n"; $str.= "Comments:\r\n"; $str.= "\t\t $Comments\r\n"; $str.= "\r\n"; $str.= "\r\n"; fwrite($fh, $str); } fclose($fh); } function test1_2() { //### Email (HTML) Someone global $Test_number, $Date, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; //### Define Variables $mailto = $Email; $From = "me@mydomain.com"; $subject = "Test1"; //### Beginning of HTML message $message = <<<EOF <html> <body BGCOLOR="tan" TEXT="black"> <br><br> $Title $LnameUc, <br> We have received your Test. <br> The information you submitted is below: <br> <b>$Title $FnameUc $LnameUc $Suffix</b> <br> <b>$Address</b> <br> <b>$CityState $Zip</b> <br> <b>$Email</b> <br><br> Comments: <br> <b>$Comments</b> <br><br> Please click your <b><u>Confirm Email Address</u></b> ,below, to confirm your email address. <br><br> * * * * * * * * * * <a href="http://www.mydomain.com/test2.php?test_number= $Test_number&date=$Date&title=$Title&fname=$FnameUc&lname=$LnameUc&suffix=$Suffix&address=$Address&citystate= $CityState&zip=$Zip&email=$Email&comments=$Comments">Confirm Email Address - $Test_number</a> * * * * * * * * * * <br><br> </body> </html> EOF; //end of message $headers = "Mime-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" ."\r\n"; $headers .= "Sensitivity: Personal\r\n"; $headers .= "From:" .$From . "\r\n"; $headers .= "Reply To:". $From . "\r\n"; $headers .= "Return-Path:" .$From . "\r\n"; $headers.= "BCC: me@mydomain.net\r\n"; $headers .= "X-Priority: 1 (Highest)\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; $headers .= "Importance: High\r\n"; //### now lets send the email if(mail($mailto, $subject, $message, $headers)) { echo "<b> <font color='green' size='+2'> Test1 sent.</font></b>"; } else { echo "<b> <font color='red' size='+2'>Test1 not sent.</b></font>"; } } ?> TEST2.PHP <?php //### Test2.php called by Test1.php //### Error Reporting error_reporting(E_ALL); //### Define varibles $Date = $_GET["date"]; $Appointment_number = $_GET["appointment_number"]; $Title = $_GET["title"]; $FnameUc = $_GET["fname"]; $LnameUc = $_GET["lname"]; $Suffix = $_GET["suffix"]; $Address = $_GET["address"]; $CityState = $_GET["citystate"]; $Zip = $_GET["zip"]; $Email = $_GET["email"]; $Comments = $_GET["comments"]; //### Call Function(s) test2_1(); test2_2(); //### HTML Email to Client function test2_1() { global $Date, $Test_number, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; //### Define variables $mailto = $Email; $From = "me@mydomain.com"; $subject = "Test2 - ". $Test_number."\r\n"; //### Beginning of HTML message $message = <<<EOF <html> <body BGCOLOR="tan" TEXT="black"> <br><br> $Title $FnameUc $LnameUc $Suffix <br> Your email address <b><$mailto></b> is confirmed. <br><br> </body> </html> EOF; //### end of message $headers = "Mime-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "Sensitivity: Personal\r\n"; $headers .= "From: ".$From. "\r\n"; $headers .= "Reply-To: ".$From. "\r\n"; $headers .= "Return-Path: ".$From. "\r\n"; $headers .= "BCC: horacef@horacefranklinjr.net \r\n"; $headers .= "X-Priority: 1 (Highest)\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; //### Now lets send the email if(mail($mailto, $subject, $message, $headers)) { echo "<b> <font color='green' size='+2'>Email address Confirmation sent to: ".$mailto."</font></b>"; echo "<br /> <br />"; } else { echo "<b> <font color='red' size='+2'>Email address Confirmation not sent.</font></b>"; echo "<br /> <br />"; } } //### HTML Email to Horace function test2_2() { global $Date, $Appointment_number, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; //### Define variables $mailto = $Email; $From = "me@mydomain.com"; $subject = "Test2 - ". $Test_number."\n\n"; //### begin of HTML message $message = <<<EOF <html> <body BGCOLOR="tan" TEXT="black"> <br><br> You have received an Test, <b>that needs to be confirmed.</b> <br> Date Received: <b>$Date</b> <br><br> The information submitted is below: <br> <b>$Title $FnameUc $LnameUc $Suffix</b> <br> <b>$Address</b> <br> <b>$CityState $Zip</b> <br> <b>$mailto</b> <br><br> Comments: <br> <b>$Comments</b> <br><br> Please click the <b><u>Confirm Appointment</u></b> ,below, to confirm the Appointment Date and Time. <br><br> <a href="http://www.mydomain.com/Test3.php?date=$Date&test_number=$Test_number&title=$Title&fname=$FnameUc&lname=$LnameUc&suffix=$Suffix&address=$Address&citystate=$CityState&zip=$Zip&email=$Email&comments=$Comments"> Confirm Appointment - $Test_number</a> <br> </body> </html> EOF; //###end of message $headers = "Mime-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "Sensitivity: Personal\r\n"; $headers .= "From:" . $From . "\r\n"; $headers .= "Reply-To:" . $From . "\r\n"; $headers .= "Return-Path:" . $From . "\r\n"; $headers .= "BCC: me@mydomain.net\r\n"; $headers .= "X-Priority: 1 (Highest)\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; //### Now lets send the email if(mail($mailto, $subject, $message, $headers)){ echo "<b> <font color='green' size='+2'> Confirm Appointment email sent to: ". $mailto."</b></font>"; echo "<br /> <br />"; } else { echo "<b> <font color='red' size='+2'> Confirm Appointment email not sent.</b></font>"; echo "<br /> <br />"; } ==> Line 114 }
  4. Hi everybody! I am building a custom PHP app, and am submitting a form. This form will have between 1 or more textareas, named "textarea1", "textarea2", "textarea200", and so on. I need to read each of these and insert them into a database. How can I script this into the PHP landing page? Is there a way to read all of the values, and names, that are contained in $_POST. Many thanks, Jason
  5. Hey All, Need to pass the current window width to a PHP class which creates a slide show presentation. The presentation image sizes need calculated for all devices including mobile and smart phone (mobile web). Problem is, PHP is server side and doesn't care about the windows width. I'm using Javascript to acquire the window width and pass that value to PHP - before calling the class that create the presentation. My workaround is using Output Buffering: <php ob_start(); //starts buffering ?> <script> var wwidth = screen.width; document.write(wwidth): //output </script> <?php $windowwidth = ob_get_clean(); //works error_log("Window width is: ".$windowwidth); //continue on with the rest of the script ?> I dislike ducking in and out of PHP like this. And I'm not able to use Javascript XMLHttpRequest because I need the size before the class is called, on the current page. Any alternative suggestions? Thanks in advance
  6. I'm running the latest stable version of PHP in Apache Server on Windows 7 64-bit. It working fine and set up correctly. I'd like to use ENVIRONMENT VARIABLES or a variable like "%current_directory%" or "..\%current_directory%" in the configuration files for PHP, php.ini. Is this possible? Is php.ini a parsed file, can variables be define and used in it? Help would be much appreciated
  7. I'm running the latest version of MySQL on Windows 7 64-bit. It working fine and set up correctly. I'd like to use ENVIRONMENT VARIABLES or a variable like "%current_directory%" or "..\%current_directory%" in the configuration files for MySQL, my.ini. Is this possible? Is my.ini a parsed file, can variables be define and used in it? Help would be much appreciated
  8. I'm running the latest version of Apache Server on Windows 7 64-bit. It working fine and set up correctly. I'd like to use ENVIRONMENT VARIABLES or a variable like "%current_directory%" or "..\%current_directory%" in the configuration files for Apache, httpd.conf etc. Is this possible? Is httpd.conf a parsed file, can variables be define and used in it? Help would be much appreciated
  9. so my situation is something like this , i'm trying to fetch user details based on `id` that isset is getting, but some how the `variable that contains the $_GET value doesn't work` in query but when i put an static value to pdo query then it works and show the result. i have checked by doing `var_dump` of variable `$user` before query and it shows the correct value but not working in query. Below is the code i'm working with: public function profile_view($user_id = null) { $user = $user_id; $stmt = $this->_db->prepare('SELECT memberID,username,email,profile_pic,active FROM members WHERE memberID = :user_id AND active="YES"'); $stmt->execute(array(':user_id'=>$user)); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $user_det = (object) array('username'=> $row['username'],'email'=>$row['email'],'profile_pic'=>$row['profile_pic'],'id'=> $row['memberID'],'active'=>$row['active']); return $user_det; } } this is how function is being called (profile_view function is child of User class so $user is class User) : $view_profile = $user->profile_view($_GET['u']); the above code returns null but when i put static value : `5` at the place of `$user` in `$stmt->execute` it returns the whole user's details which is what i need , but its not working with variable which is confusing me alot , thanks in advanced for help.
  10. Hi, I am trying to create a login system in PHP, but I am not the greatest at PHP so I am using a source code which I found online as I found it to be more secure as it uses things like salted passwords. Anyway I am trying to add more fields to the register system so it adds them to the mysql, the source has a way to do this with arrays, but it is quite complicated so I am just using variables from the original file. There are 2 files: register.php and class.loginsys.php which contains all the functions. At first the query syntax was incorrect so I decided to use the variables created in register.php in the class.loginsys, but now it's giving me an out of memory error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 28672 bytes) in C:\xampp\htdocs\ls\class.loginsys.php on line 34 Which I am unsure of how to fix. I have tried using different variable names, checking the line, checking the whole register.php file for anything rogue. Here is the code: Top part of register.php <?php include "config.php"; ?> Config.php: <?php require "class.loginsys.php"; $LS=new LoginSystem(); ?> Then actual register part from register.php: <?php if( isset($_POST['submit']) ){ $firstname2 = $_POST['firstname']; $lastname2 = $_POST['lastname']; $user2 = $_POST['username']; $sex2 = $_POST['sex']; $country2 = $_POST['strCountryChoice']; $email2 = $_POST['email']; $pass2 = $_POST['pass']; $pass3 = $_POST['pass2']; $birthdate2 = $_POST['birthdate']; $created2 = date("Y-m-d H:i:s"); //need to add a lot more validation functions.. AKA Check if email exists and username. Password > 5 chars if( $user2=="" || $email2=="" || $pass2=='' || $pass3=='' || $firstname2=='' || $lastname2=='' || $sex2=='' || $country2=='' || $birthdate2=='' ){ echo "Fields Left Blank","Some Fields were left blank. Please fill up all fields."; exit; } if( !$LS->validEmail($email2) ){ echo "E-Mail Is Not Valid", "The E-Mail you gave is not valid"; exit; } if( !ctype_alnum($user2) ){ echo "Invalid Username", "The Username is not valid. Only ALPHANUMERIC characters are allowed and shouldn't exceed 10 characters."; exit; } if($pass2 != $pass3){ echo "Passwords Don't Match","The Passwords you entered didn't match"; exit; } $createAccount2 = $LS->register($user2, $pass2, array( "email" => $email2, "name" => $firstname2, "lastname" => $lastname2, "gender" => $sex2, "country" => $country2, "DOB" => $birthdate2, "created" => date("Y-m-d H:i:s") // Just for testing ) ); //$createAccount = $LS->register($firstname,$lastname,$user,$sex,$country,$email,$pass,$birthdate,$created); if($createAccount2 === "exists"){ echo "User Exists."; }elseif($createAccount2 === true){ echo "Success. Created account."; } } ?> And the function from the class: /* A function to register a user with passing the username, password and optionally any other additional fields. */ public function register( $id, $password, $other = array() ){ if( $this->userExists($id) && (isset($other['email']) && $this->userExists($other['email'])) ){ return "exists"; }else{ $randomSalt = $this->rand_string(20); $saltedPass = hash('sha256', "{$password}{$this->passwordSalt}{$randomSalt}"); if( count($other) == 0 ){ /* If there is no other fields mentioned, make the default query */ //old query: ("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`) VALUES(:username, :password, :passwordSalt)"); //new query: ("INSERT INTO `{$this->dbtable}` (`username`, 'email' , `password`, `password_salt` , 'name' , 'lastname' , 'gender' , 'country' , 'DOB') VALUES(:username, :email, :pass, :passwordSalt, :firstname, :lastname, :gender, :country, :DOB)"); $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`) VALUES(:username, :password, :passwordSalt)"); }else{ /* if there are other fields to add value to, make the query and bind values according to it */ //old query: ("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`, $columns) VALUES(:username, :password, :passwordSalt, :$colVals)"); //new query: ("INSERT INTO `{$this->dbtable}` (`username`, 'email' , `password`, `password_salt` , 'name' , 'lastname' , 'gender' , 'country' , 'DOB') VALUES(:username, :email, :pass, :passwordSalt, :firstname, :lastname, :gender, :country, :DOB)"); $keys = array_keys($other); $columns = implode(",", $keys); $colVals = implode(",:", $keys); //l= $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`, $columns) VALUES(:username, :password, :passwordSalt, :$colVals)"); //INSERT INTO MyGuests (firstname, lastname, email)cLUES ('John', 'Doe', 'john@example.com') $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (username,email,password,password_salt,name,lastname,created,gender,country,DOB) VALUES ('$username2','$email2','$pass2','$saltedPass','$firstname2','$lastname2','$created2','$gender2','$country2','$birthdate2')"); print($sql); foreach($other as $key => $value){ $value = htmlspecialchars($value); $sql->bindValue(":$key", $value); } } /* Bind the default values */ $sql->bindValue(":username", $id); $sql->bindValue(":password", $saltedPass); $sql->bindValue(":passwordSalt", $randomSalt); $sql->execute(); return true; } } Thanks for your help. I am doing this because for a hobby I am trying to create a browser based game in which I use this login system to login the user to a main page then code all of the other pages myself. I have posted on stackoverflow and someone on their suggested that I should use a framework. If this is the case, can someone point me in the right direction? Thanks again, if you need any info ask.
  11. So I just started watching the videos from Stanford, Google, MIT and a few on youtube. One of them contained the code for using tkinter function to create an application window and I tried to put the same type of thing together can anyone tell me what I am doing wrong cause nothing is happeing for me. I am running linux mint: # - So this is what it feels like # - To be alive #!/user/bin/python import sys author = "Brian T. Flores" version = "0.1" sessionID = 0 #Get Interface from Tkinter import * #initialize interface root = Tk() #modify root window info root.title("Unknown Limits - Massive Multiplayer RPG") root.geometry("200x100") #initialize root window root.mainloop() #if session is > 0: #Get Player Info UserName = "Brian Flores" Password = "enterprise" rank = 32 #planetOverview planetName = "Earth" plasmaOnhand = 1000000000 titainiumOnhand = 340000 crystalOnhand = 55000000 magneticEnergyOnhand = 350000 ecosystem = "No" # yes or no depending on wars or natural disasters that could have damaged or destroyed your ecosystem if there is no ecosystem the atmosphere must be cleaned up and another must be transplanted from another world. ecosystemDamage = 10000; #Damage can result from experiments, wars, natural disasters. At 10,000 damage the ecosystem goes extinct. You can repair this damage my researching technologies and building machines to do such repair # else: # print "You are not logged in!"; # raw_input() Well for some reason it's not working. All I am doing here is setting some vars and using the root.tk function. If anyone has any Ideas or tips to get this basic script working let me know. Thank you, DaRedHead
  12. Hi everyone, I would like to know if: I have three different forms to create three different mysql codes. Now my code will generate the three mysql codes correctly but each time I tried to generate the second mysql code using another form, the previous will get wiped and therefore I can only have one mysql code working at the moment. (I apologize in advanced if my issue is not clearly stated.) Attached is the code that I have right now. I am trying to get all three mysql codes (Searchsql, Filtersql, Panelsql) correct so I can pass all three mysql queries to a function where it can combine all three queries into one array using the array_intersect function. Please kindly let me know your opinion on the problem and I would really appreciate the help. $object = new Three; class Three { public $Panel, $Search, $Filter; function save_Three() { while($Prow = sqli_fetch_array($Panel, MYSQLI_BOTH)) { $PanelName = $Prow ['name']; } while($Srow = sqli_fetch_array($Search, MYSQLI_BOTH)) { $SearchName = $Srow ['name']; } while($Frow = sqli_fetch_array($Filter, MYSQLI_BOTH)) { $FilterName = $Frow ['name']; } $Combined = array_intersect($Panel, $Search, $Filter); foreach ($Combined as $item) print $item; } } $Panelsql = "SELECT DISTINCT aID, name from test.article"; if (isset($_GET['pid'])) { $pID= $_GET['pid']; echo "$pID"; $Panelsql = "SELECT DISTINCT aID, name from test.a_m, test.platform, test.message, test.article where aid in (SELECT DISTINCT assocAID from test.a_m, test.platform, test.message where assocMID in (SELECT mID from test.message, test.platform where pID=$pID and pID = assocPID))"; } else if (isset($_GET['mid'])) { $mID= $_GET['mid']; $Panelsql = "SELECT DISTINCT aID, name from a_m, message, article where aid in (SELECT DISTINCT assocAID from a_m, message where mID=$mID and mID = assocMID)"; } else { $Panelsql = "SELECT DISTINCT aID, name from article"; } $object->Panel = $Panelsql; $aRegions = $_POST['RegionSelected']; $Filtersql = 'SELECT * FROM test.article'; if(isset($aRegions)) { $Filtersql .= ' WHERE 1 AND ('; foreach ($aRegions as $word) if($word==$aRegions[count($aRegions)-1]) { $Filtersql .= " Region = '". $word ."')"; } else { $Filtersql .= " Region = '". $word ."' OR"; } } //Population filtering function $aPopulations = $_POST['PopulationSelected']; if(isset($aPopulations)) { if(!isset($aRegions)){$Filtersql .= ' WHERE 1 AND ('; } else { $Filtersql .= ' AND ('; } foreach ($aPopulations as $word) if($word==$aPopulations[count($aPopulations)-1]) { $Filtersql .= " Population = '". $word ."')"; } else { $Filtersql .= " Population = '". $word ."' OR"; } } $object->Filter = $Filtersql; $Searchsql="SELECT * FROM test.article"; if (isset($_POST['search'])){ $st= ($_POST['search_box']); $Searchsql .= " WHERE name LIKE '%{$st}%' OR abstract LIKE '%{$st}%' OR Summary LIKE '%{$st}%' OR Keyword LIKE '%{$st}%' OR population LIKE '%{$st}%'OR region LIKE '%{$st}%'"; } $object->Search = $Searchsql;
  13. I am trying to build a website, where: 1) User logs in (UserA) 2) Inserting a name in the search box and pressing "Search", a list of all users matching that name is shown 3) The user selects a user (UserB) from that list (among several results) 4) By selecting the user (UserB) , a message box appears to insert text 5) The user(UserA) types the message 6) The user(UserA) presses the SUBMIT button and sends the message to the other user(UserB) The problem i face is how to pass the variables from my PHP script to the JavaScript script. Its easy for me to get the values of input fiedls, select fields or any other DOM element value. But if the value i need to pass to Javascript file to perform an AJAX call isnt inside a DOM element, how do i do it? For example, for me to determine the user that will send the message (userA), i will need several data. This data, i have them inside the PHP script as variables, but dont know how to pass them to Javascript file. Getting the data from the URL, or from a hidden input field or any other DOM element, is a solution, but i want to know the way that is safer and better. To summarize: -->[pass necessary data from PHP to JavaScript file]-->[perform an AJAX call] --> [return data to PHP Script] How do i do it? Thanks in advance.
  14. Hello guys, not sure why I keep getting this error, can anyone help me? Here is the code: $ext=end(explode('.',$thum));
  15. I want an if statement that not only checks for the existence of a variable, but which also checks all the variables already created for one with a specific value. For example, I have a loop which creates variables, but I don't want it to make two variables with the same value. The problem is, using if(isset(${'h'.$x}==false) && ${'h'.$x} != 3{ } won't work since the variable equal to 3 could be named h4, whereas this one will be named h5. I hoped I explained this efficiently enough, sorry about any confusion.
  16. All my code is returning is the username... Please help. index.php <?php include('user.class'); $user = new user("Jbonnett", "0", "Admin", "Jamie", "Bonnett", "jbonnett@site.co.uk", "01/09/1992"); echo "username: " . $user->getUsername() . "<br/>"; echo "id: " . $user->getId() . "<br/>"; echo "level: " . $user->getLevel() . "<br/>"; echo "Forename: " . $user->getForename() . "<br/>"; echo "Surname: " . $user->getSurname() . "<br/>"; echo "Email: " . $user->getEmail() . "<br/>"; echo "Dob: " . $user->getDob() . "<br/>"; ?> user.class <?php class user { private $username; private $id; private $level; private $forename; private $surname; private $email; private $dob; public function user($username, $id, $level, $forname, $surname, $email, $dob) { $this->setUsername($username); $this->setId($id); $this->setLevel($level); $this->setForename($forename); $this->setSurname($surname); $this->setEmail($email); $this->setDob($dob); } public function destroy() { unset($this->username); unset($this->id); unset($this->level); unset($this->forename); unset($this->surname); unset($this->uemail); unset($this->dob); } public function setUsername($username) { $this->username = $username; } public function getUsername() { return $this->username; } public function setId($id) { $this->id = $id; } public function getId() { return $this->$id; } public function setLevel($level) { $this->level = $level; } public function getLevel() { return $this->level; } public function setForename($forename) { $this->foreName = $forename; } public function getForename() { return $this->forename; } public function setSurname($surname) { $this->surName = $surname; } public function getSurname() { return $this->surname; } public function setEmail($email) { $this->email = $email; } public function getEmail() { return $this->email; } public function setDob($dob) { $this->dob = $dob; } public function getDob() { return $this->dob; } }; ?>
  17. Ok, I'm trying to adapt a bit of code. Right now it limits what it returns to 1 category, category "2", I need it to return items from categories 2,3,4,5,6,7. I know this is pretty basic, but I can't get it to work. The $includeCat part. Thanks! $currentItem = K2Table::getInstance('K2Item', 'Table'); $currentItem->load($itemID); $itemCat = $currentItem->get('catid'); $includeCat = 2; if($includeCat) $query .= " AND c.id = {$includeCat} "; $query .= " AND c.trash = 0 AND (i.id) IN ({$sql}) ORDER BY i.created DESC";
  18. ive got 3 errors which i have no clue what the problems are all 3 of them are related to near enough the same thing 1 of them is CompanyNameerr variable and the other to is CompanyName its confusing the hell out of me cause im pretty sure ive declared these variable. ( ! ) Notice: Undefined index: CompanyName in C:\wamp\www\AddLeads\addleads2.php on line 37 ( ! ) Notice: Undefined variable: CompanyNameErr in C:\wamp\www\AddLeads\addleads2.php on line 45 ( ! ) Notice: Undefined variable: CompanyName in C:\wamp\www\AddLeads\addleads2.php on line 68 and heres the code i used <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <? $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City); VALUES ('nelsons', 'luke', '', 'IT', '5 HIGHFIELD ROAD', 'LITTLEOVER', 'DERBY')"); mysqli_close($con); // define variables and set to empty values $companynameErr = $FirstNameErr = $Address1Err = $Address2Err = $AreaErr = $CityErr = ""; $companyname = $FirstName = $Address1 = $Address2 = $Area = $City = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") $allValid = true; { $allValid = false; } if($allValid) { // connect to db, create query, execute query } if($_POST['CompanyName']==null || $_POST['CompanyName']=="") { $allValid = false; } ?> <form action="insertaddleads.php" method="post"> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> CompanyName: <input type="text" name="companyname"> <span class="error">* <?php echo $CompanyNameErr;?></span> <br><br> FirstName: <input type="text" name="firstname"> <span class="error">* <?php echo $FirstNameErr;?></span> <br><br> Address 1: <input type="text" name="address1"> <span class="error">* <?php echo $Address1Err;?></span> <br><br> Address 2: <input type="text" name="address2"> <span class="error">* <?php echo $Address2Err;?></span> <br><br> Area: <input type="text" name="area"> <span class="error">* <?php echo $AreaErr;?></span> <br><br> City: <input type="text" name="city"> <span class="error">* <?php echo $CityErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> </form> <? echo $CompanyName; echo "<br>"; echo $FirstName; echo "<br>"; echo $Address1; echo "<br>"; echo $Address2; echo "<br>"; echo $Area; echo "<br>"; echo $City; echo "<br>"; ?> <?php foreach($_POST as $fieldName=>$fieldValue) { if($fieldValue == '') { print "<div>$fieldName is blank</div>"; } } ?> </body> </html>
  19. Hi. I'm going to create a web-based system in php. I wanna put 8 categorys, one on each row and behind each of them there will be 9 buttons.- to the right there vill be a 8x9 cells table. When i press one button the value of that buttons variable will increase with 1. After pressing the button im still at the same page still seeing all those buttons behind the categories. But the value to the button i just pressed will be shown in the table to the right. I may press several buttons a hundred times and the table still show the value (value = how many time i press each button). Can anyone help me on my way? I did work a lot with php for about 10 years ago, but i cant figure out how this could be done..
  20. I have converted an old pagination function I've had for years to a class as I've recently started to learn OOP The problem is that it doesn't display any anything except the <ul></ul> I've tried returning a variable but it comes back empty. I know it's something to do with my variables but I can't see what class Pagination { private $total_pages; private $page; private $webpage; public function __construct() { $this->total_pages; $this->page; $this->webpage; } /** * This function is called whenever the there are several records to be displayed in the table * This saves the page extending further down the page creating a long list of results * when all the results can be spread across multiple pages */ public function pagination_one($total_pages, $page, $webpage) { // Maximum number of links per page. If exceeded, google style pagination is generated $max_links = 6; $h=1; if($this->page>$max_links) { $h=(($h+$this->page)-$max_links); } if($this->page>=1) { $max_links = $max_links+($this->page-1); } if($max_links>$this->total_pages) { $max_links=$this->total_pages+1; } $paging = ''; $paging .= '<div class="page_numbers"> <ul>'; if($this->page > "1") { $paging .= '<li class="current"><a href="/'.$this->webpage.'/1">First</a></li> <li class="current"><a href="/'.$this->webpage.'/'.($this->page-1).'">Prev</a></li> '; } if($this->total_pages != 1) { for ($i=$h;$i<$max_links;$i++) { if($i==$this->page) { $paging .= '<li><a class="current">'.$i.'</a></li>'; } else { $paging .= '<li><a href="/'.$this->webpage.'/'.$i.'">'.$i.'</a> </li>'; } } } if(($this->page >="1")&&($this->page!=$this->total_pages)) { $paging .= '<li class="current"><a href="/'.$this->webpage.'/'.($this->page+1).'">Next</a></li> <li class="current"><a href="/'.$this->webpage.'/'.$this->total_pages.'">Last</a></li>'; } $paging .= '</ul> </div>'; return $this->page; } } $paging = new Pagination(); var_dump( $paging->pagination_one(3, 1, 'news')); <?php class Pagination { private $total_pages; private $page; private $webpage; public function __construct() { $this->total_pages; $this->page; $this->webpage; } /** * This function is called whenever the there are several records to be displayed in the table * This saves the page extending further down the page creating a long list of results * when all the results can be spread across multiple pages */ public function pagination_one($total_pages, $page, $webpage) { // Maximum number of links per page. If exceeded, google style pagination is generated $max_links = 6; $h=1; if($this->page>$max_links) { $h=(($h+$this->page)-$max_links); } if($this->page>=1) { $max_links = $max_links+($this->page-1); } if($max_links>$this->total_pages) { $max_links=$this->total_pages+1; } $paging = ''; $paging .= '<div class="page_numbers"> <ul>'; if($this->page > "1") { $paging .= '<li class="current"><a href="/'.$this->webpage.'/1">First</a></li> <li class="current"><a href="/'.$this->webpage.'/'.($this->page-1).'">Prev</a></li> '; } if($this->total_pages != 1) { for ($i=$h;$i<$max_links;$i++) { if($i==$this->page) { $paging .= '<li><a class="current">'.$i.'</a></li>'; } else { $paging .= '<li><a href="/'.$this->webpage.'/'.$i.'">'.$i.'</a> </li>'; } } } if(($this->page >="1")&&($this->page!=$this->total_pages)) { $paging .= '<li class="current"><a href="/'.$this->webpage.'/'.($this->page+1).'">Next</a></li> <li class="current"><a href="/'.$this->webpage.'/'.$this->total_pages.'">Last</a></li>'; } $paging .= '</ul> </div>'; return $this->page; } } $paging = new Pagination(); var_dump( $paging->pagination_one(3, 1, 'news'));
  21. Hi everybody, I created a trivia game which lets the user answer questions. So far I have created a skeleton version of it. The problem I am having is my variables are not saving in an array - the way I would like them to. I have a session array created. Also if you are using it the questions aren't answered yet. Here is my code : <html> <head> <title>Trivia</title> </head> <?php //Hides non-harmful errors error_reporting(E_ALL ^ E_NOTICE); //Gets the content from the question text file $file = $_SERVER['DOCUMENT_ROOT'] . "/class/Assignment1/questions.txt"; $contents = file($file); //Session Start session_start(); $answerOne = $_POST['answerOne']; $answerTwo = $_POST['answerTwo']; $answerThree = $_POST['answerThree']; $answerFour = $_POST['answerFour']; $answerFive = $_POST['answerFive']; $answerSix = $_POST['answerSix']; //Declaring my session variables for answers/questions $_SESSION['answers'] = array($answerOne, $answerTwo, $answerThree, $answerFour, $answerFive, $answerSix); $_SESSION['contents'] = array($contents[0], $contents[1], $contents[2], $contents[3], $contents[4], $contents[5]); $answerArray = $_SESSION['answers']; $questionsArray = $_SESSION['contents']; //Declaring my variables $answer = "answerOne"; $text = "text"; $submit = "submit"; $questions = $questionsArray[0]; //If the button is clicked. if (isset($_POST['submit']) == true ){ $clickCount = intval($_POST['clickCount']); $clickCount += 1; $questions = $questionsArray[1]; //If the clickCount = 1 if($clickCount == 1){ $answer = "answerTwo"; //If the clickCount = 2 }if($clickCount == 2){ $answer = "answerThree"; $questions = $questionsArray[2]; //if the clickCount = 3 }if($clickCount == 3){ $answer = "answerFour"; $questions = $questionsArray[3]; //If the clickCount = 4 }if($clickCount == 4){ $answer = "answerFive"; $questions = $questionsArray[4]; //If the clickCount = 5 }if($clickCount == 5){ $answer = "answerSix"; $questions = $questionsArray[5]; //If the clickCount = 6 }if($clickCount == 6){ $text = "hidden"; $submit = "hidden"; $questions = ""; print_r($answerArray) . "<br />"; } } ?> <body> <form action="trivia1.php" method="post"> <input type="hidden" name="clickCount" value="<?php echo $clickCount; ?>"> <label><?php echo $questions; ?></label> <input type="<?php echo $text; ?>" name="<?php echo $answer; ?>"> <input type="<?php echo $submit; ?>" name="submit"> </form> </body> </html>
  22. This should be pretty easy but I can get this to work right. I am dynamically adding rows to a table and I want to append the number of the current row to the variable, these variables are arrays. (ex. variable1[], variable2[]) Example Code function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var currentRow = $(this).closest('tr'); var cell1 = row.insertCell(0); cell1.style.textAlign = 'left'; cell1.innerHTML = "<a onClick=\"deleteRow('dataTable', this.parentNode.parentNode.rowIndex)\" align=\"left\"> Remove this Guest</a>"; var cell2 = row.insertCell(1); var element2 = document.createElement("input"); element2.type = "checkbox"; element2.name="breakfast" + currentRow + "[]"; cell2.appendChild(element2); var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "checkbox"; element2.name="breakfast" + row + "[]"; cell3.appendChild(element2); So, I've tried using currentRow and row, still not working. Anyone have ideas?
  23. Hi all, I am new here and have a question. I have created a search tool for a database table which I am currently searching through the Description column in the table but would like to add the Title, and the Category columns as well. My script is below. it searches, creates the table adn displays adn paginates perfectly, but as soon as I try to add more variables it crashes. It seems to be in the $construct variable I am building to fetch adn display the results. Any assistance would be great. I would like to be able to, in index.php search feild, put Burger and it would look through Title, Catagory, adn Description within the table and display the results. This is the Index.php script <html> <head> <title>RECIPE SEARCH</title> </head> <body> <form action='search.php' method='GET'> <center> <h1>CHEF JAMIE RECIPE SEARCH TOOL</h1><br/> <h4>Currently searching through recipe ingredients.</h4> <input type='text' size='50' name='search'></br></br> <input type='submit' name='submit' value='Search source code' ></br></br></br> </center> </form> </body> </html> And this is the search.php page <?php $button = $_GET ['submit']; $search = $_GET ['search']; if(strlen($search)<=1) echo "Search term too short"; else{ echo "You searched for <b>$search</b> <hr size='1'></br>"; mysql_connect("localhost","xxxx","xxxxxx!"); mysql_select_db("chefjami_CJG2"); $search_exploded = explode (" ", $search); foreach($search_exploded as $search_each) { $x++; if($x==1) $construct .="Description LIKE '%$search_each%'"; else $construct .="AND Description LIKE '%$search_each%'"; } $constructs ="SELECT * FROM recipes WHERE $construct"; $run = mysql_query($constructs); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1. Try more general words. for example: If you want to search 'how to create a website' then use general keyword like 'create' 'website'</br>2. Try different words with similar meaning</br>3. Please check your spelling. </br>4. <a href='index.php'>Go back to search</a>"; else { echo "$foundnum results found ! <a href='index.php'>Go back to search</a><p>"; $per_page = 1; $start = $_GET['start']; $max_pages = ceil($foundnum / $per_page); if(!$start) $start=0; $getquery = mysql_query("SELECT * FROM recipes WHERE $construct LIMIT $start, $per_page"); while($runrows = mysql_fetch_assoc($getquery)) { $Title = $runrows ['Title']; $Description = $runrows['Description']; $Catagory = $runrows ['Catagory']; echo " <b><h3>$Title</h3></b><br> $Description<br> <strong>Category: $Catagory</strong><p> <hr> "; } //Pagination Starts echo "<center>"; $prev = $start - $per_page; $next = $start + $per_page; $adjacents = 3; $last = $max_pages - 1; if($max_pages > 1) { //previous button if (!($start<=0)) echo " <a href='search.php?search=$search&submit=Search+source+code&start=$prev'>Prev</a> "; //pages if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { $i = 0; for ($counter = 1; $counter <= $max_pages; $counter++) { if ($i == $start){ echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> "; } $i = $i + $per_page; } } elseif($max_pages > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if(($start/$per_page) < 1 + ($adjacents * 2)) { $i = 0; for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($i == $start){ echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> "; } $i = $i + $per_page; } } //in middle; hide some front and some back elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2)) { echo " <a href='search.php?search=$search&submit=Search+source+code&start=0'>1</a> "; echo " <a href='search.php?search=$search&submit=Search+source+code&start=$per_page'>2</a> .... "; $i = $start; for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++) { if ($i == $start){ echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> "; } $i = $i + $per_page; } } //close to end; only hide early pages else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=0'>1</a> "; echo " <a href='search.php?search=$search&submit=Search+source+code&start=$per_page'>2</a> .... "; $i = $start; for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++) { if ($i == $start){ echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> "; } $i = $i + $per_page; } } } //next button if (!($start >=$foundnum-$per_page)) echo " <a href='search.php?search=$search&submit=Search+source+code&start=$next'>Next</a> "; } echo "</center>"; } } ?>
  24. Hi guys, I have a CMS system which I've spent the last week fixing. It's built in PHP, and now I'm stuck on the most simplest of tasks. I can't figure out why I am receiving an "undefined variable" error within this block of code. Any help would be greatly appreciated. function track_app($app_id, $lang_code, $str, $instance) { $lang_id = get_lang_id($lang_code); if ($instance > 0) { if ($str == 'LOAD_APP' || $str == 'APP_LOADED') { $query = "INSERT INTO `tracking` ( `APPLICATION_ID`, `LANG_ID`, `INFO`, INSTANCE_ID ) VALUES ( $app_id, $lang_id, '$str', $instance )"; } mysql_query("INSERT INTO `tracking_backup` ( `APPLICATION_ID`, `LANG_ID`, `INFO`, INSTANCE_ID ) VALUES ( $app_id, $lang_id, '$str', $instance )"); mysql_query("UPDATE `instances` SET ACTIVE = 1 WHERE INSTANCE_ID = $instance"); } else { $query = "INSERT INTO `tracking` ( `APPLICATION_ID`, `LANG_ID`, `INFO` ) VALUES ( $app_id, $lang_id, '$str' )"; } mysql_query($query); }
  25. I'f I do a var_dump after taking in the array from the foreach statement then all of the variables are present. However, by the time the variables go through the switch statement and we run the first case it only prints out the URL for most of the results and URL_title for others. foreach ($js -> results as $item) { $Faroo[$o] = array ('url'=>$item->url, 'url_title'=>$item->title, 'snippet' =>$item->kwic, 'rank' => 100-$o, 'engine' => 'Faroo'); //var_dump($Faroo[$o]); $o++; } $s=$s+10; $e=$e+10; } } ?> <?php $agg = $_POST['agg']; $full_count=0; switch ($agg) { case 'Aggregated': while ($full_count<=$bing_count) //while m <= bing results m = 0; { $r_set[$full_count] = $bing_results[$full_count]; //load bing[m] in to r_set[m] $full_count++; //m = increments for every bing result } $b_count=0; $r_count=0; //reset b_count so we can start again and create r_count so we can loop through the existing unilist while ($b_count<$blekko_count) // 0 < blekko { // We reset postion in while ( $Blekko[$b_count]['url']!=$r_set[$r_count]['url']) { //check that the url is not already in the list $r_count++; //increment z to loop through the full r_set if ($r_count>$full_count) //When r_count counts through the full_count break (after finding all the matches)//should that not be b_count? { break; } } if ( $Blekko[$b_count]['url'] == $r_set[$r_count]['url']) { //if it is in the list then add the score $r_set[$r_count]['rank']+=$Blekko[$b_count]['rank']; $b_count++; //move to next element } else { //if not in the list then add it $full_count++; //y is used to increment on from this point $r_set[$full_count]=$Blekko[$b_count]; $b_count++; //if r_count is not larger then full count and url's do not match then we increment b_count } } $b_count=0; $r_count=0; //reset both counters again while ($b_count<$o) { // We reset postion in while ( $Faroo[$b_count]['url']!=$r_set[$r_count]['url']) { //check that the url is not already in the list $r_count++; if ($r_count>$full_count) { break; } } if ( $Faroo[$b_count]['url'] == $r_set[$r_count]['url']) { //if it is in the list then add the score $r_set['rank'][$r_count]+=$Faroo[$b_count]['rank']; $b_count++; //move to next element } else { //if not in the list then add it $full_count++; //y is used to increment on from this point $r_set[$full_count]= $Faroo[$b_count]; $b_count++; } } echo $full_count; array_multisort($r_set, SORT_ASC, 'rank'); //not sure if this works or not yet $echo_l = 0; while ($echo_l<=$full_count) { echo 'URL: '.$r_set[$echo_l]['url'].'<br>'; echo 'URL TITLE: '.$r_set[$echo_l]['url_title'].'<br>'; echo 'SNIPPET: '.$r_set[echo_l]['snippet'].'<br>'; echo 'RANK: '.$r_set[echo_l]['rank'].'<br>'; echo 'ENGINE: '.$r_set[echo_l]['engine'].'<br>'; var_dump($Blekko[$echo_l]); $echo_l++; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.