PHP - Php Group Array
Hi All, I hope i'm posting in the right place but also hope someone can help! I've got the following code: <?php $variations = $product->get_available_variations(); if ($variations): ?> <div class="table-responsive"> <table class="table table-striped"> <tbody> <?php foreach ($variations as $key => $value) : ?> <tr> <td><?php echo $value['sku']; ?> <?php echo $value['variation_id']; ?></td> <?php foreach ($value['attributes'] as $attrKey => $attr) : $tax = str_replace('attribute_', '', $attrKey); $term_obj = get_term_by('slug', $attr, $tax); ?> <td><?php echo $term_obj->name; ?></td> <?php endforeach; ?> </tr> <?php endforeach; #$variations?> </tbody> </table> </div><!-- /table-responsive --> <?php endif; #$variations ?> This produces the following table: Product code System Pack Quantity Variation XT1ECWH 234 System 1 2 N/A XT2ECLWH 236 System 2 2 Left XT2ECRWH 237 System 2 2 Right XT3ECWH 238 System 3 2 N/AHowever, is it possible to alter the code to group the information? So it looks like the below? System 1 System 2 System 3 System 1XT1ECWH 234 Pack Quantity: 2 Variation: N/A System 2 XT2ECLWH 236 Pack Quantity: 2 Variation: Left XT2ECRWH 237 Pack Quantity: 2 Variation: Right System 3 Sorry, not sure why it's not formatted correctly but hopefully you can see what I'm trying to achieve. The array for $variations is as follows: Array ( [0] => Array ( [attributes] => Array ( [attribute_pa_system] => system-1 [attribute_pa_pack-quantity] => 2 [attribute_pa_variation] => n-a ) [sku] => XT1ECWH [variation_description] => [variation_id] => 234 ) [1] => Array ( [attributes] => Array ( [attribute_pa_system] => system-2 [attribute_pa_pack-quantity] => 2 [attribute_pa_variation] => left ) [sku] => XT2ECLWH [variation_description] => Left [variation_id] => 236 ) [2] => Array ( [attributes] => Array ( [attribute_pa_system] => system-2 [attribute_pa_pack-quantity] => 2 [attribute_pa_variation] => right ) [sku] => XT2ECRWH [variation_description] => Right [variation_id] => 237 ) [3] => Array ( [attributes] => Array ( [attribute_pa_system] => system-3 [attribute_pa_pack-quantity] => 2 [attribute_pa_variation] => n-a ) [price_html] => [sku] => XT3ECWH [variation_description] => ) ) If it helps, I need to always group by the first attribute, in this case : attribute_pa_system Any help on this would be very much appreciated! Thank you in advanced. Similar Tutorialshi, i'm trying to sort an array of associative arrays, based on one of the keys. if the value of the key is a primitive, normal sorting occurs - this works fine. if the value of the key is an array, i'd like to have it sorted by "groups" here's an example: Code: [Select] <?php $data[] = array('name' => 'h', 'list' => array(1,2)); $data[] = array('name' => 'g', 'list' => array(1)); $data[] = array('name' => 'a', 'list' => array(1,3)); $data[] = array('name' => 'f', 'list' => array(2)); $data[] = array('name' => 'e', 'list' => array(2,3)); $data[] = array('name' => 'b', 'list' => array(3)); $data[] = array('name' => 'c', 'list' => array(1,2,3,4)); $data[] = array('name' => 'd', 'list' => array(3,4)); function deep_sort($array, $sorton){ usort($array, function($a, $b) use($sorton) { $a = $a[$sorton]; $b = $b[$sorton]; if(is_array($a) && is_array($b)){ // this bit is obviously flawed - only included for illustrative purposes $a = implode('', $a); $b = implode('', $b); } return ($a == $b) ? 0 : ($a > $b) ? 1 : -1; }); return $array; } $sorted_by_name = deep_sort($data, 'name'); print '<pre>'; print_r($sorted_by_name); print '</pre>'; $sorted_by_list = deep_sort($data, 'list'); print '<pre>'; print_r($sorted_by_list); print '</pre>'; ?> the sorted_by_name bit is fine - but for sorted_by_list, what i want returned is all the array ordered as follows: all those with "1" (or the lowest if none have "1") in it's list value first, then all those remaining that have the next highest ("2"), etc. so right now, the returns for sort_by_list look like this: Code: [Select] Array ( [0] => Array ( [name] => g [list] => Array ( [0] => 1 ) ) [1] => Array ( [name] => f [list] => Array ( [0] => 2 ) ) [2] => Array ( [name] => b [list] => Array ( [0] => 3 ) ) [3] => Array ( [name] => h [list] => Array ( [0] => 1 [1] => 2 ) ) [4] => Array ( [name] => a [list] => Array ( [0] => 1 [1] => 3 ) ) [5] => Array ( [name] => e [list] => Array ( [0] => 2 [1] => 3 ) ) [6] => Array ( [name] => d [list] => Array ( [0] => 3 [1] => 4 ) ) [7] => Array ( [name] => c [list] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) ) )whereas i'd like to get back: Code: [Select] Array ( [0] => Array ( [name] => g [list] => Array ( [0] => 1 ) ) [1] => Array ( [name] => h [list] => Array ( [0] => 1 [1] => 2 ) ) [2] => Array ( [name] => c [list] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) ) [3] => Array ( [name] => a [list] => Array ( [0] => 1 [1] => 3 ) ) [4] => Array ( [name] => f [list] => Array ( [0] => 2 ) ) [5] => Array ( [name] => e [list] => Array ( [0] => 2 [1] => 3 ) ) [6] => Array ( [name] => b [list] => Array ( [0] => 3 ) ) [7] => Array ( [name] => d [list] => Array ( [0] => 3 [1] => 4 ) ) ) TYIA for any suggestions I have been struggling with this for awhile now, and I think it isn't as hard as I making it. Basically I want to "group" my array by month making a multidimensional array by months. Basically right now my print_r($my_array) outputs: Code: [Select] Array ( [0] => stdClass Object ( [id] => 2 [did] => 2 [dates] => 2011-06-01 [enddates] => 2011-06-01 [shortdescription] => [max_attendance] => 1 [times] => 06:30:00 [endtimes] => 07:30:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Nightclub [locid] => 2 [status] => 4 [shw_attendees] => 0 [club] => SE [url] => [street] => 615 SE Alder [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 1 [avaliable] => 0 ) [1] => stdClass Object ( [id] => 57 [did] => 57 [dates] => 2011-06-05 [enddates] => 2011-06-05 [shortdescription] => [max_attendance] => 15 [times] => 02:00:00 [endtimes] => 03:00:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Rumba [locid] => 1 [status] => 0 [shw_attendees] => 0 [club] => SW [url] => [street] => 8936 SW 17th Ave [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) [2] => stdClass Object ( [id] => 61 [did] => 61 [dates] => 2011-06-05 [enddates] => 2011-06-05 [shortdescription] => [max_attendance] => 15 [times] => 03:00:00 [endtimes] => 04:00:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Waltz [locid] => 1 [status] => 0 [shw_attendees] => 0 [club] => SW [url] => [street] => 8936 SW 17th Ave [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) [3] => stdClass Object ( [id] => 1 [did] => 1 [dates] => 2011-06-06 [enddates] => 2011-06-06 [shortdescription] => [max_attendance] => 15 [times] => 06:30:00 [endtimes] => 08:30:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Foxtrot [locid] => 2 [status] => 0 [shw_attendees] => 0 [club] => SE [url] => [street] => 615 SE Alder [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) [4] => stdClass Object ( [id] => 11 [did] => 11 [dates] => 2011-06-08 [enddates] => 2011-06-08 [shortdescription] => [max_attendance] => 15 [times] => 06:30:00 [endtimes] => 08:30:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Nightclub [locid] => 2 [status] => 0 [shw_attendees] => 0 [club] => SE [url] => [street] => 615 SE Alder [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) [5] => stdClass Object ( [id] => 15 [did] => 15 [dates] => 2011-07-04 [enddates] => 2011-07-04 [shortdescription] => [max_attendance] => 15 [times] => 06:30:00 [endtimes] => 08:30:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Rumba [locid] => 2 [status] => 0 [shw_attendees] => 0 [club] => SE [url] => [street] => 615 SE Alder [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) ) I need to take that and make it look like this, grouping by the month of the 'dates' value: Code: [Select] Array ( [0] => Array ( //June [0] => stdClass Object ( [id] => 2 [did] => 2 [dates] => 2011-06-01 [enddates] => 2011-06-01 [shortdescription] => [max_attendance] => 1 [times] => 06:30:00 [endtimes] => 07:30:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Nightclub [locid] => 2 [status] => 4 [shw_attendees] => 0 [club] => SE [url] => [street] => 615 SE Alder [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 1 [avaliable] => 0 ) [1] => stdClass Object ( [id] => 57 [did] => 57 [dates] => 2011-06-05 [enddates] => 2011-06-05 [shortdescription] => [max_attendance] => 15 [times] => 02:00:00 [endtimes] => 03:00:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Rumba [locid] => 1 [status] => 0 [shw_attendees] => 0 [club] => SW [url] => [street] => 8936 SW 17th Ave [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) [2] => stdClass Object ( [id] => 61 [did] => 61 [dates] => 2011-06-05 [enddates] => 2011-06-05 [shortdescription] => [max_attendance] => 15 [times] => 03:00:00 [endtimes] => 04:00:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Waltz [locid] => 1 [status] => 0 [shw_attendees] => 0 [club] => SW [url] => [street] => 8936 SW 17th Ave [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) [3] => stdClass Object ( [id] => 1 [did] => 1 [dates] => 2011-06-06 [enddates] => 2011-06-06 [shortdescription] => [max_attendance] => 15 [times] => 06:30:00 [endtimes] => 08:30:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Foxtrot [locid] => 2 [status] => 0 [shw_attendees] => 0 [club] => SE [url] => [street] => 615 SE Alder [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) [4] => stdClass Object ( [id] => 11 [did] => 11 [dates] => 2011-06-08 [enddates] => 2011-06-08 [shortdescription] => [max_attendance] => 15 [times] => 06:30:00 [endtimes] => 08:30:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Nightclub [locid] => 2 [status] => 0 [shw_attendees] => 0 [club] => SE [url] => [street] => 615 SE Alder [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) ) [1] => Array ( //July [0] => stdClass Object ( [id] => 15 [did] => 15 [dates] => 2011-07-04 [enddates] => 2011-07-04 [shortdescription] => [max_attendance] => 15 [times] => 06:30:00 [endtimes] => 08:30:00 [registra] => 1 [unregistra] => 0 [titel] => Beginning Rumba [locid] => 2 [status] => 0 [shw_attendees] => 0 [club] => SE [url] => [street] => 615 SE Alder [please] => [city] => Portland, OR [country] => US [locdescription] => [catname] => Adult Classes [catid] => 1 [price] => Array ( ) [registered] => 0 [avaliable] => 15 ) ) ) Hi all, I would like to ask you if somebody could have a better idea to build this function. The current one is working, but I feel this built a bit in an amateur manner. Feel free to add your ideas so we can learn more about PHP and how to deal with arrays.
I have an array: $arrayVideoSpecs = Array( Array( 'aspect' => '4:3', 'density' => '442368', 'resolution' => '768x576' ), Array( 'aspect' => '4:3', 'density' => '307200', 'resolution' => '640x480' ), Array( 'aspect' => '16:9', 'density' => '2073600', 'resolution' => '1920x1080' ), Array( 'aspect' => '16:9', 'density' => '121600', 'resolution' => '1280x720' ) );
and I want an array as output grouped by video aspect ratio where the key is the pixel density and the value is the video resolution, namely like that for aspect ratio 16:9 ... Array ( [2073600] => 1920x1080 [121600] => 1280x720 )
Then I coded this function which is working but seems amateur ... function groupAndExtractByAspect($array, $groupBy, $aspect, $density, $resolution) { $groupByAspect = Array(); foreach ($array as $value) { $groupByAspect[$value[$aspect]][] = Array($value[$density], $value[$resolution]); } $arrayClean = Array(); foreach ($groupByAspect as $key => $value) { if ($key == $groupBy) { $arrayClean[$key] = $value; } } foreach ($arrayClean as $aspectGroup) { $arrayOutput = Array(); for ($i = 0; $i <= count($aspectGroup); $i++) { $densityIsValid = false; $resolutionIsValid = false; if (!empty($arrayClean[$groupBy][$i][0])) { $density = $arrayClean[$groupBy][$i][0]; $densityIsValid = true; } if (!empty($arrayClean[$groupBy][$i][1])) { $resolution = $arrayClean[$groupBy][$i][1]; $resolutionIsValid = true; } if (($densityIsValid === true) && ($resolutionIsValid === true)) { $arrayOutput[$density] = $resolution; } } } return $arrayOutput; }
The usage is as follow ... $showArray = groupAndExtractByAspect($arrayVideoSpecs, '16:9', 'aspect', 'density', 'resolution'); echo '<pre>'; print_r($showArray); echo '</pre>';
Thank you very much for your ideas! Mapg I have it to where it groups two parts of the Array randomly but I need to make it where it won't pair the same together, or if it has already been paired with a team then use another team. Each value of the array can only be used once. Here is my code shuffle($teamname); $loopCount = $games; for ($i = 0; $i < $loopCount; $i++) { $player1 = array_pop($teamname); $player2 = array_pop($teamname); if(is_null($player1)) { echo 'Not enough different teams to create '.$games.' games'; break; } // output to screen echo "Team: " . $player1 . " Vs Team: " . $player2 . "<br />"; } } Hi All, I've a loop which creates an array as follows: $product_table[] = ['SKU' => $sku, 'Label' => $attribute_name, 'Value' => $term_obj->name ]; I'm then grouping the data by SKU code: #group the products by SKU $group_products = array(); foreach ($product_table as $element) : $group_products[$element['SKU']][] = $element; endforeach; Finally, I output the data: #output the data foreach ($group_products as $itemName => $rows) : echo '<tr>'; #echo '<td>', $element['SKU'], '</td>'; $i=0; foreach ($rows as $row) : $i++; #echo '<td>'. $row["SKU"]. '</td><td>'. $row["Label"]. '</td><td>'. $row["Value"]. '</td>'; if ($i == 1): echo '<td>'. $row["SKU"]. '</td><td>'. $row["Value"]. '</td>'; else: echo '<td>'. $row["Value"]. '</td>'; endif; #echo '<td>'. $row["Value"]. '</td>'; endforeach; echo '</tr>'; endforeach; ?> And looks like: Product code System Pack Quantity XT1CWH System 1 1 x 3m XT2CWH System 2 1 x 3m XT3CWH System 3 1 x 3m
This works perfectly fine. However, some products share the same SKU and therefore it causes an issue, like the below: Product code System Pack Quantity XT1CLWH System 1 8 x 3m System 2 8 x 3m System 3 8 x 3m Is there a way I can avoid this, so if perhaps creates the new row but shows the same SKU code? Many thanks I have an array that looks like this:
array(5642) { [0]=> string(19) "2021-02-10 09:04:48" [1]=> string(19) "2021-02-10 09:04:54" [2]=> string(19) "2021-02-10 09:05:00" [3]=> string(19) "2021-02-10 09:05:06" [4]=> string(19) "2021-02-10 09:05:12" [5]=> string(19) "2021-02-10 09:05:18" [6]=> string(19) "2021-02-10 09:06:18" [7]=> string(19) "2021-02-10 09:06:24" }
I need to group the instances any time there is more than a 6 second gap between elements. So 0 =>5 would be one array and 6 and 7 would be a new array.
Ive been able to produce the following but its not ideal
array(5642) { [0]=> string(19) "2021-02-10 09:04:48" [1]=> string(19) "2021-02-10 09:04:54" [2]=> string(19) "2021-02-10 09:05:00" [3]=> string(19) "2021-02-10 09:05:06" [4]=> string(19) "2021-02-10 09:05:12" [5]=> string(19) "2021-02-10 09:05:18" [6]=> string(19) "end" [7]=> string(19) "2021-02-10 09:06:18" [8]=> string(19) "2021-02-10 09:06:24" }
$burner_time = array(); foreach($Burner_Control_Alm as $new_burner){ $burner_time[] = strtotime($new_burner); } $repl = 'end'; for ($i=1; $i<count($burner_time); $i++) { $value_second = $burner_time[$i]; $value_first = $burner_time[$i-1] === $repl ? $burner_time[$i-2] : $burner_time[$i-1]; if ($value_second > $value_first + 6) { array_splice($burner_time, $i++, 0, $repl); } print_r($burner_time); } Hi, I have database, screenshot attached. I have to print all records of attendance sort by ID and have sum group by ID. How to know or figure out when the ID changes so that i can show the total for that ID. Bare with me please and try to show me where is my mistake! Code: <?Php include('session.php'); include('dbcon.php'); ?> <html> <head> <link rel="stylesheet" type="text/css" href="bootstrap.css"> </head> <body> <div class="container"> <div class="row"> <div class="col m-auto"> <div class="card mt-5"> <table class="table table-bordered"> <tr> <input type="button" onClick="window.print()" value="Print The Report"/> <td>OracleID</td> <td>Name</td> <td>Designation</td> <td>Clocking In Time</td> <td>Clocking Out Time</td> <td>Duration</td> </tr> <?php $isdone = -1; $query = "select * from attendance_records where isdone= '".$isdone."' order by OracleID"; $result = mysqli_query($con, $query); $query2 = "SELECT sec_to_time(SUM(timestampdiff(SECOND, ClockingInDate, ClockingOutDate))) as total from attendance_records group by OracleID"; $result2 = mysqli_query($con, $query2); while ($row = mysqli_fetch_assoc($result)) { $userid = $row['OracleID']; $name = $row['Name']; $des = $row['Des']; $clockingindate = $row['ClockingInDate']; $clockingoutdate = $row['ClockingOutDate']; $duration = $row['Duration']; $t=time(); $curdate = date("d-m-Y",$t); $curTime = date("g:i:s A",$t); ?> <tr> <td><?php echo $userid ?></td> <td><?php echo $name ?></td> <td><?php echo $des ?></td> <td><?php echo $clockingindate ?></td> <td><?php echo $clockingoutdate ?></td> <td><?php echo $duration ?></td> </tr> <?php } while($row2 = mysqli_fetch_assoc($result2)) { $totals= $row2['total']; echo '<td><h5>Total Attendance Time:</h5></td>'; echo '<td>'; echo $totals; echo '</td>'; } echo '<tr>'; echo 'Report created by ', $_SESSION['user_id2'], ' on ', $curdate, ' at ', $curTime; echo '</tr>'; ?> </table> <a href="home.php" width="100%">Click here to go back to Main Menu</a> </div> </div> </div> </div> </body> </html> and screenshot of result is attached. I have the totals but not at the end of each OracleID, it is at the end of the report. Thanks.
I am trying to get a group by to work but for some reason it will only display one output. Not sure what the problem is. Code: [Select] mpid mpyear mpmonth mpday mptitle 4 2012 3 2 Text stuff here 3 2012 3 1 Day 1 stuff here 2 2012 2 28 Feb stuff here 1 2011 12 27 First post test here So what I am trying to do is sort out per year month ie: 2012 3 Text stuff here Day 1 stuff here 2 Feb stuff here 2011 12 First post test here That is what I eventually want it to look like, but first thing I need to do is get atleast the mptitle to group first. Code: [Select] $query = "SELECT * FROM monsterpost group BY 'mpmonth'"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo $row['mptitle']; echo "<br />"; } ?> Hi all, does anyone know how to perform this, or if it's even possible? I need every 6th row to be a GROUP BY of the following 5 rows, they all share a common group_id so that's what the GROUP BY is performed on. 1. GROUP BY group_id 2. item #1 3. item #2 4. item #3 5. item #4 6. item #5 7. GROUP BY group_id 8. item #6 ... and so on Hi, Cut down code SELECT count(number) FROM table GROUP BY title echo $title .'<br>'. $number; That outputs Code: [Select] Title1 5 Title2 9 Title3 2 But what do i do if i wanted to retain and loop through the "$number" actual values, not JUST count the total? I still need access to what "$number" is while looping. But as GROUP BY returns one result.. im stuck. Ideally i want this as the resulting output Code: [Select] title1 // grouped title 3 // total number of $numbers per grouped title 1234 12345 123456 // The actual values of $number totalling to the above grouped number title2 // grouped title 2 // total number of $numbers 1234 123456 // The actual values of $number totalling to the above grouped number Hi
I am reading in data from a csv file
if (($handle = fopen("data.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { echo "User Name: $data[0]"; echo "Booking IDs: $data[1]"; } echo "<hr>";The problem is some of the usernames are duplicated so get outputted the same user name 20 times but with different IDs, obviously but I am unsure how to group them together. I can't seem to figure out how to write if the next username is the same as current then just add another ID not go through the entire loop. Any ideas? Thanks G'day to all, I need some help building a site that has the ability to accept members and deposit those members in a database. When the members join they will have the ability to add features to their profile; like, skills and certificates. Upload pictures of certificates and a profile pic. The admin area needs to have the ability to add membership types and give those members specific abilities. The admin also needs to have the ability to create profile options, like additional skills. Like a type 1 member has the ability search and see all type 2 members who have a particular skill set. type 2 members just get to see their own profile and the tasks the type 1 members list.
This all might sound like a bunch of brambles but please let me know if you are interested and we can get more involved. Thank you so very much for your help in advanced... Juan This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306114.0 Hi all, I have a script that is essentially a log file of all preious versions of an article (versioning) You can see the script I am talking about in action at: http://danielrhyshardy.com/AWT/forumadmin.php What I would like to do is, instead of displaying the title of each instance (you will see there are two instances named "apple", as they are two previous versions of an article), I would like to display that title once, and then all of the instances of that title be displayed below. I hope that makes sense. Here is the code Code: [Select] <? $sql = "SELECT id,title,message,date_added FROM messages2 ORDER BY id "; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); while(list($id,$title,$message,$date_added)=mysql_fetch_row($result)){ echo '<div style="color:#bb0000;width:250px;text-align:center;float:left;margin-left:15px;margin-bottom:15px;padding-bottom:20px;"><b>'.$title.'<br>'.$date_added.'</b> <input id="'.$message.'" type="radio" name="admin[]" value="'.$id.'" onclick="javascript:document.form22.car.value=this.id" > </font></div>'."\n"; } ?> I would use something like Code: [Select] if ($title = "apple") { but this would obviously not work for new posts, unless I wanted to constantly update my code. I am sure there is a simple way to achieve this. Perhaps someone can tell me!? Thanks in advance Dan Hi Just a quick one. I want my output result to look like this. In its simplistic form I have 2 columns, NAME and NUMBER. Adam 1 2 3 Becky 1 2 3 Charlie 1 2 3 So the output results are grouped by the "name" field, then ordered by the "number" field. I thought it was GROUP BY, but that function is something else. Iv tried searching around but im unsure what you call this form of grouping results. Many Thanks! I have a table that has pairs of matching records that are identified as matching on a specific column. In other words, 2 users submit data on the same record, and they are identified as matching and belonging to the same record data because the table column gameid is the same for the pair. How can I output the information for the pair of matching records for each of these into a table repeating it until Ive looped through all records? In other words I want to create 1 table with headers for each matching pair all the way down... thanks in advance. im trying to pull the information for a post which is to include 3 db tables(posts, users, attachments) Ive tried the following code: Code: [Select] $query = $link->query("SELECT p.*, u.u_username, u.u_posts, u.u_avatar, u.u_signature, u.u_avatar_cropped, group_concat(a.a_name, a.a_size, a.a_date_posted separator '<br />') attachments FROM ".TBL_PREFIX."posts as p JOIN ".TBL_PREFIX."users as u ON (u.u_username = p.p_poster) LEFT JOIN ".TBL_PREFIX."post_attachments as a USING (".TBL_PREFIX."posts.p_pid) WHERE p.p_tid = '$tid' GROUP BY p.p_pid ORDER BY p.p_time_posted ASC")or die(print_link_error()); but that generates the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.p_pid) WHERE p.p_tid = '158' GROUP BY p.p_pid ORDER BY p.p_time_pos' at line 10" All i am trying to do is pull everything from posts, join users and select all attachments that belong to the post. Here is my database setup(shortened) asf_posts p_pid | p_name | p_poster 1 test doddsey65 asf_users u_uid | u_username 1 doddsey65 asf_attachments a_aid | a_pid | a_name 1 1 name can anyone help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353968.0 I am working on a site, on a shipping profile module that requires users to group the countries into regions to ship the items to. That is: Region 1 - Japan, USA, Spain, Italy. Region 2 - Belgium, France, Germany. I have a table that has all the Country names which will be populated in a Listbox control for users to select. Once the supplier has selected a group of countries from the Listbox, how can I properly save it into the database with its region name. Do I save multiple county IDs with comma or whats the right way. Please advise. The question maybe basic but I need your feedback. Thank you! |