-
Posts
24,613 -
Joined
-
Last visited
-
Days Won
834
Everything posted by Barand
-
PHP Simple Dom, Regex to Replace, and Auto-Incement a Variable
Barand replied to bschultz's topic in Regex Help
Then change the code. I've given you a start. [EDIT] What the hell! $xml = simplexml_load_string($html); $trs = $xml->xpath("//tr[@class='hscore' or @class='vscore']"); $i = 1; foreach ($trs as $tr) { $tr->td[0] = "#$i ".$tr->td[0]; ++$i; } echo '<pre>' . htmlentities($xml->asXML()) . '<?pre>'; -
PHP Simple Dom, Regex to Replace, and Auto-Incement a Variable
Barand replied to bschultz's topic in Regex Help
Use xpath. $xml = simplexml_load_string($html); $trs = $xml->xpath("//tr[@class='hscore']"); $i = 1; foreach ($trs as $tr) { $tr->td[0] = "#$i ".$tr->td[0]; ++$i; } $trs = $xml->xpath("//tr[@class='vscore']"); $i = 1; foreach ($trs as $tr) { $tr->td[0] = "#$i ".$tr->td[0]; ++$i; } echo '<pre>' . htmlentities($xml->asXML()) . '<?pre>'; gives <?xml version="1.0"?> <table border="1" style="width:100%;" cellspacing="0" cellpadding="3"> <tr class="stats-section"> <td colspan="99">Scoring</td> </tr> <tr class="stats-section"> <td colspan="99">2nd Period</td> </tr> <tr class="hscore"> <td>#1 UMD</td> <td>4×4</td> <td> Kobe Roth (1)</td> <td> Noah Cates, Casey Gilling </td> <td align="right">12:35</td> </tr> <tr class="vscore"> <td>#1 BSU</td> <td>4×4</td> <td> Alex Ierullo (1)</td> <td> Kyle Looft </td> <td align="right">13:06</td> </tr> <tr class="stats-section"> <td colspan="99">3rd Period</td> </tr> <tr class="hscore"> <td>#2 UMD</td> <td/> <td> Blake Biondi (1)</td> <td> Quinn Olson </td> <td align="right">10:10</td> </tr> </table> -
You almost had it fruits = ["apple", "orange", "cherry"]; for (x = 0; x< fruits.length; x++) { document.getElementById("demo2").innerHTML += fruits[x] + "<br>"; } or fruits = ["apple", "orange", "cherry"]; $.each(fruits, function(k,v) { $("#demo").append(v + "<br>") })
-
how to i get the user_id to save it in every row in my database?
Barand replied to sashavalentina's topic in PHP Coding Help
Your input form has a mass of (unnecessary) hidden inputs for just about eveything but the user_id. -
What is HTML markup for that page? Then we can get an idea of what you are trying to do. Do you realize you can only use an id once - they have to be unique? The first time throught the loop will put apple into demo. The second time will overwrite apple with orange. Finallly you will finish with just cherry in the demo element.
-
Good - that's what I told you to use 16 hours and many posts ago
-
Here's what your code is attempting to do. Does it look anything like what you intended? fruits = ["apple", "orange", "cherry"]; // define an array of fruits x = document.getElementById("myList").innerHTML; // get text content from mylist and put in x // (I have no idea how this relates to rest of the code) for (x = 0; x< fruits.length; x++) { // now use x as a counter to loop throught fruits array // (whatever you put in x above is now replaced by the counter values) document.getElementById("demo").innerHTML = x // each time through the loop put the value of x (0,1,2) into demo // so, at the end of the loop, demo should have value of 2. }
-
try class DB { protected static $con; public static function getConnection(){ try{ self::$con = new PDO( 'mysql: host= localhost; dbname=testdb', 'root', 'password'); self::$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$con->setAttribute( PDO::ATTR_PERSISTENT, false ); } catch (PDOException $e) { echo "Could not connect to database."; exit; } //Returns Writeable db connection return self::$con; } } $conn = DB::getConnection();
-
I'd do it this way $res = $db->query("SELECT status_to , COUNT(*) as tot FROM crm_log GROUP BY status_to "); $totals = array_column($res->fetchAll(), 'tot', 'status_to'); $heads = "<tr><th>" . join('</th><th>', array_keys($totals)) . "</th></tr>\n"; $vals = "<tr><td>" . join('</td><td>', $totals) . "</td></tr>\n"; ?> <table border='1'> <?=$heads?> <?=$vals?> </table>
-
Here's an example script using this test data +------+---------+-------+ | id | product | price | +------+---------+-------+ | A001 | Widget | 10.99 | | B002 | Gizmo | 3.49 | | C003 | Thingy | 56.25 | | D444 | Wotsit | 2.25 | +------+---------+-------+ Code <?php require 'db_inc.php'; if ($_SERVER['REQUEST_METHOD']=='POST') { echo "Submitted form data:<br>"; echo '<pre>' . print_r($_POST, 1) . '</pre>'; // process the data here } $res = $db->query("SELECT product_id as id , product_name as product , price FROM product "); $tdata = ''; foreach ($res as $row) { $tdata .= <<<TDATA <tr> <td>{$row['product']}</td> <td class='price ra' data-id='{$row['id']}' data-val='{$row['price']}'>{$row['price']} €</td> <td class='ra'> <input type='number' class='qty' data-id='{$row['id']}' name='qty[{$row['id']}]' value='0'></td> <td class='total ra' data-id='{$row['id']}' >0 €</td> </tr> TDATA; } ?> <html> <head> <title>Sample</title> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> $().ready( function() { $(".qty").change( function() { var qty = $(this).val() var id = $(this).data("id") var price = $(".price[data-id="+id+"]").data("val") var tot = (qty * price).toFixed(2) $(".total[data-id="+id+"]").html(tot+" €") }) }) </script> <style type='text/css'> table { width: 600px; } tr { height: 55px; vertical-align: middle; } th, td { padding: 0 16px; } .qty { width: 50px; } .ra { text-align: right; } </style> </head> <body> <form method='post'> <table> <tr><th>Produkt</th> <th>Einzelpreis</th> <th>Menge</th> <th>Gesamtpreis</th> </tr> <?=$tdata?> </table> <input type='submit' value='Submit'> </form> </body> </html> Sample output
-
Of course you can <style type='text/css'> .w3-vomit { background-color: #f8b9ce; color: #c4ff4d; } </style> <h1 class="w3-vomit w3-padding">Example heading</h1>
-
insert data in form element does not insert into my tables?
Barand replied to sashavalentina's topic in PHP Coding Help
These fields shouldn't even be in the cart table, they should be retrieved from the product table when required. All you need are the ids and quantity (you certainly don't need the product title 3 times!). Instead of a query to see if there is already a record for the user/product you should define that combination of columns as UNIQUE. Having done that you use a single query for the inserts and updates INSERT INTO cart (user_id, product_id, seller_id, quantity) VALUES (? , ? , ? , ?) ON DUPLICATE KEY UPDATE quantity = VAUES(quantity); -
onclick of an html <a> tag change what $table will be used
Barand replied to Elara's topic in PHP Coding Help
Your links would be in the form <a href='djams_rmc.php?branch=X'> where X is the id of the branch. Then, in your appintments page (djams_rmc.php), you get the required branch with $id = $_GET['branch']; $query = $db->prepare("SELECT whatever FROM appointment WHERE branch_id = ?"); $query->execute([ $id ]); -
onclick of an html <a> tag change what $table will be used
Barand replied to Elara's topic in PHP Coding Help
Have one appointment table for all branches. Add an extra column (indexed) for "branch_id" so you know which branch each row belongs to. Then all your query needs is "WHERE branch_id = ?" and no need to switch tables. +-----------------+ | branch | +-----------------+ +------| branch_id | | | branch_name | +------------------+ | +-----------------+ | appointment | | +------------------+ | | app_id | | | branch_id |>---------+ | app_date_time | | description | | etc | +------------------+ -
onclick of an html <a> tag change what $table will be used
Barand replied to Elara's topic in PHP Coding Help
Why is the data for the different branches in different tables? Is the structure of the data different for each branch? -
Put values to text fields after submit
Barand replied to Temporary_Failure's topic in PHP Coding Help
In two words - variable scope. Variables created inside a function are not available outside of it. Have your function return an array return ["hinta" => $hinta, "stock" => $stock ]; Call $data = func(); then put those array values in your fields. [edit] PS Just return $haku. -
You have shown us your html for the login and php code which processes the login. Your code references three php file login.php home.php index.php What we don't know is where the code you have shown us is placed. Nor do we know what exactly which you are running when you see the error. We do not know the flow that is taking place from one to the next, and given your problem, I'm not sure you do either. Typical flow is like this, but it looks like you are starting at "X"
-
Getting all data in a particular timeframe for the respective agent_id
Barand replied to JJM50's topic in MySQL Help
Data +----+---------+----------+-----------+---------------------+ | id | refno | agent_id | status_to | logtime | +----+---------+----------+-----------+---------------------+ | 1 | LP01552 | 57 | Draft | 2021-10-05 10:33:12 | | 2 | LP02552 | 57 | Unpublish | 2021-10-04 10:33:12 | | 3 | LP03552 | 57 | Draft | 2021-10-05 10:33:12 | | 4 | LP04552 | 57 | Publish | 2021-10-09 10:33:12 | | 5 | LP05552 | 57 | Draft | 2021-10-10 10:33:12 | | 6 | LP06552 | 57 | Publish | 2021-10-11 10:33:12 | | 7 | LP07552 | 57 | Action | 2021-10-06 10:33:12 | | 8 | LP08552 | 58 | Draft | 2021-10-02 10:33:12 | | 9 | LP09552 | 58 | Unpublish | 2021-10-11 10:33:12 | | 10 | LP09652 | 58 | Publish | 2021-10-08 10:33:12 | | 11 | LP08542 | 59 | Draft | 2021-10-06 10:33:12 | | 12 | LP09542 | 59 | Unpublish | 2021-10-06 10:33:12 | | 13 | LP09642 | 59 | Draft | 2021-10-07 10:33:12 | +----+---------+----------+-----------+---------------------+ Code <?php $res = $db->prepare("SELECT agent_id as Agent , SUM(status_to = 'Draft') as Draft , SUM(status_to = 'Unpublish') as Unpublish , SUM(status_to = 'Publish') as Publish , SUM(status_to = 'Action') as Action FROM crm_log WHERE logtime BETWEEN ? AND ? GROUP BY agent_id "); $res->execute( [ '2021-10-01', '2021-10-31' ] ); $data = ''; $row = $res->fetch(); $heads = "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n"; do { $data .= "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n"; } while ($row = $res->fetch()); ?> <table border='1' style='border-collapse: collapse; width: 500px'> <?=$heads?> <?=$data?> </table> Output- 1 reply
-
- 1
-
-
- codeigniter
- mysql
-
(and 1 more)
Tagged with:
-
https://fontawesome.com/v4.7/icon/angle-left
-
Your biggest problem is the lack of closing curlies } after each style spec. As for the quotes, do them the way that works.
-
FYI If you have a div inside the 8-col td, then it works with display:block <tr > <td colspan='8'> <div class='more' id='details{$cnt}' >lorem fucking ipsum wahoo baby - {$cnt}</div> </td> </tr>
-
Instead of changing the display to "block" when you click the button, set it to "display: table-cell;" <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> function showDetails(cnt) { $(".more").css("display", "none"); // hide all var details = "details"+cnt; var x = document.getElementById(details); if (x.style.display === "none") { x.style.display = "table-cell"; // display requested one } else { x.style.display = "none"; } } </script>
-
If I put the style='display: none' back, I get Apart from that one inline style I am using no css, so something in yours could be screwing up.
-
How do you know with the display: none ? If I supply some dummy values, remove the display:none and add borders to the table so I can see what's happening... $rank = $image = $name = $final_worth = $country = $source = $cnt = $class = $last_change = 'X'; $html = " <tr class='mt-2'> <td>{$rank}.</td> <td><img src='{$image}' height='75' width='75'></td> <td>{$name}</td> <td class='bold'>\${$final_worth}B</td> <td class='{$class}'>\${$last_change}</td> <td>{$country}</td> <td>{$source}</td> <td><button class='bg-color-primary text-color-third px-2' id='more_btn' onclick='showDetails({$cnt})'>More</button></td> </tr> <tr > <td colspan='8' id='details{$cnt}' >lorem fucking ipsum wahoo baby - {$cnt}</td> </tr> "; I see
-
try changing that to <tr > <td colspan='8' id='details'>lorem fucking ipsum wahoo baby</td> </tr> If it ain't in a cell, it's rejected from the table, which is why it appears above.