PHP - Sql > Php > Table With Grouped Totals.
Currently we have a Microsoft Access database which we use to display a report, we are rolling over to PHP/SQL online for greater control e.t.c.
So far we have the report pulling all the information from the database however we need to group this information by Day followed by Employee, sorted by time and then totaled for each Employee for each day. Below is the code we have so far which only prints columns how do we go about displaying it like the access screenshot. Attached is an example of the Microsoft Access report we have. Code: [Select] <?php $username='admin'; $password='password'; $database='planner'; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM reservations ORDER BY start_date, machid, starttime"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <?php $i=0; while ($i < $num) { $f0=mysql_result($result,$i,"machid"); $f1=mysql_result($result,$i,"start_date"); $f2=mysql_result($result,$i,"end_date"); $f3=mysql_result($result,$i,"starttime"); $f4=mysql_result($result,$i,"endtime"); $f5=mysql_result($result,$i,"first_name"); $f6=mysql_result($result,$i,"last_name"); $f7=mysql_result($result,$i,"company"); $f8=mysql_result($result,$i,"phone_number"); $f9=mysql_result($result,$i,"site_address"); $f10=mysql_result($result,$i,"site_suburb"); $f11=mysql_result($result,$i,"site_postcode"); $f12=mysql_result($result,$i,"postal_address"); $f13=mysql_result($result,$i,"postal_suburb"); $f14=mysql_result($result,$i,"postal_postcode"); $f15=mysql_result($result,$i,"job_type"); $f16=mysql_result($result,$i,"payment_type"); $f17=mysql_result($result,$i,"payment_status"); $f18=mysql_result($result,$i,"quote_outcome"); $f19=mysql_result($result,$i,"quote_amount"); $f20=mysql_result($result,$i,"quote_employee"); $f21=mysql_result($result,$i,"job_income"); $f22=mysql_result($result,$i,"job_materials"); $f23=mysql_result($result,$i,"invoice_number"); $f24=mysql_result($result,$i,"job_notes"); /* START TIME */ $stime = $f3; $shour = floor($stime/60); $smin = str_pad($stime % 60,2,0,STR_PAD_LEFT); //echo $hour.':'.$min; //echo '<br><br>'; // For AM/PM $shalf = 'am'; if( $shour > 12 ) { $shalf = 'pm'; $shour -= 12; } $stime = $shour.':'.$smin.' '.$shalf; /* END TIME */ $etime = $f4; $ehour = floor($etime/60); $emin = str_pad($etime % 60,2,0,STR_PAD_LEFT); //echo $hour.':'.$min; //echo '<br><br>'; // For AM/PM $ehalf = 'am'; if( $ehour > 12 ) { $ehalf = 'pm'; $ehour -= 12; } $etime = $ehour.':'.$emin.' '.$ehalf; ?> <table width="3500px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="125px"><?php echo $f0; ?></td> <td width="80px"><?php echo date('d-m-y', "$f1"); ?></td> <td width="50px" style="text-align:right;"><?php echo $stime; ?></td> <td width="50px" style="text-align:right; padding-right:20px;"><?php echo $etime; ?></td> <td width="100px"><?php echo $f5; ?></td> <td width="100px"><?php echo $f6; ?></td> <td width="100px"><?php echo $f7; ?></td> <td width="100px"><?php echo $f8; ?></td> <td width="100px"><?php echo $f9; ?></td> <td width="100px"><?php echo $f10; ?></td> <td width="100px"><?php echo $f11; ?></td> <td width="100px"><?php echo $f12; ?></td> <td width="100px"><?php echo $f13; ?></td> <td width="100px"><?php echo $f14; ?></td> <td width="100px"><?php echo $f15; ?></td> <td width="100px"><?php echo $f16; ?></td> <td width="100px"><?php echo $f17; ?></td> <td width="100px"><?php echo $f18; ?></td> <td width="100px"><?php echo $f19; ?></td> <td width="100px"><?php echo $f20; ?></td> <td width="100px"><?php echo $f21; ?></td> <td width="100px"><?php echo $f22; ?></td> <td width="100px"><?php echo $f23; ?></td> <td width="100px"><?php echo $f24; ?></td> <?php $i++; } ?> Once again thanks everyone at phpfreaks! Similar TutorialsOk, I am running a baseball site and we have our player stats all in a table within a database. What I have is something like this, http://www.stlbleague.com/tm.php?tid=7... Now what I would like to do is have a row at the end of the pitching and hitting stats that says "Team Totals", here is a sample code that I have pulling the pitching stats: Code: [Select] $id = $_GET['tid']; // get var from URL /* Get data. */ $sql = "SELECT player, pos, era, w, l, sv, hold, ip, bb, k, cg, sho, whip, k9 FROM 2012pitching LEFT JOIN roster ON 2012pitching.id=roster.id WHERE tid='$id'"; $result = mysql_query($sql); ?> <table width="962" border="0" cellpadding="2" cellspacing="1" class="stats2"> <tr class='theader'> <td align='center'>PLAYER</td> <td align='center'>POS</td> <td align='center'>ERA</td> <td align='center'>W</td> <td align='center'>L</td> <td align='center'>SV</td> <td align='center'>HOLD</td> <td align='center'>IP</td> <td align='center'>BB</td> <td align='center'>K</td> <td align='center'>CG</td> <td align='center'>SHO</td> <td align='center'>WHIP</td> <td align='center'>K/9</td> </tr> <?php $alternate = "2"; while ($row = mysql_fetch_array($result)) { $field1 = $row["player"]; $field2 = $row["pos"]; $field3 = $row["era"]; $field4 = $row["w"]; $field5 = $row["l"]; $field6 = $row["sv"]; $field7 = $row["hold"]; $field8 = $row["ip"]; $field9 = $row["bb"]; $field10 = $row["k"]; $field11 = $row["cg"]; $field12 = $row["sho"]; $field13 = $row["whip"]; $field14 = $row["k9"]; if ($alternate == "1") { $color = "#ffffff"; $alternate = "2"; } else { $color = "#E4E4E4"; $alternate = "1"; } echo "<tr bgcolor=$color><td>$field1</td><td align='center'>$field2</td><td align='center'>$field3</td><td align='center'>$field4</td><td align='center'>$field5</td><td align='center'>$field6</td><td align='center'>$field7</td><td align='center'>$field8</td><td align='center'>$field9</td><td align='center'>$field10</td><td align='center'>$field11</td><td align='center'>$field12</td><td align='center'>$field13</td><td align='center'>$field14</td></tr>"; } echo "</table>"; ?> So how could I use the Team ID associated with every player that it is pulling from to add a totals row? Thanks again in advance, Bobby Here is my database: receipt_id | item_id | something_here 21 1 2 29 1 10 30 1 3 31 2 9 What i would like to do is display the above data from my database in a table looking like this: receipt_id | item_id | total_something_here 21 1 15 31 2 9 in short, i want to show only different item_id with the sum of something_here field for all records where item_id is the same ie 10 + 3 + 2 = 15 in the above example please help me right now it displays the first column of the array as a header for each foreach loop then i've got the data displayed under each header and it has 4 columns or a number of my choosing with data displayed under the Table Headings. I am trying to make it display 4 or so columns but with the each group having a certain number of grouped table (data/header) in each column. a different amount for each column that i can choose IF Possible i'd like the choice of being able to remove the headers eg. Z when there is no data in them. This is an example of how it is being displayed right now Any Help would be greatly appreciated Quote A Airlie Beach Andergrove Alexandra Armstrong Beach Alligator Creek B Bucasia Blacks Beach Beaconsfield Bakers Creek Balberra Bloomsbury Breadalbane Ball Bay Belmunda C Cannonvale Calen Crystal Brook Cremorne Chelona Campwin Beach Cape Hillsborough Conway Heres The Code i have so far. Code: [Select] <?php $file = "widget.csv"; @$fp = fopen($file, "r") or die("Could not open file for reading"); $outputArray = array(); $count = 0; while(($shop = fgetcsv($fp, 1000, ",")) !== FALSE) { $outputArray[array_shift($shop)] = array_filter($shop); } echo "<table>"; foreach ($outputArray as $alphabetical=>$value){ echo "<th colspan='4'><b>" . $alphabetical ."</b></th>"; echo "<tr>"; foreach ($value as $key){ $afterkey=preg_replace('/\s+/','-',$key); if ($count == 4){ echo '</tr><tr><td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>'; $count = 0; }else{ echo '<td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>'; } $count++; } echo "</tr>"; $count = 0; } echo "</table>"; echo "\n<br />"; ?> Heres an example of what i am trying to do. A D K N S AlexandraHeadlands DickyBeach KingsBeach Nambour SandstonePoint Aroona Diddillibah KielMountain Ninderry ShellyBeach Doonan KundaPark NoosaHeads SippyDowns B Dulong Kuluin Ningi SunriseBeach Beachmere DeceptionBay Kilcoy NorthArm SunshineBeach BanksiaBeach Noosaville Scarborough Beerburrum E L Beerwah EerwahVale Landsborough O T Bellara Elimbah Tanawha Bellmere Eudlo M P TowenMountain Birtinya Eumundi Maleny Petrie Tewantin Bongaree Mapleton Palmview TwinWaters Bokarina F Marcoola Palmwoods BribieIslandArea Flaxton MarcusBeach Parklands U Buddina ForestGlen MaroochyRiver Parrearra UpperCaboolture Burnside Maroochydore PeregianBeach Buderim G Minyama Pinbarren V Burpengary GlassHouseMountains MoffatBeach PointArkwright Valdora BliBli Mons PelicanWaters H Montville PacificParadise W C Highworth Mooloolaba WeybaDowns CoolumBeach Hunchy Mooloolah Q Warana Caboolture MountainCreek WestWoombye CabooltureSouth I MountCoolum R Woombye Caloundra ImageFlat Morayfield Rosemount Woorim CastawaysBeach Mudjimba Redcliffe WamuranBasin Chevallum J Woodford CoesCreek WoodyPoint Cooroy Wamuran Currimundi Wurtulla X Y YandinaCreek Yandina Z ok, so I can't seem to figure out why when I take this code: Code: [Select] <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT SUM(amount) AS total FROM payment where cart_id='$cid'"); while($row = mysql_fetch_array($sql)){ $amount123 = $row["total"]; ?> <?php $left = $total-$amount123; } ?><?php echo $left; ?>I echo $left and instead of subtracting $amount123 from $total, it subtracts it from zero, but when I refresh the page, it works properly. can anyone see what the issue is? in my mysql query, after the results have been grouped is there any way to count the results? i have a end result like this: 784 | x.x.x.x 754 | x.x.x.x 784 | x.x.x.x so how can i count the first column after its been grouped by IPs? here is my query: SELECT * FROM `hits`GROUP BY ip Ok I have some data that I would like to have grouped by date. There are dates that have multiple entries for the same date. I would like to have that data listed under one date. I would like it to look like this Date Location Weather Location Weather Date Location Weather Here is the code I have so far and it lists the data by date but only the data for first date in the table. If there is data listed for the same date but different location it will not list that data. What am I missing. Any help would be great. ! <?php // Connect to server and select database. include ("opendb.php"); $tbl_name="dbnwaterfowl"; $sql="SELECT huntDate, huntLocation, huntWeather, waterfowlSpecies, waterfowlNumberKilled, waterfowlBandedNumber, DATE_FORMAT(huntDate,'%m %d, %Y') FROM dbnwaterfowl GROUP BY `huntDate` ORDER BY `huntDate` ASC"; $result=mysql_query($sql); ?> <td> <p> </p> <table width="100%" border="2" cellpadding="1" cellspacing="0" bordercolor="#FA6103" bgcolor="#FFFFFF"> <tr> <td colspan="7"><div align="center"> <p><img src="images/hl-logo.jpg" /></p> <p align="center"><strong><a href="login.php">Login</a> | <a href="insert.php">Log Hunt</a> | <a href="logout.php">Logout</a></strong></p> </div></td> </tr> <tr> <td align="center" bordercolor="#FA6103" ><span class="style4">Hunting Date</span></td> <td align="center" bordercolor="#FA6103" ><span class="style4">Hunting Location</span></td> <td align="center" bordercolor="#FA6103"><span class="style4">Weather</span></td> <td align="center" bordercolor="#FA6103"><span class="style4">Waterfowl Species</span></td> <td align="center" bordercolor="#FA6103"><span class="style4">Number Killed</span></td> <td align="center" bordercolor="#FA6103"><span class="style4">Number of Bands</span></td> <td align="center"> </td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><? echo $rows['huntDate']; ?></td> <td><? echo $rows['huntLocation']; ?></td> <td><? echo $rows['huntWeather']; ?></td> <td><? echo $rows['waterfowlSpecies']; ?></td> <td><? echo $rows['waterfowlNumberKilled']; ?></td> <td><? echo $rows['waterfowlBandedNumber']; ?></td> <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> Hi. I have the following code where I grab the names and average overall rating from my database and group by the name. Code: [Select] $sql="SELECT name, AVG(overall) AS overall FROM $tbl_name GROUP BY name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ Does anybody know how I can count the number of names that have been grouped together? For instance: Name Overal ratingl John 2 Pete 5 John 8 It should group the john's, calculate the average rating (8+2)/2=5, and then show that there have been 2 johns making up the 5 rating? I've tried using the code below and messed around with it loads but cant get it to work: Code: [Select] $sql="SELECT name, AVG(overall) AS overall FROM $tbl_name COUNT name GROUP BY name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ echo $rows['Count name']; Thanks in advance. I have a pipe delimited file with this sample content: INV8004199|01/26/2012|Next door|648.00 SPT803487|01/25/2012|This and That|3360.00 INV8004193|01/25/2012|Where is it|756.00 INV8004133|01/05/2012|snowy winter|6750.00 I open the file to read it: Code: [Select] $CPfile = "sample.DEL"; $ft = fopen( $CPfile, "r"); $content1 = fread($ft, filesize($CPfile)); fclose($ft); Then I loop thru it: Code: [Select] $out = explode("\n", $content1); $total = 0; foreach($out as $var) { $tmp = explode("|", $var); for($i=0;$i<count($tmp);$i++){ echo $tmp[$i] . "<BR>"; } } What I would like to get is the total of all prices (last column) in all lines of the file. Can someone help please?. Thanks! Hi, I'm having issues trying to add up the totals of each product type in a while loop- I'm sure it's straightforward to fix but for some reason I can't find a way to get it to add up all the totals of the various product types and list them so we have say 5 of product 1, 11 of product 2, 8 of product 3 and so on. So firstly the user searches between two different dates / times to get the orders made during that time period: (I'm using separare date and time fields as the datetime-local input doesn't work in a lot of browsers)
if($_POST['search']) //Now get the orders from the db $getorders = $oc_conn->query("SELECT * FROM oc_order WHERE date_added >= '$datetime1' AND date_added <= '$datetime2' AND order_status_id != 0 ORDER BY order_id DESC"); //Then generate start of a table in HTML, the while loop that follows will populate the rows while ($row = $getorders->fetch_assoc()) { //Get the order data
$firstname = $row["firstname"]; [/PHP] As mentioned in the comment above, what I need is the total $quantity of each $productname, across ALL orders in the time range, so that I can see how many of each product ($productname) were ordered in total. I tried using SUM for quantity in the mySQL, and COUNT for adding up the different product names but for some reason it didn't work. Can someone let me know what I need to do? Thanks :)
I am trying to create a quick script to update all my products in my product table, I want to set a prodOrder starting at 1 and incrementing by 1 for each product in the catalogID group. eg if I have 12 product with a catalogID of 1 then I want to number the prodOrder for each product in my table 1-12 and so on for each catalogID group whats the best way to do this here is my starter code but no where near performing this function $sql=("SELECT * FROM product ORDER BY productID ASC GROUP BY catalogID"); $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $catID=$row['catalogID']; $id=$row['productID']; $value='1'; foreach ($catID AS $id => $value) { $qty=("UPDATE product SET prodOrder='$value' WHERE productID='$id'"); $change=mysql_query($qty); echo $row['name']." from $catID - order = $value<br/>"; $value++ } } Howdy, I'm trying to display text from a table in a database. It's a list of quotes, so I just need to pull out the quote and the author name. However, the quote and name are not fields in the same record; they are separate records. Example data: Code: [Select] quoteid name value 1 content You guys are great! Thanks for being awesome. 1 author John Jackson 2 content Gosh you're amazing! Always been so darn helpful! 2 author Peter Davis So, I just need to rip out the data from 'content' and 'author', and then group them together based on the quoteid. This is my code thus far: $testimonial_resource = mysql_query("SELECT name, value FROM quotes GROUP BY quoteid ORDER BY author ASC") or die(mysql_error()); while ($testimonial = mysql_fetch_assoc($testimonial_resource)) { echo '<p>'.$testimonial['value']'.<br /><strong>'.$testimonial['value'].'</strong></p>'; } Any help would be greatly appreciated for this novice. Cheers. Ok, so I have a bit of code but it's not working as it should, would one of you guys have a look at it and let me know where I'm going wrong? Basically I need to be able to input several words or terms into the text area, each on a separate line and have the results displayed something like: hello: 23,000.000 hello world: 19,000,000 world: 278,000,000 I also see that the script is not searching the words / terms inside quotes (EG. "hello world") TIA Code: [Select] <html> <body> <?php function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)') { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); $result = curl_exec ($ch); curl_close ($ch); return $result; } $s = $_GET['s']; if (isset($s)) { echo "<p><i>Search for $s</i></p>"; $s = urlencode($s); $data = my_fetch("http://www.google.com/search?hl=en&q=" . $s . "&btnG=Google+Search"); $data = strip_tags($data); $find = 'Results 1 - 10 of about '; $find2 = ' for'; $data = strstr($data, $find); $pos = strpos($data, $find2); $search_number=substr($data,strlen($find), $pos-strlen($find)); echo "Total Results: $search_number"; } else { ?> <form name="form1" id="form1" method="get" action=""> <div align="left"> <p> <textarea name="s" type="text" id="s" rows="8" style="width:60%" /></textarea><br /> <input type="submit" name="Submit" value="Results" /></p> Put "" around the string: <input type="checkbox" checked name="apos" value="true" /><br /> </div> </form> <p> <?php } ?> </p> </body> </html> Hi All,
I'm looking to update a mysql column weekly, where by 5 randomly selected rows are given a new random number, from between 1 and the num_rows / 5. This cycle is looped again until all the entries have a new random group for the week. It is to help mix up the players for teams for 5 aside. It needs to be able to accomodate the posibillity of the num_rows not dividing exactly by 5, using ceil perhaps?
As an example
Name Group
a 1
b 2
c 1
d 1
e 1
f 3
g 2
h 1
i 2
j 2
k 2
Then Next week
Name Group
a 2
b 1
c 2
d 2
e 1
f 2
g 3
h 1
i 2
j 1
k 1
I hope that makes sense. It'll be automated via cron job.
I've been really struggling with it, this is as far as I have got.
$totalgroupsraw = $num_rows /5; Hi All,
I want to copy into a table values from another table that partially match a given value, case-insensitively. So far I do as follows but I wonder whether there is a quicker way.
$input_table=array('1'=>'toto','2'=>'tota','3'=>'hello','4'=>'TOTO','5'=>'toto'); $input_table_2 = array_map('strtolower', $input_table); $value_to_look_for='Tot'; $value_to_look_for_2=strtolower($value_to_look_for); $output_table=array(); foreach ($input_table_2 as $k=>$v) { if(false !== strpos($v, $value_to_look_for_2)) { $output_table[]=$input_table[$k]; } }One drawback is that $input_table_2 is 'foreached' whereas there might be no occurrences, which would lead to a loss of time/resources for big arrays. Thanks. Hello, I need some help. Say that I have a list in my MySQL database that contains elements "A", "S", "C", "D" etc... Now, I want to generate an html table where these elements should be distributed in a random and unique way while leaving some entries of the table empty, see the picture below. But, I have no clue how to do this... Any hints? Thanks in advance, Vero Hello everyone. I need help with the following PHP APP. I am running on (Version PHP 7.2.10) I am trying to have a page table form on table.php pass the input variable of “5-Numbers” to another page called table_results.php I want that variable string of “5-Numbers” to be compared against 4 arrays and output any duplicates found within each of those 4 lists. If nothing is found, I still want some visual output that reads “None found”.
Lets pretend I have the following example .. On table.php, I typed inside my table form the 5-Numbers .. INPUT: 2,15,37,13,28 On table_results.php, the 4 arrays to be compared against my input numbers “ 2,15,37,13,28” are ..
$array_A = array(2,6,8,11,14,18,24); $array_B = array(1,2,9,10,13,14,25,28,); $array_C = array(1,3,7,9,13,15,20,21,24); $array_D = array(4,5,12,22,23,27,28,29);
So my output should read as follows below .. OUTPUT:
TABLE COLUMN 1 COLUMN 2 ROW 1 Matches Found Results .. ROW 2 GROUP A: 2 ROW 3 GROUP B: 2,13,28 ROW 4 GROUP ? 13,15 ROW 5 GROUP ? 28 ROW 6 5#s Input: 2,15,37,13,28
Please let me know if anyone has any suggestions on how to go about it. Thanks. Edited January 1, 2019 by Jayfromsandiego Wanted to include image example Hi All ,
I have a small table with 4 fields namely Day_ID, Dues, Last_Visit, Points. where Day_ID is an auto-increment field. The table would be as follows:
Day_ID -- Dues --- Last_Visit --- Points.
1 --------- 900 -------- 1/12 -------- 6
2 --------- 700 -------- 4/12 -------- 7
3 --------- 600 -------- 7/12 -------- 5
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
So this is the record of a person's visit to say a club. The last row indicates the last date of his visit to the club. His points on this date are 6. Based on this point value of 6 in the last row I want to retrieve all the previous BUT adjoining all records that have the same Points i.e. 6.
So my query should retrieve for me, based on the column value of Points of the last row (i.e. Day_ID - 6 ), as follows:
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
This problem stated above had been completely resolved, thanks to a lot of help from Guru Barand by this following query :-
$query = "SELECT cv.day_id, cv.dues, cv.last_visit, cv.points FROM clubvisit cv WHERE last_visit >= ( SELECT MAX(last_visit) FROM clubvisit WHERE points <> ( SELECT points as lastpoints FROM clubvisit JOIN ( SELECT MAX(last_visit) as last_visit FROM clubvisit ) as latest USING (last_visit) ) )";I am using this and it works perfectly except that now there is a slight change in the table because the criteria for points is now dependent on more than one column cv.points and is more like cv.points1, cv.points2, cv.points3 etc. So now I need to make a selection based on each of these cv.points columns. As of now I can still get the results by running the query multiple times for each of the cv.points columns ( seperately for cv.points1, cv.points2, cv.points3) and it works correctly. However I am wondering if there is a better way to do this in just one go. This not only makes the code repetitive but also since the queries are interconnected, involves the use of transactions which I wish to avoid if possible. The values that I require for each of the cv.point columns is 1. day_id of the previous / old day on which the cv.points value changed from the current day value, and 2. cv.points on that old/ previous day. So for example if the table is as below: Day_ID -- Dues --- Last_Visit --- Points1 --- Points2. 1 --------- 900 -------- 1/12 ----------- 9 ------------ 5 2 --------- 600 -------- 4/12 ----------- 6 ------------ 6 3 --------- 400 -------- 7/12 ----------- 4 ------------ 7 4 --------- 500 -------- 9/12 ----------- 5 ------------ 8 5 --------- 600 -------- 10/12 ---------- 6 ------------ 8 6 --------- 600 -------- 11/12 ---------- 6 ------------ 8 7 --------- 600 -------- 13/12 ---------- 6 ------------ 7 8 --------- 500 -------- 15/12 ---------- 5 ------------ 7 9 --------- 500 -------- 19/12 ---------- 5 ------------ 7 Then I need the following set of values : 1. day_id1 -- Day 7, points1 ---- 6, days_diff1 -- (9-7 = 2) . // Difference between the latest day and day_id1 2. day_id2 -- Day 6, points2 ---- 8, days_diff2 -- (9-6 = 3) 3. day_id3 -- .... and so on for other points. Thanks all ! hi... i have a table ... i add and remove data in the table...when i add new record , information add to center of the table ! whats problem? i want add data in first of table. please guide me.thanks
Hi
I am very new to PHP & Mysql.
I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion.
Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself.
Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows).
Ripon.
Below is my Code:
<?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?>Output is attached. I know I'm doing it something right, but can someone tell me why only one table is showing up? Can you help me fix the issue? Heres my code: function showcoords() { echo"J3st3r's CoordVision"; $result=dbquery("SELECT alliance, region, coordx, coordy FROM ".DB_COORDFUSION.""); dbarray($result); $fields_num = mysql_num_fields($result); echo "<table border='1'>"; // printing table headers echo "<td>Alliance</td>"; echo "<td>Region</td>"; echo "<td>Coord</td>"; // printing table rows while($row = mysql_fetch_array($result)) { // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row AS $Cell) echo "<tr>"; echo "<td>".$row['alliance']."</td>\n"; echo "<td>".$row['region']."</td>\n"; echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n"; echo "</tr>\n"; } echo "</table>"; mysql_free_result($result); } I have 2 rows inserted into my coords table. Just frustrated and ignorant to php. |