Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. You need to append [] to the select name so the choices are posted as an array <select multiple name='Status[]' id='Status'>
  2. Your query is duplicating information. The counts from the subqueries are the same in every row. The count from the browser XXX subquery is always the same as the total count in the XXX row so you would get as much information by omitting the subqueries altogether.
  3. Running both methods 100 times gave me STRPOS: 0.002000 sec REGEX : 0.004000 sec
  4. You should read the manual for substr() $version = substr($page, $posStart, $posStop-$posStart);
  5. Having just Googled "PDO rowCount" there appears to be issues on unbuffered result sets always returning a zero count. It certainly worked ok with mysqli $mysqli = new mysqli(HOST,USERNAME,PASSWORD,'test'); $plate = isset($_GET['plate']) ? $_GET['plate'] : ''; $sql = "SELECT * FROM vehicles WHERE platenumber = ?"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('s', $plate); $stmt->execute(); $res = $stmt->get_result(); if ($res->num_rows) { $row = $res->fetch_row(); echo $row[0] . ' | ' . $row[1]; } else echo "No results"; ?> <html> <head> <style type='text/css'> td {text-align: center;} </style> </head> <body> <form> Plate <input type='text' name='plate' value=''> <input type='submit' name='btnSub' value='Submit'> </form> </body> </html>
  6. The question that immediately springs to mind is "Why the hell would anyone do that?"
  7. With a few test records mysql> SELECT * FROM browsers; +----+---------+-----------------+---------+ | id | browser | ip | country | +----+---------+-----------------+---------+ | 1 | Chrome | 123.123.123.123 | UK | | 2 | Chrome | 123.123.124.124 | UK | | 3 | Chrome | 123.123.123.125 | USA | | 4 | Firefox | 12.12.12.12 | FRA | | 5 | Safari | 23.23.23.23 | UK | | 6 | Safari | 25.25.25.25 | USA | +----+---------+-----------------+---------+ Your query gave me
  8. See http://forums.phpfreaks.com/topic/292890-invalid-selection/?do=findComment&comment=1498515
  9. I can attest to that
  10. Alex, There is <input type='image'> which will submit the form when clicked, and also pass the x.y coordinates of where the image was clicked
  11. If your arrays and options are always sorted in the same order function test($map,$array1) { $value=false; foreach($map as $elem) { if($array1 == $elem['options']) { $value=$elem['name']; break; } } return $value; }
  12. If all you want is a row count then selecting all the records and counting them is the inefficient way to do it. You should use SELECT COUNT(*) as count FROM mxit Then look at value returned in $row['count']
  13. Yes - Step 1 = get array "c" for unique combinations of a and b while (list($a, $b, $c) = $result->fetch_row()) { $data[$a][$b][] = $c; } // STEP 2 foreach ($data as $a => $adata) { foreach ($adata as $b => $c) { $result[] = array('a' => $a, 'b' => $b, 'c' => $c); } }
  14. while (list($a, $b, $c) = $result->fetch_row()) { $data[$a][$b][] = $c; }
  15. Perhaps this in euser.php $sql = "SELECT id, username FROM $tbl_name ORDER BY username"; $result = $con->query($sql); echo "<table cellpadding='5'>"; while ($row = $result->fetch_assoc()) { echo "<tr><td>{$row['username']}</td> <td><a href='editUser.php?id={$row['id']}'>Edit User</a></td> <td><a href='changepassword.php?id={$row['id']}'>Change Password</a></td> <td><a href='banUser.php?id={$row['id']}'>Ban User</a></td> </tr>\n"; } echo "</table>\n";
  16. There is if you design your tables correctly and don't just throw different bits of data together into a single field. As a workaround for now you could try ... GROUP BY SUBSTRING_INDEX(clid, '+', 1)
  17. Define you styles once in the <head>..</head> section of your page, not every time you output something to the page. eg <html> <head> <style> a { color: blue; text-decoration: none; } a:hover { color: #ff0000; } body { background-color: #000; } </style> </head> or put the styles in an external .css file. Having linked to "edituser.php?id=1" passing the id of the selected user, why would you then run a query to get the ids of all the users again? Get the details of the selected user for editing (ie. change password, set a flag to ban them etc.)
  18. Total count for each client SELECT clid, COUNT(*) as tot FROM tablename GROUP BY clid Total count each day for each client SELECT clid, date, COUNT(*) as tot FROM tablename GROUP BY clid, date
  19. IF they are consistent, yes. I'd advise running SELECT DISTINCT category FROM book WHERE ABS(category) = 0 ORDER BY category and checking the list before going ahead
  20. Bite the bullet and clean up your data. Create categories in the category table for those that are not already there (such as Classic Kids) and store category id in the book table. I know this this may be as easy as it sounds. I once did a similar data migration exercise where a company department had been storing supplier invoice details in a home-built Access database. One of the data fields was the company name. Some companies had hundreds of invoices stored and it was rare to find every record for a company having exactly the same spelling of the name. Some had half a dozen variations of the same name. And that is a reason NOT to store names but to use the ids.
  21. As you want to output income and expenditure totals then those might be good totals to store, don't you think? Something like this $mysqli = new mysqli(HOST,USERNAME,PASSWORD,'test'); $inSql = "SELECT , YEAR(si.date_invoiced) as year , MONTH(si.date_invoiced) AS month , SUM(li.sub_total) AS total , SUM(li.tax_amount) AS total_tax FROM sales_invoice si INNER JOIN sales_invoice_line_items li ON si.invoice_id = li.invoice_id GROUP BY year, month"; $exSql = "SELECT , YEAR(pi.date_invoiced) AS year , MONTH(pi.date_invoiced) AS month , SUM(li.sub_total) AS total , SUM(li.tax_amount) AS total_tax FROM purchase_invoice pi INNER JOIN purchase_invoice_line_items li ON pi.invoice_id = li.invoice_id GROUP BY year, month"; $data = array(); // GET INCOME TOTALS $res = $db->query($inSql); while (list($y, $m, $tot, $tax) = $res->fetch_row()) { if ($m < 4) $y--; // jan, feb, mar belong in previous year $m = ($m + % 12; // adjust month number $data[$m][$y]['i'] += $tot - $tax; } // GET EXPEND TOTALS $res = $db->query($exSql); while (list($y, $m, $tot, $tax) = $res->fetch_row()) { if ($m < 4) $y--; // jan, feb, mar belong in previous year $m = ($m + % 12; // adjust month number $data[$m][$y]['x'] += $tot - $tax; } // LOOP THROUGH DATA ARRAY AND OUTPUT TOTALS $mnames = array('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); $totals = array(); foreach ($data as $m => $mdata) { echo "<tr><td>{$mnames[$m]}</td>"; foreach ($mdata as $y => $ydata) { echo "<td>{$ydata[i]}</td><td>{$ydata[x]}</td>"; $totals[$y]['i'] += $ydata['i']; $totals[$y]['x'] += $ydata['x']; } echo "</tr>\n"; } // echo total row here from $totals array
  22. What are you trying to do? If you are trying to change the appearance of alternate rows then a. The value of $nr_row needs to change b. It needs to change within your loop
  23. Look up the category_id in your category table if a name is entered instead of an id. SELECT category_id FROM category WHERE cat_name = '$googleCategory'
  24. http://phpsecurity.org/code/ch02-5
  25. Don't double post ! This has already been answered in the MySQL forum.
×
×
  • 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.