PHP - Adding Serial Number To My Function
I made a function which displays the left and right children of the root. However i need to add serial numbers to them. Due to Recursive functions i'm not quite able to to do so . Can someone please help me?
Code: [Select] function side_display($root) { $sql = "SELECT lchild,rchild FROM tree WHERE parent='".$root."'"; $sqlexec = mysql_query($sql); $array = mysql_fetch_array($sqlexec); if(!empty($array['lchild']) && $array['lchild'] != '0') { echo "<tr>"; echo "<td>".($array['lchild'])."</td>"; $get = "SELECT * FROM member WHERE member_id='".$array['lchild']."'"; $execget = mysql_query($get); $getarray = mysql_fetch_array($execget); echo "<td>".$getarray['fname']." ".$getarray['lname']."</td>"; echo "<td>".$getarray['id_sponsor']."</td>" ; echo "<td>Left</td>"; echo "<td>".$getarray['doj']."</td>" ; echo "</tr>"; side_display($array['lchild']); } if(!empty($array['rchild']) && $array['rchild'] != '0') { echo "<tr>"; echo "<td>".($array['rchild'])."</td>"; $get = "SELECT * FROM member WHERE member_id='".$array['rchild']."'"; $execget = mysql_query($get); $getarray = mysql_fetch_array($execget); echo "<td>".$getarray['fname']." ".$getarray['lname']."</td>"; echo "<td>".$getarray['id_sponsor']."</td>" ; echo "<td>Right</td>"; echo "<td>".$getarray['doj']."</td>" ; echo "</tr>"; side_display($array['rchild']); } } Similar TutorialsHow can you use PHP to generate a serial number? e.g. DF34-VB89-98AP-34NQ-QQUI-23AW So I have this function which generates a random serial # that is 12 characters long. However I want to insert a dash every four characters like so: XXXX-XXXX-XXXX Any suggestions? Code: [Select] <?php $serial1 = get_serial_num(12); //Serial # function function get_serial_num($number_cnt){ $ret_arr = array(); $serial = ""; $ser_num = array("1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); for($i = 0; $i < $number_cnt; $i++){ $rand = rand(0,count($ser_num)-1); $val = wordwrap($ser_num[$rand],1,"\n", true); $serial .= $val; } return $serial; } echo ''.$serial1.''; ?> Warning: I am a bit noobish. Please i'm working on a project and i need to write a code that generates a unique random serial number.How can i go about it? Hi all. I am trying to add 1 to a number. The problem I have is that the number is 4 digits long. So for example the number could be 0007. I add one and it returns 8. I need it to return 0008. Code: [Select] <?php $next = 0007 + 1; echo $next; ?> Can anyone show me how I can get the number to be 4 digits? Thank you Good day: Im trying to add a number every time a person visits the page. here is the code Im using. Any help will be appreciated. Code: [Select] <?php $aid = $_GET['aid']; $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT visits FROM articles_description WHERE id=$aid"; $result=mysql_query($query); $num=mysql_numrows($result); <?php while ($j < $num) { $visits = $num[0] + 1; } $query = "UPDATE articles_description SET visits = $visits WHERE id = $aid"; if(mysql_query($sql_query)) { echo "Record updated successfully"; $j++; } mysql_close(); ?> Hi, I'm just starting PHP and I ran into a simple problem (that I can fix), but I just want to understand why my first approach doesn't work. I was testing multiplications and additions and the result I got was unexpected. Here is the code that doesn't work: Code: [Select] <?php $number1 = 5; $number2 = 10; print $number1." multiplied by ".$number2." + 1000 = ".$number1*$number2+1000; ?> Obviously, what I want as a result when I'm displaying the page is: "5 multiplied by 10 + 1000 = 1050" What I get: "1005". That's right, nothing else. On top of getting an erroneous answer, the sentence that's supposed to display right before the equation doesn't display at all. It's even worse if I switch it around like that: Code: [Select] print $number1." multiplied by ".$number2." + 1000 = ".1000+$number1*$number2; I get an error message and nothing displays. The obvious solution works: using a parenthesis at the beginning and at the end of the equation, which I should do regardless, but still, it's bugging me and since I just started learning PHP today, I want to understand how the code is compiled / interpreted so I don't make stupid mistakes like this one. Thanks in advance for the replies. I have 3 columns in my DB: email (primary), unique_code, timestamp Users enter their email address and it is added to the DB, including an alphanumeric 5 digit unique code in the 'unique_code' column and a timestamp in the 'timestamp' column. 1. The email address is being added, but not the unique code? What is the issue here and what can I should I specifically do to fix it? 2. The next thing is that I need to display that code to the user in where it says <?php echo $unique_code;?>. How can I do that? DB is as follows: Field Type Collation Attributes Null Default Extra Action email varchar(64) utf8_unicode_ci No None unique_code varchar(64) utf8_unicode_ci No None timestamp timestamp on update CURRENT_TIMESTAMP No CURRENT_TIMESTAMP INDEXES PRIMARY BTREE Yes No email 7 A Full code Code: [Select] <?php require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('This email already exists in the database.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; $mysqli->query("INSERT INTO coming_soon_emails VALUES('email', SUBSTRING(MD5(UUID()),FLOOR(RAND()*25),5), UNIX_TIMESTAMP())"); echo "Something went wrong:" . $mysqli->error; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>example</title> <link rel="stylesheet" type="text/css" href="css/styles.css" /> </head> <body> <div id="container"> <form id="form" method="post" action=""> <input type="text" id="email" name="email" value="<?php echo $msg?>" /> <input type="submit" value="Submit" id="submitButton" /> </form> <div id="thankyou"> Thank you! <?php echo $unique_code;?></p> </div> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script src="js/script.js"></script> </body> </html> Thank you! Hi Guys, I want to go about creating a CMS, that'd cost per license key, however I'm not sure how to go about the checking of the Serial Key. For example, I could have a simple PHP script, that checked for the Serial Key, however they could then just go into a file, and delete that section of the file, which checks for the Serial Key. The reason I want to add a serial key checker, is incase people decide to leak my software, and could use it without paying. Whilst I'm aware they're will be cracks for it, I want to make sure that it'd be a good start. Could anybody please put forward any methods or suggestions? Thanks Guys! This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=332690.0 Hi all,
I want to send a string of data to serial port. Below is the code. Sdata contains the string. for example "<LT-ON-50>".
<?php exec("mode com3: BAUD=600 PARITY=n DATA=8 STOP=1 to=off dtr=off rts=off"); if (isset($_GET['action'])) { $SData = $_GET['action']; $fp = fopen("com3","w"); fwrite($fp,$SData); fclose($fp); } ?>unfortunately, it will send only one character i.e '<'. the remaining characters will be lost. What could be wrong in the code. Any help can be greatly appreciated. Thanks, 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 im having some trouble when i try to add values to an array from a function. The added value will not stay saved. fun1 will display both firstname and surname but when i call fun2 after calling fun1 i just get the firstname. I would like to have it so the array is updated and stays updated untill it is cleared or over written. Any help with this would be greatly appreciated. i am using codeigniter if that makes any difference. Thanks <?php class Test extends Controller { var $data1 = array( 'firstname' => 'craig' ); function fun1() { global $data1; $this->data1['surname'] = 'brute'; echo "<pre>"; print_r($this->data1); } function fun2() { global $data1; echo "<pre>"; print_r($this->data1); } } Hi all. I try to adding checkbox when I call my function, my Class code is Code: [Select] class SQLconn{ function fetchData($table_name, $argument, $linebreak, $end_linebreak){ $result = mysql_query("select * from $table_name where status='$argument'"); while($row=mysql_fetch_row($result)){ echo $linebreak.$row[1]."<input type='checkbox' name='option' id='checkbox' value=$row[0] />".$end_linebreak; //$row[0] is 'job_id' from database } } } and my view code is like this Code: [Select] <?php $connect = new SQLconn(config()); $connect->connectDB(); $connect->fetchData("todo", "Undone", "<li>", "</li>"); //this is where the problem is $connect->closeConn(); ?> With that code I succesfully achieve my goal to add checkbox with right 'job_id' value but this is a workaround and not good because if I code it this way my function will be broken if use it somewhere else. My question is, how can I fix my code so I can add checkbox to view page but I can keep my function clean? Really need opinion about this?? I cant figure out how to add $recieved into this needs to take place of time hope someone knows how to do this what im doing is adding in the UNIX time i want to offset Code: [Select] <?php $offset = date('m/d/Y/H:i:s', time()+$send1['time_offset']); ?> This would seem like a simple question, but I can't seem to find the answer anywhere. Perhaps I'm asking it wrong. What I'd like to do is add a hash of optional arguments for a function. For example, I might have a function that has two required arguments, and three optional arguments. The only way I know to design this function is to put the arguments in a specific order, and fill them out to the degree needed. So if the 5th argument needs to be called, but the 3rd and 4th don't, you'd still have to give them values. function example($arg1, $arg2, $arg3, $arg4, $arg5) Must be used by: example('red', 'horse', '', '', 'texas'); Is there anyway of designing a function to only use the specified arguments? example('red', 'horse', ['arg5: texas']); Hi,
I am using fancybox on my site and the function I am using to display the title and data-caption is this.
$(document).ready(function() { $('.fancybox').fancybox({ beforeShow : function(){ this.title = this.title +"<br>" + $(this.element).data("caption"); } }); }); // readyI would like to change this so that I can add a hypertext link. Here is what a sample of the HTML looks like: <img src="img/portfolio/GSI_web.png" height="194" width="400" alt="Globalsoftwareinc.com" /> <h4>www.globalsoftwareinc.com</h4> <div class="portfolio-desc align-center"> <div class="folio-info"> <h5><a title="globalsoftwareinc.com" href="#" title="www.globalsoftwareinc.com">Globalsoftwareinc.com</a></h5> <a title="Global Software Inc. website" href="img/portfolio/GSI_web_large.png" class="fancybox" data-caption="I was the interactive web designer at Global Software, Inc. and assisted in the re-design and development of Global Software, Inc. in Drupal<br>www.globalsoftwareinc.com"><i class="fa fa-plus fa-2x"></i></a> </div> </div> </div> </article>so for example I would want to make www.globalsoftwareinc a hyperlink and that isn't do-able currently. It breaks the code. thanks in advance! The web application should allow the user to view the items in a catalogue, add items to a shopping cart, remove items from the shopping cart, and to view the contents of the shopping cart. Hey guys. Right ill try explain as best i can. Basicly we were told to write a php script that can view a shopping cart. The items in the catalogue should be stored as an array of objects. (The next assignment will require you to store this list of objects in a database). There should also be pages to allow the user to add, edit and delete items in the catalogue. Thats taken from a brief.Ive spent the most of the week getting it to view a catalog and now it can add items.view the cart its added them to and remove them from the cart and return. What im having trouble with is making the add function for the the other users or admin* to add/edit/delete.i reckoned adding and deleting wouldnt be so bad considering ive alrready done so.But im kinda stumped on how to do it.i think what the brief wanted was a seprate product add that would actully let u add another product to the cart list on the same page and then u can add that to the shopping basket etc. Yea real stumped.if only it was through sql it would be so much handier. ill post the code below.if anyone can help at all in the slightest id be so grateful.Thank you. 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;} ?>"> Hi all i have stumbled across an issue and really need some help i have got a function below which i am using in a wordpress plugin. here is the code. // Base function function isd_s3player() { // Plugin Url $s3url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); echo '<object type="application/x-shockwave-flash" data="'.$s3url.'dewplayer-playlist.swf" width="235" height="200" id="dewplayer" name="dewplayer"> <param name="wmode" value="transparent" /> <param name="wmode" value="transparent" /> <param name="movie" value="'.$s3url.'dewplayer-playlist.swf" /> <param name="flashvars" value="showtime=true&autoreplay=true&xml='.$s3url.'playlist.php&autostart=1" /> </object>'; } ok the problem i am having is i cant passed the database variable to the playlist.php which the dewplayer needs to call within the function. is their a way to somehow use or set the playlist.php in this function without having to call it seperatly??? Here is my playlist.php <?php $bucket = get_option("isd-bucket"); $folder = get_option("isd-folder"); //include the S3 class if (!class_exists('S3'))require_once('s3/S3.php'); //AWS access info if (!defined('awsAccessKey')) define('awsAccessKey', 'amazon key'); if (!defined('awsSecretKey')) define('awsSecretKey', 'amazon secret key'); //instantiate the class $s3 = new S3(awsAccessKey, awsSecretKey); // Get the contents of our bucket $bucket_contents = $s3->getBucket($bucket,$folder); header("Content-type: text/xml"); $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $xml_output .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">\n'; $xml_output .= "<trackList>\n"; foreach ($bucket_contents as $file){ $fname = $file['name']; $furl = "http://$amazon_bucket.s3.amazonaws.com/".urlencode($fname); if(preg_match("/\.mp3$/i", $furl)) { if (isset($outputted[$furl])) { continue; } $xml_output .= "\t<track>\n"; $xml_output .= "\t\t<location>" . $furl . "</location>\n"; $xml_output .= "\t\t<creator>" . $fname . "</creator>\n"; $xml_output .= "\t\t<album>" . $fname . "</album>\n"; $xml_output .= "\t\t<title>" . basename($fname) . "</title>\n"; $xml_output .= "\t\t<annotation>I love this song</annotation>\n"; $xml_output .= "\t\t<duration>32000</duration>\n"; $xml_output .= "\t\t<image>covers/smetana.jpg</image>\n"; $xml_output .= "\t\t<info></info>\n"; $xml_output .= "\t\t<link>" . $furl . "</link>\n"; $xml_output .= "\t</track>\n"; $outputted[$furl] = true; } } $xml_output .= "</trackList>"; echo $xml_output; ?> ok so as you can see right at the top i am trying to grab two option from the database but it doesnt allow you to do it this way within wordpress. So i guess what i am asking is their a way to completely skip the playlist.php file and do everything within the function??? Any help?? |