jonsjava
-
Posts
1,579 -
Joined
-
Last visited
Posts posted by jonsjava
-
-
try this:
foreach (parseTXT("some_file.txt") as $key=>$val){ echo "<h2>Statistics for $key: </h2><br />"; echo "<table border=\"0\"><tr><th>MS to Complete</th></tr>"; foreach ($val as $key2=>$val2){ if (is_int($key2)){ echo "<tr><td>$val2</td></tr>"; } else{ echo "</table><br /> <h2><strong>Total Run on $key: $val2</strong</h2><br /><br /><br />"; } } }
-
It's an array. run it through a for loop. If you need help, let me know.
-
A brief explination of my code:
It looks for all lines that have the word "runtime" in them. This poses an issue, but not insurmountable.
Next, it splits up that line by spaces (only thing that keeps the data separate) into an array.
Next, knowing the spacing should always be the same, I can tell which array element will contain the data needed. From there, I throw that into an array with the task number as the key, and the time as children arrays, then does the math to give you total time.
-
array key was off. try this:
function parseTXT($data){ $fh = fopen($file, "r"); $data = fread($fh,filesize($fh)); fclose($fh); foreach ($d_array as $val){ if (strstr($val, "runtime")){ $tmp_array = explode(" ", $val); $token = str_replace(":", "", $tmp_array[12]); $token_array[$token][] = $tmp_array[13]; } } foreach ($token_array as $key=>$val2){ $token_array[$key]['total'] = 0; foreach ($val2 as $val3){ $token_array[$key]['total'] += $val3; } } return $token_array; } print_r(parseTXT("some_file.txt"));
EDIT to account for double spacing. Darn double spaces where one ain't needed! lol
-
try
if (isset($_SESSION['memberof'])){
Your code is how many people used to code. Only problem is that if your error reporting is set to notice, you get errors, when the variable isn't set. Best to check if it is set, and go from there.
How your code works: if it is set, it's counted as true. If not, it comes back as false with notice.
-
<?php //require_once 'includes/config.php'; $dbusername = $_POST['email']; $dbfirstname = $_POST['first_name']; $dblastname = $_POST['last_name']; //$dbmobile_number = $_POST['mobile']; if (empty($_POST['mobile'])) { $dbmobile_number = NULL; } else { $dbmobile_number = $_POST['mobile']; } if (empty($_POST['landline'])){ $dblandline_number = NULL; } else{ $dblandline_number = $_POST['landline']; } if (empty($_POST['dob'])){ $dbdob = NULL; } else{ $dbdob = $_POST['dob']; } if (empty($_POST['shipping_pincode'])){ $dbpincode = NULL; } else{ $dbpincode = $_POST['shipping_pincode']; } if(isset($_POST['is_email'])) { $dbSubscribe_Email_Alert = '1'; } else { $dbSubscribe_Email_Alert = '0'; } if(isset($_POST['is_sms'])) { $dbSubscribe_SMS = 0; } else { $dbSubscribe_SMS = 0; } $dbAddress_firstname = $_POST['shipping_first_name']; $dbAddress_lastname = $_POST['shipping_last_name']; $dbAddress = $_POST['shipping_address']; $dbcity = $_POST['shipping_city']; $dbstate = $_POST['shipping_state']; $dbcountry = $_POST['shipping_country']; echo "Welcome".$dbusername; //if($_POST['btnSave']) //if ($_POST['btnSave']) //{ //echo "Inside query loop"; $connect = mysql_connect("localhost","root","") or die("Couldn't connect!"); mysql_select_db("salebees") or die ("Couldn't find DB"); //$query = mysql_query("SELECT * FROM users WHERE username='$username'"); $query = mysql_query("update users set firstname = '$dbfirstname', lastname = '$dblastname', mobile_number = '$dbmobile_number', landline_number = '$dblandline_number', dob = '$dbdob', Subscribe_Email_Alert = '$dbSubscribe_Email_Alert', Subscribe_SMS = '$dbSubscribe_SMS', Address_firstname = '$dbAddress_firstname', Address_lastname = '$dbAddress_lastname', Address = '$dbAddress', city = '$dbcity', pincode = '$dbpincode', state = '$dbstate', country = '$dbcountry' where username = '$dbusername' "); header("location:my_account.php"); //} //else //{ //die(); //} ?>
If I understand what you want, if the data is empty, store as NULL. This code should do the trick. All I did was have it check to see if the POST data was empty. If the variable exists in the form, it will come across, so we cannot check to see if isset(), but empty(), because it will always be set, but it just may be empty. That is the check you need to be doing.
-
Ok, we have guessed about as far as we can without actually seeing code. If you are willing, could you post what you are able to of the code in question?
-
Why not create a link at the end, which will point them to an edit page. Much cleaner and easier.
<?php //to display image from source $dir = "360_covers"; echo '<table>'; echo '<tr><th>Title</th><th>Cover</th><th>comment</th><th>Actions</th></tr>'; $result = mysql_query("SELECT * FROM xbox_games order by gametitle"); while ($row = mysql_fetch_assoc($result)){ echo "<tr><td>{$row['gametitle']}</td><td><img src=\"$dir/{$row['cover']}\" width='38' height='38'></td><td>{$row['cover']}</td><td><a href=\"edit.php?id={$row['id']}\">Edit</a> | <a href=\"delete.php?id={$row['id']}\">Delete</a></tr>"; } //close out table echo '</table>'; ?>
-
Fatal error. Means that either the parsing engine is acting up (PHP is crapping itself), or Apache doesn't like something you are trying to do. Do you have a .htaccess file associated with this?
-
Cleaned up the code for anybody who wants to help
<?php //to display image from source $dir = "360_covers"; echo '<table>'; echo '<tr><th>Title</th><th>Cover</th><th>comment</th></tr>'; $result = mysql_query("SELECT * FROM xbox_games order by gametitle"); while ($row = mysql_fetch_assoc($result)){ echo "<tr><td>{$row['gametitle']}</td><td><img src=\"$dir/{$row['cover']}\" width='38' height='38'></td><td>{$row['cover']}</td></tr>"; } //close out table echo '</table>'; ?>
-
Ok, I got this for you. Be warned: not tested, and it only works if your data is formatted exactly as outlined in the sample.
function parseTXT($file){ $fh = fopen($file, "r"); $data = fread($fh,filesize($fh)); fclose($fh); $d_array = explode("\n", $data); foreach ($d_array as $val){ if (strstr($val, "runtime")){ $tmp_array = explode(" ", $val); $token = str_replace(":", "", $tmp_array[5]); $token_array[$token][] = $tmp_array[6]; } } foreach ($token_array as $key=>$val2){ $token_array[$key]['total'] = 0; foreach ($val2 as $val3){ $token_array[$key]['total'] += $val3; } } return $token_array; }
Ok, I tested my code against the sample data you gave, and here's what I got:
Array ( [9188147351] => Array ( [0] => 9953 [1] => 10903 [2] => 65456 [3] => 83128 [4] => 12187 [5] => 28148 [total] => 209775 ) )
look right to you?
-
try this:
<?php ini_set("display_errors","1"); //code here
A warning: if the script is having a fatal error, this won't work.
-
think of it this way: A pregnant woman has a baby, and she is in a house.
$house = Array( [Mother] => Array ( [0] => Baby ) )
93 (mother) is a key in an array (house), and the data for 93 IS an array, which contains key 0 (baby), which has a value of 96.
This is a multi-dimensional array. Hopefully that link can help.
-
Before asking: yes, I could have used str_split, and I could have used preg_split, or done it better. It is 1:00AM here, and I'm bored. I did it the "fun" way.
-
Not sure if this will do, but here you go
/*Ok, this doesn't work if you have multiple <code> tags...*/ function hide_code_from_nl2br($input){ $content = $input; //so I can remember what the heck I am doing $code_begins = strstr($content,"<code>"); // Find where the code bracket starts. $code_only_a = explode("</code>", $code_begins); //builds an array to get the end of the <code>, so we can keep it to itself $code_only = $code_only_a[0]; // gets just the code $content_minus_code = str_replace($code_only."</code>", "{CODE_GOES_HERE}", $content); //strips out the code from the content return str_replace("{CODE_GOES_HERE}", $code_only."</code>", nl2br($content_minus_code)); //does an nl2br on what is left, and then adds the code back where it should be }
I know there must be an easier way, but it was fun to write this way.
-
Easiest way I can come up with is create an array of data to store the <code>, then strip out the data from <code> to </code>, placing a placeholder there, and running what you have left through the nl2br, then do a str_replace("{HOLDER_NUMBER",$content[$NUMBER],$content)
just an idea, and the only one I have.
working on a running code version right now.
-
Try restarting Apache. If you edited the file after starting Apache, then the change won't be visible. Let me know if this resolves the issue.
-
That was an example to show you how to manipulate the data. Have fun with it! You are working with arrays now.
-
ok, try this:
$shipID = $random_ship['shipID']; $url = "http://some_site/ship_info.php?id=$shipID"; echo $url;
-
That wouldn't work. That would only pull up people born tomorrow/today. He wants it a little more flexible. Babies excluded *lol*
-
SELECT * FROM detail WHERE dob LIKE '$mydate%';
change mydate to
$myDate = date('d/m/');
-
try
print_r($random_ship);
-
the ugly method (coding in the reply box, not my IDE, so not tested):
$count = 0; while ($row = mysql_fetch_assoc($res)){ $array[$count]['shipID'] = $row['shipID']; $array[$count]['ShipName'] = $row['ShipName']; $array[$count]['Class'] = $row['Class']; $count++; } $total = count($array); $random = rand(0,$total - 1); $random_ship = $array[$random]; ?>
-
I won't actually write code for it, but I will point you in the right direction.
You will need to use AJAX (Dynamic page changes without reloading the page=AJAX). AJAX is Javascript and Server-Side scripting. The javascript makes XMLHTTP requests, and waits for a response. Once it gets a response, you can echo the data out. Simple as that.
The coding is the hard part. Get some code, and post it here if you have issues.
500 Error but nothing in error_log
in PHP Coding Help
Posted
you should have a ~/logs or ~/var/log directory. find that, and in there, you should have httpd or apache folder
in that folder, you should have error.log
also, you should have a ~/php or ~/var/log/php directory