-
Posts
93 -
Joined
-
Last visited
Profile Information
-
Gender
Female
tHud's Achievements

Member (2/5)
0
Reputation
-
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.
-
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.
-
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.
-
Thank you.
-
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. :)
-
That's it. Thanks so much for taking the time to help.
-
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"); ?>
-
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
-
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.
-
That's the best news you could have given me. Thank you so much (everybody) for your assistance.
-
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.
-
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.
-
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.
-
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.