PHP - Simple Arithmetic Gone Bad?
So I added a number unformatted and got the expected value, but after I formatted it I received an incorrect value?
The Number unformatted looks like this: 441492111.66667. So did $number + 10 and got = 441492121.66667. That's all fine and correct. But after I formatted like so: $final = number_format($number) + 10; I got 451. Not too sure why that would happen, can someone explain to me please? Similar TutorialsI am trying to add foo onto bar inside a loop so I can then echo bar outside the loop and see the sum. The PHP manual doesn't have anything on addition in the way I need it (adding onto), so I was wondering if anyone can help me? LOL embrace yourself! $query = "select * from products where id='{$content['id']}'"; $result = mysql_query($query); $row = mysql_fetch_array($result); mysql_query ($query); mysql_close($link); echo " <B>Product ID:</B> {$content['id']} <BR> <B>Price:</B> $row[price] AUD <BR> <BR> "; +$row[price] -> $total; } echo $total; Hello again. I run a sports league website and registrations received after a certain date need to have their league fees calculated to add 10%. someone wrote this for me a couple of years ago, but I have since then lost the full code. Need to know how to add a date to the follow statement that would automatically add the 10%. Can someone look at this for me and fill me in on what's missing? Thanks! Code: [Select] /* * Calculate fees */ $intSize = intval($arrLeagueSearch['size']); switch($intSize) { case 2: $dblBase = 150.00; $intBSize = 3; break; case 4: $dblBase = 330.00; $intBSize = 6; break; case 6: $dblBase = 550.00; $intBSize = 10; break; default: die("Invalid league size"); }; $dblEarlyTeam = $dblBase; $dblEach = $dblEarlyTeam / $intPlayers; /* $dblLateTeam = $dblEarlyTeam * 1.10; $dblLateEach = $dblLateTeam / $intPlayers; */ Hello I'm trying to use PHP "for loops" to build a table of 10 rows with 5 columns and I'm sure there's a better way to do this, but the result is the page won't fully load and continually spins its wheel. Here's the code: Code: [Select] $states = array(1 => 'AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','OZ','PA','PR','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI' ); <table id="stateCheck"> <?php for ($i = 1; $i <= 10; $i++) { echo '<tr>'; for ($j = 5*$i; $j <= $j+4; $j++) { echo '<td> <input type="checkbox" name="state" value="'.$states[$j].'" /> '.$states[$j].' </td>'; } echo '</tr>'; } ?> <tr> <td> <input type="checkbox" name="state" value="WV" /> WV </td> <td> <input type="checkbox" name="state" value="WY" /> WY </td> </tr> </table> Is it breaking because I'm using arithmetic operators to define the nested for loop? Many thanks Hi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 I think I'm using simple xml wrong I'm trying to read strings of xml and get it to list the "attributes" in the strings but it's not working. How would I read and list the attributes of this string <Address><to>Joshua</to><from>Rockhampton</from><country>Australia</county></Address> It needs to out put a string that can be printed and look like (or something like) to:Joshua from:Rockhampton country:Australia All my code produces errors and the page just goes blank and I don't know what is wrong.l Hello, i am newbie at PHP codes and i need help little! How to limit of chars of song? I uploaud an images and post php code! $fp_data = ereg_replace("^.*<body>","",$fp_data); $fp_data = ereg_replace("</body>.*","",$fp_data); list($currentlisteners,$status,$peak,$max,$reported,$bit,$song) = explode(",", $fp_data, 7); if($showsong == '1') { $stationinfo = ' '.$currentsong.' '.$song.' '; } if($showlisteners == '1') { $stationinfo = $stationinfo.' '.$currentlisteners.' of '.$peak.' '.$listenerlabel.' '; } } } // Include the layout for display require(JModuleHelper::getLayoutPath('mod_ngs_shoutcast')); ?> Thank you! Code: [Select] <?php //ob_start(); include "../connect.php"; Header('Cache-Control: no-cache'); Header('Pragma: no-cache'); $UserId=$_POST['UserId']; $UserId = stripslashes($UserId); $UserId = mysql_real_escape_string($UserId); $UserName=$_POST['UserName']; $UserName = stripslashes($UserName); $UserName = mysql_real_escape_string($UserName); $UserFirstName=$_POST['UserFirstName']; $UserFirstName = stripslashes($UserFirstName); $UserFirstName = mysql_real_escape_string($UserFirstName); $UserLastName=$_POST['UserLastName']; $UserLastName = stripslashes($UserLastName); $UserLastName = mysql_real_escape_string($UserLastName); $UserGender=$_POST['UserGender']; $UserGender = stripslashes($UserGender); $UserGender = mysql_real_escape_string($UserGender); $UserLink=$_POST['UserLink']; $UserLink = stripslashes($UserLink); $UserLink = mysql_real_escape_string($UserLink); $UserPicture=$_POST['UserPicture']; $UserPicture = stripslashes($UserPicture); $UserPicture = mysql_real_escape_string($UserPicture); $sql="SELECT * FROM Fb_Profile WHERE UserId='$UserId' and UserName ='$UserName' and UserFirstName ='$UserFirstName' and UserLastName ='$UserLastName' and UserGender ='$UserGender' and UserLink ='$UserLink' and UserPicture ='$UserPicture'"; $result=mysql_query($sql); $count=mysql_num_rows($result); //Lets add a first time active check 0 or 1 if 1 skip and check for update<br /> if($UserId == 'undefined') { return true; } if($count==1) { echo "&msgText=Facebook MySql Copy Successfully!\n"; return false; } else { echo "&msgText=Invalid Login!\n"; //THIS HERE IS WHAT I AM HAVING A PROBLEM WITH, IF STATEMENT STATING THAT IF $UserId IS EMPTY AND THE OTHER VARIABLES RETURN NOTHING BUT IF IS HAS A VALUE IT INSERTS //IF(!empty $UserId) $FB_Profile_Copy = mysql_query("INSERT INTO Fb_Profile(UserId,UserName,FirstName,LastName,Gender,Link,Picture) VALUES('$UserId','$UserName','$UserFirstName','$UserLastName','$UserGender','$UserLink','$UserPicture')"); $FB_BackGround_Copy = mysql_query("INSERT INTO Fb_BackGround(UserId) VALUES('$UserId')"); return false; } ?> Please .i want php code to get metacfe thumbnail from url this is the url http://www.metacafe.com/watch/5823413/the_sinister_eyes_of_dr_orloff_movie_trailer/ php code to grab 5823413 for thumbnail links this http://www.metacafe.com/thumb/5823413.jpg I am trying to write a PHP page that takes an XML file stored on an external server, parses it, and rewrites the data to a new XML file formatted to my liking. The feed is for events and has about 250 events to parse. The problem is that if one event has an empty node, the script will use the same event data for the node used previously. Upon research, I see that empty nodes are parsed as an empty SimpleXMLElement Object. See my code for example: XML Original: Code: [Select] <event_info> <event id="1222209"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>102.9 FM</radio> <sched_opp><![CDATA[Toledo]]></sched_opp> </event> <event id="1222210"> <outcome_score><![CDATA[]]></outcome_score> <quotes></quotes> <radio>107.1 FM</radio> <sched_opp><![CDATA[Ohio]]></sched_opp> </event> </event_info> Output XML (note <outcome_score> on second event): Code: [Select] <event_info> <event id="1222209"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>102.9 FM</radio> <sched_opp><![CDATA[Toledo]]></sched_opp> </event> <event id="1222210"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>107.1 FM</radio> <sched_opp><![CDATA[Ohio]]></sched_opp> </event> </event_info> PHP code: $xml = simplexml_load_file($source); echo "<event_info>"; foreach($xml->event as $event) { echo "<event>"; if($event->outcome_score != '') { echo "<outcome_score><!CDATA[{$event->outcome_score]]></outcome_score>"; } if($event->quotes != '') { echo "<quotes><!CDATA[{$event->quotes]]></quotes>"; } } if($event->radio != '') { echo "<radio><!CDATA[{$event->radio]]></radio>"; } if($event->sched_opp != '') { echo "<sched_opp><!CDATA[{$event->sched_opp]]></sched_opp>"; } echo "</event>"; } echo "</event_info>"; Basically, whenever an event has no outcome score, the most recent outcome score is repeated for all events after. Any help would be greatly appreciated! Thanks! Hi Guys
I'm updating my website and I'm stumped on the last section. I have a dynamic Table with various fields showing from Mysql, I use MS Access as a front end, and I have a field named Download, I enter the file location of a customers invoice and it stores the link in mysql, works perfectly. BUT, the dynamic table looks like this: Download - \users\MM4512\Invoices\Invoice23.PDF which is hyperlinked so they can download it etc.. Is there a way I can change this section from the above to a simple (Download Invoice) instead of all that text? The code used is : <td><a href="<?php echo $row_Invoices['download']; ?>" target="_blank"><?php echo $row_Invoices['download']; ?></a></td> Have tried to do this myself all day now and i`m getting a little frustrated now. I have a contact form with a select box which can have multiple options selected, i`m using formmail.php to process the info. Problem is I have forgot how to list the values within the array and format them within the email body. $licences is the multiple select box any help would be gratefully received!! Code: [Select] <?php $name=addslashes($_POST['name']); $email=addslashes($_POST['email']); $town=addslashes($_POST['town']); $phone=addslashes($_POST['phone']); $licences=addslashes($_POST['licences']); $message=addslashes($_POST['message']); // you can specify which email you want your contact form to be emailed to here $toemail = "admin@mysite.com"; $subject = "Question : mysite.com"; $headers = "MIME-Version: 1.0\n" ."From: \"".$name."\" <".$email.">\n" ."Content-type: text/html; charset=iso-8859-1\n"; $body = "Name: ".$name."<br>\n" ."Email: ".$email."<br>\n" ."Town/City: ".$town."<br>\n" ."Phone: ".$phone."<br>\n" ."Interested in Licence/s: ".$licences."<br>\n" ."Message:<br>\n" .$message; if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)) { echo "That is not a valid email address. Please return to the" ." previous page and try again."; exit; } mail($toemail, $subject, $body, $headers); echo "Thanks for submitting your message."; ?> Code: [Select] <?php if ( $_SERVER['HTTP_REFERER'] == "http://domain.net/sub/index.php" ) { echo "true"; } else { echo "false"; } ?> is the code i'm using. /sub/index.php redirects to http://domain.net/index.php it's not seeming to work. please help sort out this bug. Im trying to parse this xml but i can get it to output a simple string, can someone see what im doing wrong?? Code: [Select] $str = "<channel><item> <id>cb-uA4QHmpDxYdpgW1jPwiYsUwjBViwlinS</id> <title>Rules of Engagement - Play Ball Extended Preview - Season 5 - Episode 12</title> </item> </channel>"; $n_data = new SimpleXmlElement($str, LIBXML_NOCDATA); foreach ($n_data->channel->item as $d) { $vid = $d->id; $title = $d->title; print_r($d->title); //testing die(); //testing $arr2[] = array('vid' => $vid, 'title' => $title, 'site_id' => 10 ,'time' => 456); } The print_r() returns Code: [Select] SimpleXMLElement Object ( [0] => Rules of Engagement - Play Ball Extended Preview - Season 5 - Episode 12 ) If i simply echo $d->title it returns a string, but i need to reapply $d->title to another array as shown above Hi all, wonder if someone would be able to help. I am a pure beginner but am developing an app which allows students in a school to enter their username and see their timetable. The php works great and fits fine in my app. I am trying to get it to remember the username which is entered so they do not need to enter it again. I know I need cookies and have played with no joy. I wondered if anyone would be able to help get the page to remember their username when entered (no password needed). Many thanks. Code: [Select] <style type="text/css"> <!-- body,td,th { color: #FFFFFF; } body { background-color: #000000; } .style1 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style><form id="form1" name="form1" method="post" action=""> <label> <div align="center" class="style1"><strong>My Timetable Search</strong><br /> <br /> Enter Network User ID:<br /> <input type="text" name="txtUserID" id="txtUserID" /> </div> <p align="center"> <label> <input type="submit" name="cmdGo" id="cmdGo" value="Show Timetable" /> </label> <br /> </p> <hr /> </form> <div align="center"> <?php $userName = $_POST["txtUserID"]; $hostname = "localhost"; $dbuser = "xxxxx"; $dbpassword = "xxxxxx!"; $dbname = "xxxxxxx"; $LessonCount = 0; $db_link=mysql_connect($hostname, $dbuser, $dbpassword) or die("Unable to connect to the server!"); mysql_select_db($dbname) or die("Unable to connect to the database"); $fields_array=array(); $num_fields=0; $num_row=0; $sql= "SELECT core.UserID, wstt.Period, wstt.Lesson, wstt.Staff, wstt.Room FROM wstt INNER JOIN core ON wstt.Adno = core.Adno WHERE core.UserID='$userName'"; // find position of "FROM" in query $fpos=strpos($sql, 'from'); // get string starting from the first word after "FROM" $strfrom=substr($sql, $fpos+5, 50); // Find position of the first space after the first word in the string $Opos=strpos($strfrom,' '); //Get table name. If query pull data from more then one table only first table name will be read. $table=substr($strfrom, 0,$Opos); // Get result from query $result=mysql_query($sql); $num_row=mysql_numrows($result); print('<html>'); print('<head><title>'); print('Timetable for'.$userName.'</title>'); print('<link rel="stylesheet" href="style.css">'); print("</head>"); print('<body><br>'); print('<h3>Timetable for: '.$userName.'</h3>'); print('<div align="center"'); if($num_row >0) { //Get number of fields in query $num_fields=mysql_num_fields($result); # get column metadata $i = 1; //Set table width 10% for each column $width=10 * $num_fields; // print('<br><table width='.$width.'% align="center" border=1> padding=0<tr>'); print('<br><table width='.$width.'% border="1" cellpadding="0" cellspacing="0" bordercolor="#000066"<tr>'); print('<tr><th colspan='.$num_fields.'>Timetable List</th></tr>'); while ($i < $num_fields) { //Get fields (columns) names $meta = mysql_fetch_field($result); $fields_array[]=$meta->name; //Display column headers in upper case print('<th><b>'.strtoupper($fields_array[$i]).'</b></th>'); $i=$i+1; } print('</tr>'); //Get values for each row and column while($row=mysql_fetch_row($result)) { print('<tr>'); //SET TO 1 TO HIDE USERNAME for($i=1; $i<$num_fields; $i++) { //Display values for each row and column print('<td>'.$row[$i].'</td>'); } //START if ($LessonCount ==4) { print('<tr>'); print('<td colspan="4"><div align="center">-----------------------------------------------------</td></tr>'); $LessonCount=0; }else { ($LessonCount = $LessonCount+1); } //STOP print('</tr>'); } } print('</div>'); ?> </div> I'm not sure what I'm doing wrong here. I'm trying to get this to show the schedule for each person in the database. It does show the schedule, but it only shows one day in each box, and it's the last day. So, if the last day is October 28th, it populates every box with the schedule for the 28th. Code: [Select] <?php $query = "SELECT * FROM employees WHERE day > '$current_date' AND day < '$get_date'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $id = $row['id']; $position = $row['position']; $pay_rate = $row['pay_rate']; $total_hours = $row['total_hours']; $total_pay = $row['total_pay']; $start_time = date("g:i a", strtotime($row['start_time'])); $end_time = date("g:i a", strtotime($row['end_time'])); $work_day = date("l", strtotime($row['day'])); $day = date("F j", strtotime($row['day'])); if($end_time == "24:00:00"){ $end_time ="Close";}; $schedule = $start_time ."<br />". $end_time; $first = $row['first_n']; $last = $row['last_n']; if ($work_day == "Monday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Tuesday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Wednesday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Thursday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Friday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Saturday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Sunday"){ $name[$last.", ".$first] = $schedule; } } foreach ($name as $n => $s) { ?> <tr> <td align="left" valign="top"><?php echo $n; ?></td> <td align="left" valign="top"><?php echo $position; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="right" valign="top"> </td> </tr> <? } ?> Can somebody see what I'm doing wrong? Thanks in advance Hi all, i think i am making a really stupid mistake but i have a problem with my php function that i do not get. My function is: Code: [Select] function user_level($userlevel){ if($userlevel = 0){ $level = test; } elseif($userlevel >= 1){ $level = test1; } return $level; } In the cases i tried it on the userlevel is way higher than 1, but nothing returns when i echo the function. Whenever i change the >= to = and the exact number, it works fine. So the following does work: Code: [Select] elseif($userlevel = 767){ $level = test1; } Am i doing something really stupid here? :p ok say I have a file that has something like 123456 abcde 654321 edcba in a file.. how would I go about having the script pull "123456" and make it a variable in the script.. and "abcde" a variable? and then "654321" a variable but is set in an array so that 123456 and 654321 are both the same variable but like $variable[0] and abcde and edcba would be $variable[1] what do I have to do? |