PHP - Compare Words In Two Arrays And Calculate Number Of Hits
Hi guys,
I am new to PHP/coding and am trying to look for 1. A way of comparing the words in one static array against other dynamically created arrays (created from mysql queries) 2. Work out how many similar words there are - then assign that number to that array My static array is...$comparewithme = array with values = this is an example of an array Mysql_query("select id, words from table_example") Results from query are put into an array that is named according to id.. $result2 = array with values = this is an example of queries $result3 = array with values = this is not an example of php Comparison should give the following info Comparing $comparewithme with $result2 should generate a hit rate of 5 (similar words=this is an example of)... Comparing $comparewithme with $result3 should generate a hit rate of 4 (similar words=this is an example)... Any ideas greatly appreciated...thanks in advance Similar Tutorialsjust a newbie in php i got the code in this forum and it really works, but not that exact, it can really compare word from array to per line in a file. but what im trying to do is, to compare the exact word/number. if(strstr($line,$key)) echo $line; if $key = 123 and line 1 is 1234 and line 2 is 123 it will still output line1 Code: [Select] $key = "waka"; $fc = file("file.txt"); $f = fopen("file.txt","r"); foreach($fc as $line) { if(strstr($line,$key) echo 4line; } fclose($f); ?> I need to compare several arrays...to narrow down a bunch of mysql selects. I can't figure out which of the array_diff, array_unique, array_merge options there are. I need to get an array of umpires (baseball), then compare that to the array of umpires that can work a given level, then compare that to the array of umpires that can work at that school, and finally compare that to the array of umpires who have asked for the day off. In the code below, all of the selects work...the echo's that are commented out printed out what I expected them to. I'm having a problem with the array comparisons at the end of this code: Code: [Select] <?php //connect to database $dbc = mysql_pconnect($host, $username, $password); mysql_select_db($db,$dbc); //get info of game $sql = "SELECT sport,home,day FROM games WHERE `game_id` = $_GET[game]"; $rs = mysql_query($sql,$dbc); while($row = mysql_fetch_array($rs)) { $game_array = $row['sport']; $home_team_array = $row['home']; $game_day_array = $row['day']; } //list of all umpires in association $sql = "SELECT ump_id FROM ump_names WHERE '$_SESSION[association_id]' = `association_id`"; $rs = mysql_query($sql,$dbc); while($row = mysql_fetch_array($rs)) { $name_array[] = $row['ump_id']; // echo "<br /><br />All Ump ID's Array = "; // foreach($name_array as $name_array_final) { // echo $name_array_final . "<br />"; // } } //get bad schools list $sql = "SELECT ump_id FROM bad_school WHERE '$_SESSION[association_id]' = `association_id` AND `school` = '$home_team_array' and `sport` = '$game_array'"; $rs = mysql_query($sql,$dbc); while($row = mysql_fetch_array($rs)) { $bad_school_array[] = $row['ump_id']; // echo "<br /><br />Bad School Array = "; // foreach($bad_school_array as $bad_school_array_final) { // echo $bad_school_array_final . ", "; // } } //get official list at this game's level $sql = "SELECT ump_id FROM ump_names WHERE `association_id` = '$_SESSION[association_id]' AND `$game_array` = '1'"; $rs = mysql_query($sql,$dbc); while($row = mysql_fetch_array($rs)) { $official_level_array[] = $row['ump_id']; // echo "<br /><br />Officials that can work this level of game = "; // foreach($official_level_array as $official_level_array_final) { // echo $official_level_array_final . ", "; // } } //get vacation list $sql = "SELECT ump_id FROM days_off WHERE '$_SESSION[association_id]' = `association_id` AND `day` = '$game_day_array'"; $rs = mysql_query($sql,$dbc); while($row = mysql_fetch_array($rs)) { $days_off_array[] = $row['ump_id']; // echo "<br /><br />Officials that are on vacation this day = "; // foreach($days_off_array as $days_off_array_final) { // echo $days_off_array_final . ", "; // } } //$first_step = array_merge($official_level_array, $name_array); $first_step = array_merge($official_level_array, $name_array); $first_step_part_2=array_unique($first_step); //$second_step = array_merge($bad_school_array, $first_step); $second_step = array_merge($bad_school_array, $first_step_part_2); $second_step_part_2=array_unique($second_step); //$third_step = array_merge($days_off_array, $second_step); $third_step = array_merge($days_off_array, $second_step_part_2); $third_step_part_2=array_unique($third_step); echo "These umpires are available for this game:<br />"; foreach ($third_step as $iamavailable) { echo "$iamavailable<br />"; } ?> This prints out: Quote 2 1 2 4 5 6 10 14 15 3 7 8 9 11 12 13 16 17 It should only print out 4, 5, 6, 10, 14, 15. What I want to do is: compare $official_level_array and $name_array...only keep those that are in $official_level_array. Then, compare that result with $bad_school_array...removing those in the $bad_school_array...and keeping the ones that are left. Then, compare that result, with $days_off_array...removing those in the $days_off_array...and keeping the ones that are left. Print out what's left... Where am I going wrong? Hi,
please help me to solve my query... I was incurring a problem in executing a PHP code which executes 'n' number of data sets..
For example -- in the below shown outputs, I need to eliminate executing the 4th output which is similar (repeated data) to the 1st output,
input output
4,4,5,6,5 4,4,5,5,6
4,4,5,7,5 4,4,5,5,7
4,4,5,7,6 4,4,5,6,7
4,4,6,5,5 4,4,5,5,6
Kindly send me the function details to execute it without repetition.
Thanks a lot for your support!
Regards,
Maanu
I have two arrays, X and Y, which contain names. The arrays are of the same size. The arrays are related to each other such that for each pair X[n] , Y[n] X is friends with Y. For example: X[0,1,2] = [Link, Cloud, Cloud, Mario, Mario, Luigi] Y[0,1,2] = [Zelda, Barrett, Tifa, Luigi, Bowser, Mario] Link is friends with Zelda Cloud is friends with Barrett and Tifa Mario is friends with Luigi and Bowser Luigi is friends with Mario I want to loop through these arrays and, for each unique name, find all of that person's friends. I then want to print the results to a text file, like so: Link, Zelda Cloud, Barrett, Tifa Mario, Luigi Luigi, Mario I know how to do this theoretically, but I just need help with the PHP syntax. Thanks very much. Hi, I have this code :- $datestarted = $row['datestarted']; $datestart=date("l d/m/Y @ H:i:s",strtotime($datestarted)); Which is been echo'd like this :- echo ' <tr align="center"'.$rowbackground.'> <td>'.$datestart.'</td> <td align="center"> '; So for example I get this output :-Sunday 18/04/2021 @ 10:45:26 The data in the DB for the above is stored like this :-2021-04-18 10:45:26
What I'd like to do is also echo how many days ago this date was, all of the examples I've tried don't seem to work though? I've tried several scripts to get the number of days between two dates, but none of them will work. Obviously I'm doing something wrong. One thing I know that is causing a problem is that I'm using variables instead of an actual typed in date. Which in my opinion is how most people would do it - variables not actual dates. I've tried these: $todaydate = date('Y/m/d'); $now = date('Y-m-d'); $dd2 = strtotime($now); $thisyear = 2019; $payment_day = 29; $pay_month = 6; if($pay_month == 1){$newpaymentmonth = 2;} if($pay_month == 2){$newpaymentmonth = 3;} if($pay_month == 3){$newpaymentmonth = 4;} if($pay_month == 4){$newpaymentmonth = 5;} if($pay_month == 5){$newpaymentmonth = 6;} if($pay_month == 6){$newpaymentmonth = 7;} if($pay_month == 7){$newpaymentmonth = 8;} if($pay_month == 8){$newpaymentmonth = 9;} if($pay_month == 9){$newpaymentmonth = 10;} if($pay_month == 10){$newpaymentmonth = 11;} if($pay_month == 11){$newpaymentmonth = 12;} if($pay_month == 12){$newpaymentmonth = 1;} $threezero = array(4, 6, 9, 11); // months with 30 days // Deal with months that have only 28 days or 30 days, setting the payment day to accommodate months with fewer days. if ($payment_day > 28 && $pay_month == 2) { $payment_day = 28; } elseif ($payment_day == 31 && in_array($pay_month, $threezero)) { $payment_day = 30; } else { $payment_day = $payment_day; } if ($newpaymentmonth == 1){$newpaymentyear = $thisyear + 1;}else{$newpaymentyear = $thisyear;} $newpaymentdate = date($newpaymentyear.'-'.$newpaymentmonth.'-'.$payment_day); echo date("Y-m-d", $newpaymentdate) . "<br><br>"; $ddate = new DateTime($thisyear.'-'.$newpaymentmonth.'-'.$payment_day); $ddate->add(new DateInterval('P5D')); echo $ddate->format('Y-m-d') . " - New month payment date with 5 day grace period added.<br><br>";
Now, how to calculate the difference in days between today's date and $ddate? I tried the below, but none worked. function DateDiff($strDate1,$strDate2){ return (strtotime($strDate2) - strtotime($strDate1))/ ( 60 * 60 * 24 ); // 1 day = 60*60*24 } echo "Date Diff = ".DateDiff($now,$ddate)."<br>"; $timeDiff = abs($now - $ddate); $numberofdays = $timeDiff/86400; echo "<p>$numberofdays - days between today's date and payment w/grace date.</p>"; $date1 = $now; $date2 = $ddate; $diff = date_diff($date1,$date2); echo 'Days Count - '.$diff->format("%a"); $date1=$now; $date2=$ddate; function dateDiff($date1, $date2) { $date1_ts = strtotime($date1); $date2_ts = strtotime($date2); $diff = $date1_ts - $date2_ts; return round($diff / 86400); } $dateDiff= dateDiff($date1, $date2); printf("Difference between in two dates : " .$dateDiff. " Days "); print "</br>"; This one returns 18112 Days. Should be days 7 days from 2019-08-05. None of these work, so I'm doing something wrong. Any ideas? Thanks Edited August 9, 2019 by cyberRobotfixed typo <?php require_once('upper.php'); if(isset($_POST['submit'])) { //This is code in which we can choose the type and size file uploaded or upload anything. We can declare the path of folder or can do without it. if($_FILES['uploaded_file']['size']< 200000) { /*if($_FILES['uploaded_file']['error']>0) { echo "Error occurs".$_FILES['up_test']['error']."<br/>"; } else{*/ $Title=$_POST['Title']; $City=$_POST['City']; $Content=$_POST['Content']; $Date=$_POST['Date']; echo "Uploaded Title--$Title<br/>"; echo "Uploaded City--$City<br/>"; echo "Uploaded Content--$Content<br/>"; echo "Uploaded Date of Event--$Date<br/>"; /*if(file_exists("upload/". $_FILES['uploaded_file']['name'])) { echo "File".$_FILES['uploaded_file']['name']." already exists"; } else {*/ move_uploaded_file($_FILES['uploaded_file']['tmp_name'],"upload/".$_FILES['uploaded_file']['name']); echo "File uploaded-- ".$_FILES['uploaded_file']['name']."<br><br><br>"; } else{ echo "File size is too large or Not Uploaded "; } $path="upload/".$_FILES['uploaded_file']['name']; require_once('database.php'); $result=mysqli_query($dbc,"insert into events (Title,City,Content,Photo,Date) values ('$Title','$City','$Content','$path','$Date')") or die ('Not Connected Events'); //echo "PAth"; } ?> <html> <head> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data"> <h4>Enter Events</h4><br> Enter Title <br><textarea rows="10" cols="10" name="Title"></textarea><br> Enter City <br><input type="text" name="City"><br> Enter Content <br><textarea rows="10" cols="10" name="Content"></textarea><br> <label for="file">Upload Photo<br></label> <input type="file" name="uploaded_file" /> <br /> Enter Date of Event<br> <input type="text" name="Date" value="yyyy-mm-dd"><br> <input type="submit" name="submit" value="Upload" /> </form> <?php require_once('lower.php');?> </body> </html> Hi friends............... In above code when i upload title or content within range of 20 words it works properly but when I increase numbers of words till approx. 100 words. It gives an error "Not Connected Events". Not any file is uploaded in database. I set the length of title and content in phpmyadmin is 500 and 1000 and type is varchar respectively. I can't understand where is problem???????? I think it's about something size??????? Help me Anyone??????????????? I have a string in the form of "word1-word2-word3-word4-word5-word-6-word7", but I want to shorten it to 5 words only. Hi all, please bare with me i am a newbie to this forum, i will try my best to provide all clear accurate information where possible, please find a below breakdown, i've had a little help from a user already but as am still getting problems and confused i will take his advise am post it in the right place ! 1) I have the below code and wish to ban specifc words, numbers and emails of my choice. 2) If the users enter a baned word etc either nothing will happen or it will forward them to another page. Please find attached index.php which is full working script of where i wish to add my banned words code too, also please find attached indextest.php containing the working script and code of bannng specfic words that i can't get to work. When i run indextest.php on my linux server the whole page displays perfectly but when you enter a baned or unbaned word and click submit nothing happens at all, so am very confused to where am going wrong. Any kind, helpfull guides to what i'm doing wrong would be highly appriciate as i do want to learn from my mistakes. All the best Steve Hi all - I'm setting up a custom PHP blog. It pulls the data from a MySQL database which includes HTML tags (<p><div><span> etc...). I would like to display only up to 50 words per post on the blog page, which users can then read and click a link to then see the entire post. I've developed some code which does this, however, it seems to be stripping my HTML tags... Very sad! Would be very very grateful if one (or more) of you kind lot would have a look at my code and let me know if there is a easier (I'm all for easy) and proper way of implementing this so that it works without stripping my HTML tags. Cheers!!! Code: [Select] // Counts number of blog words in the content $blog_content_words = str_word_count($blog["content"], 1); // Sets the blog_words variable to 0 $blog_words = 0; // Prints title on page as a permalink to a post echo '<h1><a href="blog.php?id='.$blog["id"].'">'.$blog["title"].'</a></h1><p>'; // Loops while blog_word is under 50 while($blog_words < 50) { // Prints a word from blog_content_words array of blog post and adds a space afterwards echo $blog_content_words["$blog_words"]." "; // Adds 1 to the blog_words counter ++$blog_words; } // Adds a read more link to the post which links to full blog post echo '... <a href="blog.php?id='.$blog["id"].'">[read more]</a></p>'; Create a data form that should accept odd number of words in a particular sentence
Input Example: I am working in retailon.
and should display the output as reversing first and last word and second word to fourth word
and so on and the middle word should be same and should also display the number of words.
Output Example: retailon in working am i.
words=5.
Input:I am Working in Google.
Output:Google in Working am I.
Words:5
am i going about this in the right way? it doesn't seem to be echoing anything Code: [Select] <?php mysql_select_db($database_uploader, $uploader); $totalHits = mysql_query("SELECT SUM(hits) AS totalHits FROM userDataTracking") or die(mysql_error()); mysql_close($con); echo $totalHits; ?> Greetings to all! I am very new to this so I may not be on the right track. I am providing some code I have because I think this is the best way to explain what I am trying to do. I have a database and php pages that generate a pedigree when one selects any particular dog from the search page. If anyway has a tip on how to simplify this, I would sure appreciate it!! First, I request an array for the dog selected: Code: [Select] $sql = "SELECT RegName, SireID, DamID FROM pedigrees WHERE ID="; $thisDogQ = $sql . $values["ID"]; $thisDogR = db_query($thisDogQ,$conn); $thisDogRow_value = mysql_fetch_assoc($thisDogR); $thisDogRow_value = array ( 'RegName' => $thisDogRow_value['RegName'], 'SireID' => $thisDogRow_value['SireID'], 'DamID' => $thisDogRow_value['DamID']); </code> //Next I request the same information for his sire <code> if (is_numeric($thisDogRow_value['SireID'])) { $query_SireQ = $sql . $thisDogRow_value['SireID']; $SireR = mysql_query($query_SireQ, $conn) or die(mysql_error()); $SireRow_value = mysql_fetch_assoc ($SireR); $SireRow_value = array ( 'RegName' => $SireRow_value['RegName'], 'SireID' => $SireRow_value['SireID'], 'DamID' => $SireRow_value['DamID']); </code> //and then his dam <code> if (is_numeric($thisDogRow_value['DamID'])) { $query_DamQ = $sql . $thisDogRow_value['DamID']; $DamR = mysql_query($query_DamQ, $conn) or die(mysql_error()); $DamRow_value = mysql_fetch_assoc ($DamR); $DamRow_value = array ( 'RegName' => $DamRow_value['RegName'], 'SireID' => $DamRow_value['SireID'], 'DamID' => $DamRow_value['DamID']); </code> Now, here's the rub: Now I need the sire and the dam for those 2 [described above] so this time through, I will need the same information for FOUR dogs. The next time will be for EIGHT, then SIXTEEN - and so on until there are a total of 256 dogs. <code> //Get PatGrandSire 2 if (is_numeric($SireRow_value['SireID'])) { $PatGrandSireQ = $sql . $SireRow_value['SireID']; $PatGrandSireR = mysql_query ($PatGrandSireQ, $conn) or die(mysql_error()); $PatGrandSireRow_value = mysql_fetch_assoc ($PatGrandSireR); $PatGrandSireRow_value = array ( 'RegName' => $PatGrandSireRow_value['RegName'], 'SireID' => $PatGrandSireRow_value['SireID'], 'DamID' => $PatGrandSireRow_value['DamID']); //GetPatGrandDam 17 if (is_numeric($SireRow_value['DamID'])) { $PatGrandDamQ = $sql . $SireRow_value['DamID']; $PatGrandDamR = mysql_query ($PatGrandDamQ, $conn) or die(mysql_error()); $PatGrandDamRow_value = mysql_fetch_assoc ($PatGrandDamR); $PatGrandDamRow_value = array ( 'RegName' => $PatGrandDamRow_value['RegName'], 'SireID' => $PatGrandDamRow_value['SireID'], 'DamID' => $PatGrandDamRow_value['DamID']); //Get Pat1GGrandSire-3 if (is_numeric($PatGrandSireRow_value['SireID'])) { $Pat1GGrandSireQ = $sql . $PatGrandSireRow_value['SireID']; $Pat1GGrandSireR = mysql_query ($Pat1GGrandSireQ, $conn) or die(mysql_error()); $Pat1GGrandSireRow_value = mysql_fetch_assoc ($Pat1GGrandSireR); $Pat1GGrandSireRow_value = array ( 'RegName' => $Pat1GGrandSireRow_value['RegName'], 'SireID' => $Pat1GGrandSireRow_value['SireID'], 'DamID' => $Pat1GGrandSireRow_value['DamID']); if (is_numeric($PatGrandSireRow_value['DamID'])) { $Pat1GGrandDamQ = $sql . $PatGrandSireRow_value['DamID']; $Pat1GGrandDamR = mysql_query ($Pat1GGrandDamQ, $conn) or die(mysql_error()); $Pat1GGrandDamRow_value = mysql_fetch_assoc ($Pat1GGrandDamR); $Pat1GGrandDamRow_value = array ( 'RegName' => $Pat1GGrandDamRow_value['RegName'], 'SireID' => $Pat1GGrandDamRow_value['SireID'], 'DamID' => $Pat1GGrandDamRow_value['DamID'], 'Title' => $Pat1GGrandDamRow_value['Title'], 'Title2' => $Pat1GGrandDamRow_value['Title2'], 'Title3' => $Pat1GGrandDamRow_value['Title3'], 'Title4' =>$Pat1GGrandDamRow_value['Title4'], 'Title5' => $Pat1GGrandDamRow_value['Title5'], 'Title6' =>$Pat1GGrandDamRow_value['Title6'], 'Title7' => $Pat1GGrandDamRow_value['Title7'], 'Title8' =>$Pat1GGrandDamRow_value['Title8'], 'Title9' => $Pat1GGrandDamRow_value['Title9'], 'Addl_Titles' => $Pat1GGrandDamRow_value['Addl_Titles']); //Get Pat2GGrandSire-18 if (is_numeric($PatGrandDamRow_value['SireID'])) { $Pat2GGrandSireQ = $sql . $PatGrandDamRow_value['SireID']; $Pat2GGrandSireR = mysql_query ($Pat2GGrandSireQ, $conn) or die(mysql_error()); $Pat2GGrandSireRow_value = mysql_fetch_assoc ($Pat2GGrandSireR); $Pat2GGrandSireRow_value = array ( 'RegName' => $Pat2GGrandSireRow_value['RegName'], 'SireID' => $Pat2GGrandSireRow_value['SireID'], 'DamID' => $Pat2GGrandSireRow_value['DamID'], 'Title' => $Pat2GGrandSireRow_value['Title'], 'Title2' => $Pat2GGrandSireRow_value['Title2'], 'Title3' => $Pat2GGrandSireRow_value['Title3'], 'Title4' => $Pat2GGrandSireRow_value['Title4'], 'Title5' => $Pat2GGrandSireRow_value['Title5'], 'Title6' => $Pat2GGrandSireRow_value['Title6'], 'Title7' => $Pat2GGrandSireRow_value['Title7'], 'Title8' => $Pat2GGrandSireRow_value['Title8'], 'Title9' => $Pat2GGrandSireRow_value['Title9'], 'Addl_Titles' => $Pat2GGrandSireRow_value['Addl_Titles']); //Get Pat2GGrandDaminfo-25 if (is_numeric($PatGrandDamRow_value['DamID'])) { $Pat2GGrandDamQ = $sql . $PatGrandDamRow_value['DamID']; $Pat2GGrandDamR = mysql_query ($Pat2GGrandDamQ, $conn) or die(mysql_error()); $Pat2GGrandDamRow_value = mysql_fetch_assoc ($Pat2GGrandDamR); $Pat2GGrandDamRow_value = array ( 'RegName' => $Pat2GGrandDamRow_value['RegName'], 'SireID' => $Pat2GGrandDamRow_value['SireID'], 'DamID' => $Pat2GGrandDamRow_value['DamID']); I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? Hi all, Using a form with check boxes divided into different categories, I collect data selected by the user. I now want to combine each choice in each category with each choice in the other categories and list the combinations to the user. If the user chooses one or more options in each category, it is relatively easy to nest foreach loops, since the number of categories will always be the same. For example, if the form contains three categories of options, the code will be: Code: [Select] foreach ($form['cat_1'] as $k1 => $val1) { foreach ($form['cat_2'] as $k2 => $val2) { foreach ($form['cat_3'] as $k3 => $val3) { echo $val1.' _ '.$val2.' _ '.$val3.'<br/>'; } } } Things get complicated if the user does not select options within a given category. More generally, I want to be able to generate the list regardless of the number of categories in which the user selects options. Thank you in advance for your advice. Hello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. I need to display a number(the number is retrieved from the db) in the form input field such that only the last 4 digits is visbile, the remaining can be masked as * or X or whatever is applicable. I know the last 4 can be obtained as follows: Code: [Select] $number=substr($number,-4,4); But when i hit the submit button the form validates the input field and checks if the number is a valid number of a specific format. Therefore when I click on the submit button then I should still be able to unmask the masked numbers or do something similar that would help me validate the whole number. Code: [Select] <input type="text" name="no" value="<?php if(!empty($number)){ echo $number;} ?>"> I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! |