-
Posts
24,572 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
Trying to get a several rows and colums with data.
Barand replied to rvdveen27's topic in MySQL Help
Your output sample shows a driver name but in your table the driver column is INT. Where is the name coming from? Also, why are the value columns (price, cargodamage,costs) that you are adding defined as VARCHAR ? -
All you ever stated was that have a table1. My "result" table corresponds to your Table1 AccessDate__UserCode__AnalisisName____AnalisisResult 2012-01-01____1____________a1______________10 2012-01-01____1____________a2______________15 2012-01-01____1____________a3______________12 that contains 2.5 million records The only one you need to change is in the FROM clause FROM result although you will need to misspell "analisiname" and "analisisresult" too
-
One way to speed up your search if you use a database is to store the word with its "word root" (ie the letters in the word sorted into alphabetic order). All anagrams have the same root. For example, if you have found EAST you can quickly find others word | root -----+------ east | aest eats | aest seat | aest sate | aest tase | aest
- 4 replies
-
- php
- preg_match
-
(and 3 more)
Tagged with:
-
???
-
Trying to get a several rows and colums with data.
Barand replied to rvdveen27's topic in MySQL Help
Where is $row['id'] supposed to come from? There are two separate aggregation queries on same table - what does the "id" relate to (identify) in the second? What is your table structure? -
Copy all records with 2 equals data from table1 to one record in table2
Barand replied to paolo123's topic in MySQL Help
Don't double-post your questions, it wastes our time. See my answer in the other post you made on this. -
Does this help? SELECT User , COUNT(*) as `Count` , GROUP_CONCAT(accessdate,' (',result,')' ORDER BY accessdate SEPARATOR ' , ') as Dates FROM ( SELECT accessdate , @N:=IF((usercode<>@prevuser) OR (@prevres < 10) OR (analysisresult < 10), 1, @N+1) as seqcount , @startdate := IF(@N=1 , accessdate, @startdate) as startdate , @prevres:=analysisresult as result , @prevuser:=usercode as user FROM result JOIN ( SELECT @N:=0, @startdate:=NULL, @prevres:=NULL, @prevuser:=NULL ) as init WHERE analysisname = 'a1' ORDER BY usercode, accessdate ) as detail GROUP BY user,startdate HAVING `Count` >= 5; (Takes around 25 secs on my laptop with the 2.55 million record table I saved from your last topic)
-
"=" is an assignment operator "==" is an equality test
-
Are you sure?
-
Echo out results comma and apostrophe delimited
Barand replied to solidrocketfuel's topic in PHP Coding Help
Store the things you want to join in the array $sql = 'SELECT video_code FROM yt_videos WHERE yt_video_item_id="'.$vidid.'" ORDER BY RAND() LIMIT 10'; $result=mysqli_query($db_conx,$sql); $codes = array(); while ($row = mysqli_fetch_assoc($result)) { $codes[] = $row['video_code']; // add code to the array } // now join the array of codes echo '"' . join('","', $codes) . '"'; -
Insert checkbox into database and the select checked ones!
Barand replied to zazu's topic in PHP Coding Help
So, having normalized your data you will have a table (eg age) to define the age ranges and table (eg children) to store the checkbox values each use chose. age children +-------+-----------------+ +------+-------------+----------+ | id | age_range | | id | user_id | age_id | +-------+-----------------+ +------+-------------+----------+ | 1 | 1-2 years | | 1 | 1 | 2 | | 2 | 2-4 years | | 2 | 1 | 4 | | 4 | 4-6 years | | 3 | 2 | 1 | | 4 | 2 | 2 | | 5 | 3 | 1 | You use these tables to create the checkboxes for the user, so running this query (for user 1) SELECT a.id ,a.age_range ,c.id as checked FROM age a LEFT JOIN children c ON a.id = c.age_id AND c.user_id = 1 ORDER BY a.id Which will give id | age_range | checked -------+-------------+---------- 1 | 1-2 years | NULL 2 | 2-4 years | 2 4 | 4-6 years | 4 Loop through these results creating the checkboxes. "id" will be the checkbox value and "age_range" will be the label. If "checked" has value then the checkbox should be checked- 11 replies
-
- html checkbox
- checkbox
-
(and 1 more)
Tagged with:
-
I do not see session_start() at top of login.php
-
that's what the examples in the manual are for
-
Echo out results comma and apostrophe delimited
Barand replied to solidrocketfuel's topic in PHP Coding Help
If you have an array, say $arr = [12345,23456,56789]; then using join echo '"' . join('","', $arr) . '"'; gives "12345","23456","56789" -
Echo out results comma and apostrophe delimited
Barand replied to solidrocketfuel's topic in PHP Coding Help
Store them in an array then join() the array elements echo join(', ', $theArray) -
session_register("password"); // don't use session_register - deprecated $_SESSION["authorized"] = true; // do it this way instead And every page using sessions must call session_start() at the top of the page
-
if (empty($datatoencode1)) echo "<img src='default.png'>"; else echo "<img src='code128b-1.php?D=$datatoencode1'>";
-
Trying to get a several rows and colums with data.
Barand replied to rvdveen27's topic in MySQL Help
try SELECT driver , COUNT(id) as deliveries , SUM(distance) as totaldistance , SUM(price) as totalprice FROM `drive_routes` GROUP BY driver -
Reading your post it seems as though an owner can register one or more horses a horse can enter one or more types of event So your table structure would be owner +----------+-------------------+ | owner_id | owner_name | +----------+-------------------+ | 101 | Roy Rogers | | 102 | Lone Ranger | +----------+-------------------+ | | +-----------+ | horse | event +----------+----------+-------------------+ +---------+------------+ | owner_id | horse_id | horse_name | | type | name | +----------+----------+-------------------+ +---------+------------+ | 101 | 1 | Trigger | | 1 | Barrel | | 102 | 2 | Silver | | 2 | Roping | | 102 | 3 | Flicka | +---------+------------+ +----------+----------+-------------------+ | | | | | +----------+ +----------------+ | | entry | | +----------+----------+--------+ | id | horse_id | event | +----------+----------+--------+ | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 1 | | 4 | 3 | 2 | +----------+----------+--------+ So the processing for the form would be as follows Check if owner id is stored in session If notAdd record to the owner table Get id of new owner using mysqli_insert_id() store in session Add horse to horse table using owner id Get id of new horse Add record/s to entry table using horse id NOTE: mysql_ functions are deprecated and you should be using mysqli or PDO functions
-
calculate the price came from Json file and Array
Barand replied to tonton's topic in PHP Coding Help
You don't need to loop twice echo '<pre>'; $data = json_decode($datajs, 1); // decode as an array $amountAll = 0; foreach ($data['products'] as $product) { $totalPrice = $product['price']; //get product price foreach ($product['tax'] as $tax) { $totalPrice += $tax['price']; //add in the tax } printf('%-12s %5d x %8.2f<br>', $product['description'], $product['quantity'], $totalPrice); $amountAll += $product['quantity'] * $totalPrice; } printf('%-12s %5s %8.2f<br>', '','Total', $amountAll); echo '</pre>'; gives chocolat 1 x 5.00 bonbon 1 x 8.00 gateaux 1 x 5.00 Total 18.00 -
Here's the mysqli version (assuming your connection variable is "$mysqli" $sql = "INSERT INTO users (username, password) VALUES (?, ?)"; // use placeholders $stmt = $mysqli->prepare($sql); // create prepared statement $stmt->bind_param("ss", $username, $password); // bind STATEMENT parameter $stmt->execute(); // execute the statement edit: Beat to the post by jcbones!
-
Make it a function and pass it the group array function CNList($arr) { $list=''; foreach ($arr as $group) { $items = explode(',', $group); foreach($items as $element) { list($key, $value) = explode('=', $element); if ($key=='CN') { $list .= "$value<br>"; break; } } } return $list; } echo CNList($groupArray);
-
try $groupArray = array ( 0 => 'CN=testnamehere,OU=Groups,OU=Employees,OU=UserAccounts,DC=contoso,DC=com', 1 => 'CN=heresanother,OU=Distribution Lists,DC=contoso,DC=com', 2 => 'CN=VPN,OU=_UserGroups,DC=contoso,DC=com', 3 => 'CN=ManicMondayDL,OU=_UserGroups,DC=contoso,DC=com' ); foreach ($groupArray as $group) { $items = explode(',', $group); foreach($items as $element) { list($key, $value) = explode('=', $element); if ($key=='CN') { echo "$value<br>"; } } }
-
For those of us not sat on a network with active directory, the content of $groupArray would be an immense help to us. Can you post the output from var_export($groupArray);
-
Alternative approach The data mysql> SELECT * FROM clock; +----+-------+-----------+------------+----------+ | id | empid | name | dated | datet | +----+-------+-----------+------------+----------+ | 1 | 37 | Employee1 | 2015-05-04 | 08:20:00 | | 2 | 37 | Employee1 | 2015-05-05 | 13:00:00 | | 3 | 39 | Employee2 | 2015-05-04 | 12:00:00 | | 4 | 37 | Employee1 | 2015-05-05 | 16:30:00 | | 5 | 39 | Employee2 | 2015-05-05 | 18:00:00 | | 6 | 37 | Employee1 | 2015-05-05 | 08:00:00 | | 7 | 37 | Employee1 | 2015-05-04 | 17:00:00 | | 8 | 39 | Employee2 | 2015-05-04 | 08:00:00 | | 9 | 37 | Employee1 | 2015-05-04 | 13:30:00 | | 10 | 39 | Employee2 | 2015-05-04 | 13:00:00 | | 11 | 37 | Employee1 | 2015-05-04 | 12:30:00 | | 12 | 39 | Employee2 | 2015-05-04 | 17:00:00 | | 13 | 39 | Employee2 | 2015-05-05 | 07:30:00 | | 14 | 39 | Employee2 | 2015-05-05 | 11:30:00 | | 15 | 39 | Employee2 | 2015-05-05 | 12:45:00 | | 16 | 37 | Employee1 | 2015-05-05 | 12:15:00 | | 17 | 40 | Employee3 | 2015-05-04 | 08:00:00 | | 18 | 40 | Employee3 | 2015-05-04 | 13:30:00 | | 19 | 40 | Employee3 | 2015-05-05 | 09:00:00 | | 20 | 40 | Employee3 | 2015-05-05 | 14:00:00 | +----+-------+-----------+------------+----------+ The query SELECT name as Name , dated as Date , MAX(t1) as `In` , MAX(t2) as `Out` , MAX(t3) as `BackIn` , MAX(t4) as `Leave` FROM ( SELECT @N := IF(name=@name AND dated=@dated,@N+1,0) ,IF(@N=0, datet, '') as t1 ,IF(@N=1, datet, '') as t2 ,IF(@N=2, datet, '') as t3 ,IF(@N=3, datet, '') as t4 ,@name:=name as name ,@dated:=dated as dated FROM clock JOIN (SELECT @N:=NULL,@name:=NULL,@dated:=NULL) as init ORDER BY name, dated, datet ) as times GROUP BY name, date; Output +-----------+------------+----------+----------+----------+----------+ | Name | Date | In | Out | BackIn | Leave | +-----------+------------+----------+----------+----------+----------+ | Employee1 | 2015-05-04 | 08:20:00 | 12:30:00 | 13:30:00 | 17:00:00 | | Employee1 | 2015-05-05 | 08:00:00 | 12:15:00 | 13:00:00 | 16:30:00 | | Employee2 | 2015-05-04 | 08:00:00 | 12:00:00 | 13:00:00 | 17:00:00 | | Employee2 | 2015-05-05 | 07:30:00 | 11:30:00 | 12:45:00 | 18:00:00 | | Employee3 | 2015-05-04 | 08:00:00 | 13:30:00 | | | | Employee3 | 2015-05-05 | 09:00:00 | 14:00:00 | | | +-----------+------------+----------+----------+----------+----------+