PHP - Mysql + Arrays
I have a problem that i'm not quite sure how to do.
I have to create a system that allows me to enter several postcodes associated with a particular event. (These are 4 digit postcodes). Somebody then has to enter a Postcode and it should pull up all events associated with that postcode. The problem being that each event (For i can't see another way of storing it easily) will have the postcodes stored in a mysql database in an array. How do i get SELECT to search through the postcode arrays and then print out any rows that have that particular postcode in it. Similar Tutorialsis it possible to save it this way? I found no errors but there are also no effect in my db. help me guys! thank you. "while ($row = mysql_fetch_array($query)) { echo "<tr>"; echo '<td><input type="hidden" name="se_Id['.$i.']">'.$row['se_Id'].'</td>'; echo '<td><input type="hidden" name="user_Id['.$i.']">'.$row['user_Id'].'</td>'; echo '<td><input type="hidden" name="course_Id['.$i.']">'.$row['course_Id'].'</td>'; echo '<td><input type="hidden" name="ap['.$i.']">'.$row['ap_Id'].'</td>'; echo "<td>". $row['user_Fname']."</td>"; echo "<td>". $row['user_Lname']."</td>"; echo "<td></td>"; echo "<td></td>"; echo "<td>".$row['se_Yearlevel']."</td>"; echo "<td></td>"; echo "<td></td>"; echo "<td></td>"; echo "<td> <input type='checkbox' id='checkbox".$i."' value ='checked' onclick='checkbox_disabled(\"checkbox".$i."\",\"textbox".$i."\",\"checkbox".$i."2\");'></td>"; echo "<td><input type='checkbox' id='checkbox".$i."2'>"; echo " <input type='text' id='textbox".$i."'></td>"; echo "</tr>"; $i++; } } else { echo "No students enrolled"; } echo "</form>"; echo "</table>"; echo "<br></br>"; echo " <input type='submit' name = 'submit' value='Submit'>"; ?> <?php if (isset($_POST['submit'])) { foreach ($_POST['user_Id'] as $key => $user_Id) { $se_Id = $_POST['se_Id'][$key]; $status = $_POST['status'][$key]; $course = $_POST['course'][$key]; $officeid [$key]; $ap = $_POST['ap'][$key]; mysql_query("INSERT tbl_data (user_Id,se_Id,office_Id,course_id,ap_Id,Status) VALUES ('$user_Id','$se_Id','$officeid','$course','$ap','$status')") or die(mysql_error()); // echo "<meta http-equiv=\"refresh\"content=\"0;URL=offcourse_view.php\">"; echo "congrats"; } } ?>" Hey guys, i am having a problem and for the life of my i can't think of how to get around this problem. All the variables below are arrays and the code below is what i have done so far. The problem is when updating the records it only puts in "Array" in all of the fields being updated. How should i go about re-doing it so that when the first array in $idnumber is called. All the other arrays (Date, Description, Name) have their 1st array information allocated to a variable?? Code: [Select] $Date = $_POST['Date']; $Name = $_POST['Name']; $Description = $_POST['Description']; $idnumber = $_POST['ID']; $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Picture_Blog", $con); foreach ($idnumber as $ID) { mysql_query("UPDATE slidorion SET Name = '$Name' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Description = '$Description' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Date = '$Date' WHERE ID = '$ID'"); } Hello again
Sorry, I come back cap in hand to ask for one last bit of help. After this I should be done never to bother you again.
I posted just previously regarding outputting the results of a MySQL COUNT query to a PDF file. Staying on that subject to an extent, I've been wracking my brains on why this conundrum isn't working. As before, I wish to display the information from one table but unlike before there are multiple rows as opposed to multiple columns.
I have my table 'faults' and wish to query the top ten, or top most occurring 'site_id' in this table. The following MySLQ query as before works just fine in phpMyAdmin:
"SELECT `site_id` AS `site`, COUNT(*) AS `count`
FROM `faults`
GROUP BY `site`
ORDER BY count(*) DESC;"
Not much in the DB right now but it yields the following as I expect:
Site Count
1 7
2 6
3 6
I was hoping getting this into a PDF wouldn't be so tricky but as usual I've come unstuck. Essentially what is happening is that it's only displays the bottom row, not all. Here's my code:
<?php require('pdf/fpdf/fpdf.php'); include('core/connect.php'); //Create new pdf file $pdf=new FPDF(); $pdf->Open(); //Disable automatic page break $pdf->SetAutoPageBreak(false); //Add first page $pdf->AddPage(); //Heading $pdf->SetFillColor(255,255,255); $pdf->SetFont('Arial','BU',12); $pdf->SetY(25); $pdf->SetX(25); $pdf->Cell(25,6,'Top Site:',9,0,'L',1); $result_topten = mysqli_query($con, "SELECT `site_id` AS `site`, COUNT(*) AS `count` FROM `faults` GROUP BY `site` ORDER BY count(*) DESC;"); while($row = mysqli_fetch_array($result_topten)) { $site = $row['site']; $num_faults = $row['count']; } $pdf->SetFillColor(192,192,192); $pdf->SetFont('Arial','B',10); $pdf->SetY(35); $pdf->SetX(25); $pdf->Cell(50,6,'Site',1,0,'C',1); $pdf->Cell(50,6,'Number of faults',1,0,'C',1); $pdf->SetFillColor(232,232,232); $pdf->SetFont('Arial','',10); $pdf->SetY(45); $pdf->SetX(25); $pdf->Cell(50,6,$site,1,0,'C',1); $pdf->Cell(50,6,$num_faults,1,0,'C',1); $i = $i++; //Send file $pdf->Output(); ?>Resulting output in the PDF: Top Site: Hi everyone
I have a requirement to create some reports and outputting these to a PDF. I'm using FPDF which seems to be rather user-friendly. I was hoping someone could help with me a problem I have regarding MySQL COUNT and PHP arrays.
I have a table named 'faults' and within this a row called 'level'. There are three 'levels' = P1, P2, P3 that could populate this row. I wish to display the output into a PDF so it looks something like this:
Total number of faults;
P1 P2 P3
1 2 3
Where I'm falling short is how to perform the COUNT and then grab the data stick it into an array and output it to the PDF. The MySQL statement you see below, if put directly into phpMyAdmin, seems to do the trick, so I'm hoping I'm on the right track. So far I have this:
<----OUTPUT OMITTED----> $result=mysqli_query($con, "SELECT COUNT(IF(level='P1',1, NULL)) 'P1', COUNT(IF(level='P2',1, NULL)) 'P2', COUNT(IF(level='P3',1, NULL)) 'P3' FROM faults"); //initialize counter $i = 0; //Set maximum rows per page $max = 25; while($row = mysqli_fetch_array($result)) { //If the current row is the last one, create new page and print column title if ($i == $max) { $pdf->AddPage(); //print column titles for the current page $pdf->SetY($y_axis); $pdf->SetX(25); $pdf->Cell(50,6,'Total P1s',1,0,'L',1); $pdf->Cell(50,6,'Total P2s',1,0,'L',1); $pdf->Cell(50,6,'Total P3s',1,0,'L',1); //Go to next row $y_axis = $y_axis + $row_height; //Set $i variable to 0 (first row) $i = 0; } //This bit definitely ain't right $p1 = $row['level']; $p2 = $row['level']; $p3 = $row['level']; $pdf->SetY($y_axis); $pdf->SetX(25); $pdf->Cell(50,6,$p1,1,0,'L',1); $pdf->Cell(50,6,$p2,1,0,'L',1); $pdf->Cell(50,6,$p3,1,0,'R',1); //Go to next row $y_axis = $y_axis + $row_height; $i = $i + 1; } //Send file $pdf->Output(); ?>Appreciate it must look a mess, but would appreciate someone cleverer than me pointing me in the right direction. I've been playing around with this code from http://v3.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart Objective: I'm trying to make the scripts work but without pulling the data from MySQL Database. Instead, I created an array and inserted some info there and trying to replicate the same results but getting confused. For example, on the Index.php file, I made the following changes: <?php // Start the session session_start(); // Include functions require_once('inc/functions.inc.php'); // Products multidimensional Array $products = array("book" => array( 'id' => '1', 'title' => 'Learn Your ABC\'s', 'author' => 'John Doe', 'price' => '14.95'), "video" => array('id' => '2', 'title' => 'Visual Guide to learn', 'author' => 'Adam Smith', 'price' => '21.38'), "puzzle" => array('id' => '3', 'title' => 'Can You Solve?', 'author' => 'Sara Brown', 'price' => '9.41'), "exam" => array('id' => '4', 'title' => 'Test Your Knowledge', 'author' => 'Kim Carver', 'price' => '11.15')); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php /* $sql = 'SELECT * FROM books ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); */ ?> <?php $output[] = '<ul>'; foreach ($products as $product => $product_item) { // $flavor is the key and $piece is the value foreach ($product_item as $item => $piece) { if ($item == "id") { # Conditional logic defined to map specific keys to specified name value $row['id'] = $piece; // echo "The id is ". $id."<br />"; // set just to confirm value correct for variable } elseif ($item == "title") { # Conditional logic defined to map 1st key to price value $row['title'] = $piece; // echo "The title is ". $title."<br />"; // set just to confirm value correct for variable } elseif ($item == "author") { # Conditional logic defined to map 1st key to price value $row['author'] = $piece; // echo "The author is ". $author."<br />"; // set just to confirm value correct for variable } elseif ($item == "price") { # Conditional logic defined to map 1st key to shipping value $row['price'] = $piece; // echo "Price: ". $price."<br /><br />"; // set just to confirm value correct for variable } $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; $output[] = '</ul>'; echo join('',$output); } } ?> </div> </body> </html> And here's the original index.php before my edits which show the sql query to the db: <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php $sql = 'SELECT * FROM books ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); ?> </div> </body> </html> Also, I included the zipped file of the entire script setup. Again, I'm trying to figure out how to make the cart work with using an array for the product instead of MySQL database. My goal is to remove ALL SQL statements from the scripts but stuck with the looping portion to display the title, author, and price from the array as shown above. In case you guys don't know what lisp is, tl;dr is that is an old language without syntax that uses polish notation and parentheses to represent all language constructs. You can also create your own language constructs. For example, this mysql statement : UPDATE table_name SET column1=value1,column2=value2 WHERE some_column=some_valueCan be represented as (update "table_name" (set ('column1 "value1") ('column2 "value2") (where (= some_column "some_value")))One advantage of this whole thing is that you don't have to mix multiple languages to create a site. When you program in php, you actually use html, css, php and MySQL. When you program in lisp, you only use lisp. Another advantage is that the language with no syntax is easier to programaticaly generate than one with it. I can auto generate various sql statements as lisp trees. The disadvantage is that lisp is obscure as hell and no one uses it. So I was thinking of using php arrays to get some of that expressiveness of lisp in PHP and to abstract away necessity to glue together sql strings. So far it has been mixed results. One way to represent update is this ["update", "table_name", ["column1" => "value1", "column2" => "value2"], ["where", [ "=", "some_column", "some_value"]]]I represent columns to be updated as key=>value pairs since column names are unique anyway. One advantage of this method is that I don't have to use mysql_real_escape_string on variables for updating. My interpreter automatically escapes everything inside SET bracket and adds quotes to values. This is however, less than practical in its WHERE part. That's because it is less clear what part you can and can't escape, since column names, functions and values can all be mixed up in WHERE part, and arrays are not nearly as flexible as s-expressions. Anyone has any idea how best to do this? Edited by Goat, 24 July 2014 - 02:46 PM. 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! I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? hi all, how can i make this array dynamic. E.g, i want the numbers to be pulled from a database... Code: [Select] $s=array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" ); thanks in advance, i just cant work it out I'm not sure if this can be done, but I would like to get the sum for each $.row[''] result ex: if $row['robotics'] had values of 100,150,300 I would like to be able to show a total of 550 Code: [Select] <?php echo "<Table border=1>"; echo "<tr><td></td><td>Robotics</td><td>Chiral Stuctors</td><td>Enriched Uranium</td><td>Mechanical Parts</td><td>Coolant</td><td>Consumer Electronics</td><td>Precious Metals</td><td>Reactive Metals</td><td>Oxygen</td><td>Toxic Metals</td></tr>"; $result = mysql_query("select * from `pi`"); while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['pilot']."</td>"; echo "<td>".$row['robotics']."</td>"; echo "<td>".$row['chiralstuctors']."</td>"; echo "<td>".$row['enricheduranium']."</td>"; echo "<td>".$row['mechanicalparts']."</td>"; echo "<td>".$row['collant']."</td>"; echo "<td>".$row['consumerelectronics']."</td>"; echo "<td>".$row['preciousmetals']."</td>"; echo "<td>".$row['reactivemetals']."</td>"; echo "<td>".$row['oxygen']."</td>"; echo "<td>".$row['toxicmetals']."</td></tr>"; } echo "</table>"; ?> Hi i'am try to insert multiple data on a single submit, but i'm a total noob to Arrays, can any one help me out here... one of the members send me this out, but still i can figure it out how to insert the fields onto my database. it inserts but doesnt get the valuee.. Please help! if(isset($_POST['save'])) { unset($_POST['save']); $i = count($_POST['id']); $x = 0; for($x=0; $x <$i;$x++){ foreach($_POST as $data =>$d){ echo $data.'-'.$d[$x].'<br/>'; $insert = mysql_query("insert into tbl_grades"); //sql statement here (example): insert into table name (value of $data) values( value of$d[$x]) -- can anyone help me with this , how can i query to get the value of this, //HOW DO I MAKE MY SQL QUERY TO SAVE THIS OUT, I KNOW THIS IS MY PROBLEM IN THE QUERY.... here's my HTML <input name="id[]" type="hidden" value="<?php echo $row['id'];?>" /> 1st<input name="fg[]" type="text" id="fg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 2nd<input name="sg[]" type="text" id="sg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 3rd<input name="tg[]" type="text" id="tg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 4th <input name="forg[]" type="text" id="forg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> ---- sub_id stands for subject id Hi Guys, I have an array Code: [Select] $arr When i run this function Code: [Select] print_r($arr) I get the output below:- -------------------------------- Code: [Select] Array ( [WHMCSAPI] => Array ( [ACTION] => getclientsproducts [RESULT] => success [CLIENTID] => 87 [PID] => 13 [DOMAIN] => dfgbhcgnd.com [TOTALRESULTS] => 1 [STARTNUMBER] => 0 [NUMRETURNED] => 1 [PRODUCTS] => Array ( [PRODUCT] => Array ( [ID] => 196 [CLIENTID] => 87 [ORDERID] => 218 [PID] => 13 [REGDATE] => 2011-12-07 [NAME] => Walderizer [DOMAIN] => dfgbhcgnd.com [DEDICATEDIP] => [SERVERID] => 3 [FIRSTPAYMENTAMOUNT] => 55.00 [RECURRINGAMOUNT] => 55.00 [PAYMENTMETHOD] => banktransfer [PAYMENTMETHODNAME] => Bank Transfer [BILLINGCYCLE] => Monthly [NEXTDUEDATE] => 2011-12-07 [STATUS] => Active [USERNAME] => vitaforiz [PASSWORD] => ghTfg476fg [SUBSCRIPTIONID] => [LASTUPDATE] => 0000-00-00 00:00:00 [CUSTOMFIELDS] => Array ( [CUSTOMFIELD] => Array ( [NAME] => IP Address [VALUE] => ) ) [CONFIGOPTIONS] => ) ) ) ) --------------------------------- My question is, how can i print only certain parts of the data rather than printing the whole array. For example i only want to echo the values for [NAME], [USERNAME], [PASSWORD] and [NEXTDUEDATE] from the [PRODUCT] part of the array Thanks in advance I am trying to learn about sorting and modifying arrays and I am practicing on a book assignment but need some help to grasp what I need to do. If you go here, you will see how it is supposed to work. http://198.86.244.3/mabarckhoff/WEB182/ch11_ex1/ I need to write a case to sort the task when you click the sort button and modify when you click that button. The delete button works and the add task works. I understand the sort array and have added that case, but don't know how to get it to work with the submit. Also there is a promote button so would need 'promote' what ever you have chosen in the dropdown menu to the top. Here is my code. tasklist.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Task List Manager</title> <link rel="stylesheet" type="text/css" href="main.css"/> </head> <body> <div id="page"> <div id="header"> <h1>Task List Manager</h1> </div> <div id="main"> <!-- part 1: the errors --> <?php if (count($errors) > 0) : ?> <h2>Errors:</h2> <ul> <?php foreach($errors as $error) : ?> <li><?php echo $error; ?></li> <?php endforeach; ?> </ul> <?php endif; ?> <!-- part 2: the tasks --> <h2>Tasks:</h2> <?php if (count($task_list) == 0) : ?> <p>There are no tasks in the task list.</p> <?php else: ?> <ul> <?php foreach( $task_list as $id => $task ) : ?> <li><?php echo $id + 1 . '. ' . $task; ?></li> <?php endforeach; ?> </ul> <?php endif; ?> <br /> <!-- part 3: the add form --> <h2>Add Task:</h2> <form action="." method="post" > <?php foreach( $task_list as $task ) : ?> <input type="hidden" name="tasklist[]" value="<?php echo $task; ?>"/> <?php endforeach; ?> <label>Task:</label> <input type="text" name="newtask" id="newtask"/> <br /> <label> </label> <input type="submit" name="action" value="Add Task"/> </form> <br /> <!-- part 4: the modify/promote/delete form --> <?php if (count($task_list) > 0 && empty($task_to_modify)) : ?> <h2>Select Task:</h2> <form action="." method="post" > <?php foreach( $task_list as $task ) : ?> <input type="hidden" name="tasklist[]" value="<?php echo $task; ?>"/> <?php endforeach; ?> <label>Task:</label> <select name="taskid"> <?php foreach( $task_list as $id => $task ) : ?> <option value="<?php echo $id; ?>"> <?php echo $task; ?> </option> <?php endforeach; ?> </select> <br /> <label> </label> <input type="submit" name="action" value="Modify Task"/> <input type="submit" name="action" value="Promote Task"/> <input type="submit" name="action" value="Delete Task"/> <br /> <label> </label> <input type="submit" name="action" value="Sort Tasks"/> </form> <?php endif; ?> <!-- part 5: the modify save/cancel form --> <?php if (!empty($task_to_modify)) : ?> <h2>Task to Modify:</h2> <form action="." method="post" > <?php foreach( $task_list as $task ) : ?> <input type="hidden" name="tasklist[]" value="<?php echo $task; ?>"/> <?php endforeach; ?> <label>Task:</label> <input type="hidden" name="modifiedtaskid" value="<?php echo $task_index; ?>" /> <input type="text" name="modifiedtask" value="<?php echo $task_to_modify; ?>" /><br /> <label> </label> <input type="submit" name="action" value="Save Changes"/> <input type="submit" name="action" value="Cancel Changes"/> </form> <?php print_r($_POST); ?> <?php endif; ?> </div><!-- end main --> </div><!-- end page --> </body> </html> index.php <?php if (isset($_POST['tasklist'])) { $task_list = $_POST['tasklist']; } else { $task_list = array(); // some hard-coded starting values to make testing easier $task_list[] = 'Write chapter'; $task_list[] = 'Edit chapter'; $task_list[] = 'Proofread chapter'; } $errors = array(); switch( $_POST['action'] ) { case 'Add Task': $new_task = $_POST['newtask']; if (empty($new_task)) { $errors[] = 'The new task cannot be empty.'; } else { $task_list[] = $new_task; } break; case 'Delete Task': $task_index = $_POST['taskid']; unset($task_list[$task_index]); $task_list = array_values($task_list); break; case 'Sort Task': sort($task_list); print_r($task_list); break; /* case 'Save Changes': case 'Cancel Changes': case 'Promote Task': */ } include('task_list.php'); ?> Ok so this link returns HTML $hitlist = file_get_contents($iMobLink."get_hit_list?user_id=".$iStore[2]."&level=10&auth_key=".$iStore[3]); now to parse it out I have this $entry = explode('<entry>', $hitlist); $hitlist = file_get_contents($iMobLink."get_hit_list?user_id=".$iStore[2]."&level=10&auth_key=".$iStore[3]); $user_id = explode('<user_id>', $hitlist); $user_id = explode('</user_id>', $user_id[1]); $mobname = explode('<mob_name>', $hitlist); $mobname = explode('</mob_name>', $mobname[1]); $paiduser = explode('<paid_user>', $hitlist); $paiduser = explode('</paid_user>', $paid_user[1]); $amount = explode('<amount>', $hitlist); $amount = explode('</amount>', $amount[1]); $paid_time = explode('<placed_time_ago>', $hitlist); $paid_time = explode('</placed_time_ago>', $paid_time[1]); $level = explode('<level>', $hitlist); $level = explode('</level>', $level[1]); $entry = explode('</entry>', $entry[1]); echo $user_id[0]."\n"; echo urldecode($mobname[0])."\n"; echo $amount[0]."\n"; echo $paid_time[0]."\n"; echo $level[0]."\n"; echo $entry[0];} Ok now.... this only returns one entry of the xml when there are more than 10. I need it to return all ten+ of the entrys here is what the xml looks like <outer> − <xml> − <entry> − <target_user> <user_id>512433892</user_id> <mob_name>MR%2025TATT00S%2C%20Level%2015</mob_name> </target_user> − <paid_user> <user_id>554190549</user_id> <mob_name>PRINCE%20OF%20NEW</mob_name> </paid_user> <amount>48000000000</amount> <is_npc>false</is_npc> <placed_time_ago>3 days ago</placed_time_ago> <level>15</level> </entry> − <entry> − <target_user> <user_id>530120192</user_id> <mob_name>EVILNESS%20SIMPLIFIED%2C%20Level%2013</mob_name> </target_user> − <paid_user> <user_id>539494114</user_id> <mob_name>StompinDatAzz</mob_name> </paid_user> <amount>1478608800</amount> <is_npc>false</is_npc> <placed_time_ago>1 day ago</placed_time_ago> <level>13</level> </entry> − <entry> − <target_user> <user_id>526183645</user_id> <mob_name>snatch%20rider%2C%20Level%20112</mob_name> </target_user> − <paid_user> <user_id>450207248</user_id> <mob_name>ShiftyShellShock</mob_name> </paid_user> <amount>999999999</amount> <is_npc>false</is_npc> <placed_time_ago>22 hours ago</placed_time_ago> <level>112</level> </entry> − <entry> − <target_user> <user_id>542145086</user_id> <mob_name>Riding%20Raider%2C%20Level%2043</mob_name> </target_user> − <paid_user> <user_id>513441119</user_id> <mob_name>Level%20U%20uP</mob_name> </paid_user> <amount>334616000</amount> <is_npc>false</is_npc> <placed_time_ago>18 hours ago</placed_time_ago> <level>43</level> </entry> − <entry> − <target_user> <user_id>554043828</user_id> <mob_name>klaibers%20limited%2C%20Level%2011</mob_name> </target_user> − <paid_user> <user_id>522432052</user_id> <mob_name>Sloppy%20Seconds</mob_name> </paid_user> <amount>39344504405</amount> <is_npc>false</is_npc> <placed_time_ago>17 hours ago</placed_time_ago> <level>11</level> </entry> − <entry> − <target_user> <user_id>496266215</user_id> <mob_name>Geheim%20Abwher%2C%20Level%207</mob_name> </target_user> − <paid_user> <user_id>216904061</user_id> <mob_name>yve1</mob_name> </paid_user> <amount>2499912800</amount> <is_npc>false</is_npc> <placed_time_ago>16 hours ago</placed_time_ago> <level>7</level> </entry> − <entry> − <target_user> <user_id>524874924</user_id> <mob_name>MYLILFRIEND%2C%20Level%20104</mob_name> </target_user> − <paid_user> <user_id>536745842</user_id> <mob_name>SUC%20MY%20GLOCK</mob_name> </paid_user> <amount>1615247200</amount> <is_npc>false</is_npc> <placed_time_ago>15 hours ago</placed_time_ago> <level>104</level> </entry> − <entry> − <target_user> <user_id>531185082</user_id> <mob_name>THE%20RAGE%20WITHIN%2C%20Level%2031</mob_name> </target_user> − <paid_user> <user_id>512862859</user_id> <mob_name>The%20Kozmik%20Slop</mob_name> </paid_user> <amount>16536800</amount> <is_npc>false</is_npc> <placed_time_ago>14 hours ago</placed_time_ago> <level>31</level> </entry> − <entry> − <target_user> <user_id>494326270</user_id> <mob_name>RIDE%20HIS%20CUCUMBER%2C%20Level%2016</mob_name> </target_user> − <paid_user> <user_id>554794332</user_id> <mob_name>STDS%20R%20BAD%20MMKAY</mob_name> </paid_user> <amount>337825600</amount> <is_npc>false</is_npc> <placed_time_ago>14 hours ago</placed_time_ago> <level>16</level> </entry> − <entry> − <target_user> <user_id>558355598</user_id> <mob_name>DEATH%20TO%20HITLIST%2C%20Level%2011</mob_name> </target_user> − <paid_user> <user_id>558349535</user_id> <mob_name>Gangsta%20Love</mob_name> </paid_user> <amount>181600000</amount> <is_npc>false</is_npc> <placed_time_ago>10 hours ago</placed_time_ago> <level>11</level> </entry> − <entry> − <target_user> <user_id>545114043</user_id> <mob_name>Ridin%20Dirty%2C%20Level%20130</mob_name> </target_user> − <paid_user> <user_id>510805692</user_id> <mob_name>iced%20baby</mob_name> </paid_user> <amount>481680800</amount> <is_npc>false</is_npc> <placed_time_ago>10 hours ago</placed_time_ago> <level>130</level> </entry> Notice there is more than one energy.. now how to I parse it out to where I can define each entry by a variable or something... any help is appreciated.. Thanks Hi, I need to do this: Write a method to quickly find the array index position of a given number in a ascending sorted array of numbers. e.g. in an array { 1, 2, 5, 10, 102 }, the array index position of a given number 5, would have an answer of 2. We're looking for an answer that's better than O(n). I was using php's built in methods but I need to do this with a basic function using no helper methods. Can anybody help me out with this? Thanks in advance. Let's say I have an array like this: Man1(0), Man1(1), Man1(2), etc. Man2(0), Man2(1), Man2(2), etc. Man3(0), Man3(1), Man3(2), etc. ... and I want to loop through the array. I know I can do: Code: [Select] $i=0; while $i<=99 {//...do something with Man1[$i];} i++; but can I also do a loop with each Man? Like: Code: [Select] $i=0;$a=1; while $i<=99 {//...do something with Man$a[$i];} i++;a++; I've written all the code for each Man separately and I'm thinking there's got to be a way to shorten the code with another loop, but I don't know how. Hope that makes sense. Thanks. Ok i am trying to create a simple program that will allow mwe to use an array with 8 numbers, the output form should show the numbers in their original order that the user inputs them, in numerical order, Highest number, lowest number and then the average number. I am confused on what logic i would use to do this. If anyone could help me get started it would be much appreciated. here's waht i have so far. Code: [Select] <?php $Num1 = $_POST['fielda']; $Num2 = $_POST['fieldb']; $Num3= $_POST['fieldc']; $Num4 = $_POST['fieldd']; $Num5 = $_POST['fielde']; $Num6 = $_POST['fieldf']; $Num7 = $_POST['fieldg']; $Num8 = $_POST['fieldh']; $Numbers = array(1,2,3,4,5,6,7,8); $big = max($Numbers); $small = min($Numbers); $average = array_sum($Numbers) / 8; ?> |