Jump to content

tHud

Members
  • Posts

    93
  • Joined

  • Last visited

Everything posted by tHud

  1. Oh thank you so much ginerjm, I'm always overthinking things! I really appreciate your help. @benanamen - Thank you for your input. I am aware of this, it's not my code. I only saw it today for the first time.
  2. I'm sorry, this is the code. $query = "SELECT assignTable FROM EXHIBITORS WHERE year = $newYear"; $result = $mysqli->query($query) or die("There was a problem with the query: " . mysqli_error($mysqli)); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) {$myResults[] = $row; } } $myVals = array_column($myResults, 'assignTable'); echo '<pre>'; print_r($myVals); echo '</pre>'; I've been asked to alter some code of a guy that left the company.
  3. Hello everyone I have an array like this... Array ( [0] => A27 [1] => A25+A26 [2] => B1 [3] => B7 [4] => C10 [5] => A3 [6] => B5 [7] => C1+C2 [8] => A1 [9] => A6 [10] => C8 [11] => A12 [12] => C14 [13] => A15 [14] => C11 [15] => B3+B4 ) I would like to remove the values after the + sign and replace the second part back in the array. Something like this... Array ( [0] => A27 [1] => A25 [2] => B1 [3] => B7 [4] => C10 [5] => A3 [6] => B5 [7] => C1 [8] => A1 [9] => A6 [10] => C8 [11] => A12 [12] => C14 [13] => A15 [14] => C11 [15] => B3 [16] => A26 [17] => C2 [18] => B4 ) I think I've been away from PHP too long because I've tried all sorts of ways of doing this and I am really stuck. Thank you for any suggestions.
  4. Thank you.
  5. Hello, I've been struggling to get array_multisort to work... If I have this array output... I'd like to sort on the product sub-array. The array is called orders and that number 15 is the specific order id. Array ( [15] => Array ( [clientId] => 1 [clientName] => Bob [o_date] => 2014-01-02 [o_number] => 1 july-append [o_notes] => order on 1 july-append [i_date] => 2014-01-17 [i_number] => 18072014-append [i_notes] => invoiced on 18 july 14 -append [products] => Array ( [0] => Array ( [id] => 37 [prod_id] => 1 [product] => door [qty] => 2 [cost] => 12.121 ) [1] => Array ( [id] => 38 [prod_id] => 2 [product] => window [qty] => 3 [cost] => 22.5 ) [2] => Array ( [id] => 36 [prod_id] => 3 [product] => chair [qty] => 1 [cost] => 300 ) ) ) ) So, I've tried a number of variations of this... array_multisort($orders[$theOrder]['products'], SORT_DESC, SORT_NUMERIC, $orders[$theOrder]['products'], SORT_ASC, SORT_STRING); array_multisort($orders[$theOrder]['products']['id'], SORT_DESC, SORT_NUMERIC); etc. etc. - but I seem to get no-where. Can some-one kindly point out my error, please? Thank you. :)
  6. That's it. Thanks so much for taking the time to help.
  7. Hi, I really don't know why it is submitting. I've been staring at the code since you last posted but I guess my knowledge does not go deep enough. This is the whole script (very much in prototype). <?php if ( isset($_POST['client_id']) && ($_POST['client_id'] == "addClient")) { header("Location: clients.php?addClient" ); exit; } include("includes/connect.php"); include("includes/header.txt"); if (isset($_POST['addOrder'])) { foreach($_POST['select'] as $key => $value) { $items[] = current(explode(":", $value)); } $stmt = $mysqli->prepare("INSERT INTO orders (client_id, o_date, o_number, o_notes ) VALUES (?, ?, ?, ?)"); $stmt->bind_param('isss', $_POST['client_id'], userToMysql($_POST['o_date']), $_POST['o_number'], $_POST['o_notes']); $stmt->execute(); $newOrderId =$mysqli->insert_id; $stmt->close(); if(!empty($_POST['qty'])) { foreach($_POST['qty'] as $cnt => $qty) { $stmt = $mysqli->prepare("INSERT INTO order_details (o_id, prod_id, qty) VALUES (?, ?, ?);"); $stmt->bind_param('iii', $newOrderId, $items[$cnt], $qty); $stmt->execute(); $stmt->close(); } } include("includes/footer.txt"); } $query = "SELECT client_id, client FROM clients ORDER BY client ASC"; $result = $mysqli->query($query); echo '<form method="post">'; echo '<label>Client</label>'; echo '<select name="client_id">'; echo '<option value="addClient">Add New Client</option>'; while ($row = $result->fetch_assoc()) { echo'<option value="'.$row['client_id'].'">'.$row['client'].'</option>'; } echo '</select><br>'; ?> <label>Date</label><input type="text" name="o_date" size="10"> <script language="JavaScript"> new tcal ({ 'formname': 'orderform', 'controlname': 'o_date' }); </script> <label>Order No.</label><input type="text" name="o_number" size="25"><br><br> <label>Notes</label><textarea name="o_notes" cols="65" rows="3"></textarea><br><br> <div id='container'> <div id='rowNum1'> qty: <input type="qty" name="qty{}"><br> <?php $prod = "SELECT prod_id, product FROM products ORDER BY product ASC"; $prodRes = $mysqli->query($prod); echo ' Select: <select name="select{}">'; while ($p = $prodRes->fetch_assoc()) { echo'<option value="'.$p['prod_id'].':'.$p['product'].'">'.$p['product'].'</option>'; } echo '</select>'; ?> </div> </div> <button onclick="addRow()">Add Row</button> <input type="submit" value="Submit new order" name="addOrder"> </form> <script type="text/javascript"> function addRow() { var container = document.getElementById('container'); var rowNum = container.children.length + 1; var rowSetHTML = container.children[0].innerHTML; var rowHTML = '<p id="rowNum'+rowNum+'">'+rowSetHTML+'</p>'; $( "#container" ).append(rowHTML); } </script> <?php include("includes/footer.txt"); ?>
  8. Hi Psycho, Thanks so much for this answer. (Sorry abbout the use of the word 'clone' - whilst researching the answer I read about clone and used the word instead of append.) Your code seems to do exactly what I need (thanks again!). Just one thing though... How can I stop the form from submitting when using the button... <button onclick="addRow()">Add Row</button> (As opposed to when I use the main form submit button when all the other fields have been filled in.) Thank you again
  9. Should this while ($row = mysqli_fetch_array ($result)){ read $results ?
  10. Hello I'm using a small script (that I found online) to dynamically add fields to an order form. It works well with normal text fields but I would like to use it with a select box fields (as it draws data from MySQL). My problem is, that when the field is 'cloned' it contains the product id and not the product name - which is what the user needs to see. <?php echo '<form method="post" name="orderform">'; // lots of form fields... echo '<div id="itemRows">'; echo 'Item quantity: <input type="text" name="add_qty" size="4" />'; $prod = "SELECT prod_id, product FROM products ORDER BY product ASC"; $prodRes = $mysqli->query($prod); echo 'Item name : <select name="add_name">'; while ($p = $prodRes->fetch_assoc()) { echo'<option value="'.$p['prod_id'].'">'.$p['product'].'</option>'; } echo '</select>'; echo '<input onclick="addRow(this.form);" type="button" value="Add row" /> (Won't be saved until you click on "Add row")'; if(isset($product['qty']) && isset($product['name'])) { ?> <p id="oldRow<?=$product['id']?>"> Item quantity: <input type="text" name="qty<?=$product['id']?>" size="4" value="<?=$product['qty']?>" /> Item name: <input type="text" name="name<?=$product['id']?>" value="<?=$product['add_name']?>" /> <input type="checkbox" name="delete_ids[]" value="<?=$product['id']?>"> Mark to delete </p> </div> <?php } ?> </div> <input type="submit" value="Submit new order" name="addOrder"> </fieldset> </div> </form> <script type="text/javascript"> var rowNum = 0; function addRow(frm) { rowNum ++; var row = '<p id="rowNum'+rowNum+'">Item quantity: <input type="text" name="qty[]" size="4" value="'+frm.add_qty.value+'"> Item name: <input type="text" name="name[]" value="'+frm.add_name.value+'"> <input type="button" value="Remove" onclick="removeRow('+rowNum+');"></p>'; jQuery('#itemRows').append(row); frm.add_qty.value = ''; frm.add_name.value = ''; } function removeRow(rnum) { jQuery('#rowNum'+rnum).remove(); } </script> I know I could use the $p['product'] value in the select box field, but when it is submiitted - it loses its $p['prod_id'] value which I need to input back into the MySQL database. I did try echo'<option value="'.$p['prod_id'].':'.$p['product'].'">'.$p['product'].'</option>'; and then explode... foreach($_POST['name'] as $key => $value) { $items[] = current(explode(":", $value)); } ...but clearly, that is a dreradful solution and looks awful to the user. Any thoughts, please? Thank you.
  11. That's the best news you could have given me. Thank you so much (everybody) for your assistance.
  12. Thank you Mac & Kicken On this occasion I think that the array solution would be the best option for me. Could I just ask (hopefully) one last question? I have a fourth table now that tracks the number/ cost etc of items in the product table... Array ( [3] => Array ( [clientId] => 3 [clientName] => Joe [o_date] => 2014-07-01 [o_number] => 11112 [o_notes] => blah blah [details] => Array ( [0] => Array ( [qty] => 10 [cost] => 19.5 ) [1] => Array ( [qty] => 2 [cost] => 250.5 ) ) [products] => Array ( [0] => Array ( [prod_id] => 1 [product] => door ) [1] => Array ( [prod_id] => 2 [product] => window ) ) ) ) I would like to output the sub-arrays details and products but I'm failing with the nested for-each loops. The results are getting duplicated. <table border="1"> <?php foreach ($orders as $o): ?> <?php foreach ($o['details'] as $d): ?> <?php foreach ($o['products'] as $p): ?> <tr> <td> Qty: <?=htmlentities($d['qty'])?>; </td> <td> id: <?=htmlentities($p['prod_id'])?>; </td> <td> Name: <?=htmlentities( $p['product']);?></td> </tr> <?php endforeach; ?> <?php endforeach; ?> <?php endforeach; ?> </table> I have beeen Googling on how to do this, but can't find a solution. Thank you again.
  13. Sorry - I can't edit the above post and I've just realised it won't work, as it can't track multiple products. Ignore please - I'll have to rethink this.
  14. Hi Mac - thanks for the advice which I am taking on board. I am redesigning the table structure - hopefully, this is what you meant? I'm afraid I am not well enough versed in php to understand the terminology in your other post (about data sections). In this line... I see that the data has been 'ouput'(?) previously - but I'm not sure what is meant by closing the data section.
  15. Hello, I have 3 tables for clients, orders and the products they ordered. Here are the tables... Clients CLIENT_ID CLIENT_NAME Orders o_id client_id o_number o_date o_notes Products o_id qty name I am getting the results I need with this query... SELECT clients.CLIENT_ID, clients.CLIENT_NAME, orders.o_id, orders.client_id, orders.o_date, orders.o_number, orders.o_notes, products.o_id, products.qty, products.name FROM clients, orders, products WHERE clients.CLIENT_ID = orders.client_id AND orders.o_id = products.o_id AND orders.o_id = $theOrder ..and this is the php I use to display it... while ($row = $result->fetch_assoc()) { echo "<h2>$row[CLIENT_NAME]</h2>"; echo '<label>Date</label><input type="text" value="'.timechange($row['o_date']).'" readonly><br>'; echo '<label>Order No.</label><input type="text" value="'.$row['o_number'].'" readonly><br>'; echo '<label>Notes</label><input type="text" value="'.$row['o_notes'].'" readonly>'; echo '<label>Product Qty.</label><input type="text" value="'.$row['qty'].'" readonly><br>'; echo '<label>Product Name</label><input type="text" value="'.$row['name'].'" readonly><br>'; } However - rather predictably I am getting three forms printed out as the results from MySQL look like this... Is it possible to somehow get my form to display the results, like this... I hope I'm explaining myself well enough - and thank you for reading.
  16. Hi, Thanks very much for the response. I've tried it but I guess I'm going wrong somewhere. $sql = "SELECT id, subject FROM newsdat WHERE category = ? ORDER BY id DESC LIMIT (SELECT howmany FROM newscat WHERE id = ?)"; $stmt = $conn->stmt_init(); if ($stmt->prepare($sql)) { $stmt->bind_param('i', $catNumber); // I also tried this... // $stmt->bind_param('ii', $catNumber, $catNumber); $stmt->bind_result($id, $subject); I'm quite lost...
  17. HI I'm just trying to learn some php/mysqli and I'm not sure how to run two consecutive queries. I need to call a function which will... a) get a result (howmany) then apply that to a second query e.g. a LIMIT $howmany Something like this... // if form has been submitted, do stuff if (array_key_exists('build', $_POST)) { $conn->autoCommit(false); doStuff($a, $b); $conn->commit(); } function doStuff($a, $b){ $sql1 = "SELECT howmany FROM news WHERE id = ?"; $stmt1 = $conn->stmt_init(); $stmt1->prepare($sql1); $stmt1->bind_param('i', $a); $stmt1->execute(); $stmt1->bind_result($howmany); $stmt1->fetch(); $stmt1->close(); $sql2 = "SELECT STUFF LIMIT $howmany"; $stmt2 = $conn->stmt_init(); if ($stmt2->prepare($sql2)) { $stmt2->bind_param('i', $catNumber); $stmt2->bind_result($id, $subject, $howmany); $ok = $stmt2->execute(); while ($stmt2->fetch()) { // do stuff } } I am aware that this looks awful but that's why I'm here How could I go about doing this properly? Sorry if there is insufficient info - I'll try to correct that as I get responses (if I get any ) Thank you.
  18. Hi - just wondering if anyone could point me in the right direction with the script above
  19. ha ha yes! In younger days I was an electronics engineer and I certainly know that feeling Well, the screen flashed briefly before going blank but eventually I managed to copy these messages. I have to tell you that I really appreciate every-bodies help. It's already more than the new owner of the software is prepared to do. Thank you!
  20. Just for completeness, I should point out the the database connection variables are stored in the blanked file - which clearly will account for the white pages in the admin area. When trying to access the script as a user - there is an error message along the lines of ---- dbase error - contact admin.
  21. I tried replacing the function with the one you posted - and it's the same thing. No errors are reported and a white screen. (Source displays nothing except the #1 which I believe Firefox adds.) Here are some examples of the calls to the function...
  22. Hi, .htaccess From PHPinfo I added these lines ...and I see that $body contains all the expected data of a config file. Then I removed the echo /exit commands and the script predictably blanked the file again (unfortunately - no error reported). I did try using file_put_contents (just to check - and it worked). By that I mean that wherever another script calls that function - I replaced it with f_p_c - but there are so many calls to that function, I felt it better to ask here first. My inexperience with php meant that I was unable to re-write the original function using file_put_contents ..and of course, as you say - upgrades could be a serious issue ongoing.
  23. I'm hosted on a shared server - so I have created this htaccess file. Hopefully that's ok? However, no errors are being reported. When I update some admin setting the config file is being erased and all I see is a blank (white) screen.
  24. Hello I have been using a certain forum software for many years now on an old php4 server. I recently trialed the software on a php5 server in preparation for upgrading. My forums appeared as plain white pages as soon as I altered any admin feature. I tracked the casue down to a function that locks and writes to the admin file. Whenever this function is called, the admin file gets wiped to zero bytes. Can anyone suggest a better way of writing this function? This forum is quite well known and in use on many different platforms, other users are not reporting problems - so I guess I'm an oddity. I will seriously be considering moving to new software whether or not I can resolve this issue. (The new company owner doesn't appear the least bit interested in the product.)
  25. Aaaaaahhhhhh... requinix, I appreciate your patience, the world is a better place with you in it! Thank you
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.