Jump to content

l3asturd

Members
  • Posts

    40
  • Joined

  • Last visited

    Never

Everything posted by l3asturd

  1. Yeah it works. Sorry, it all kinda runs together after looking at code all day. PHP...SQL...HTML...
  2. I think that worked, I wrote a quickie to find out, and it looks like it's giving me the results I'm asking for. I'll write back after I've tested this out with real data.
  3. ok, I don't have any code yet, my module is a concept until I can figure out if it's possible. So here's what I have: A table that has user names, golf courses, and scores at each course. There are multiple entries for each course but different scores. OK here's an example table: Name Score Course ------------------------------------- John 50 Visalia John 49 Visalia Rick 48 Visalia John 52 Tulare Rick 77 Hanford Rick 50 Tulare OK, now, on my stats page, I wanted users to be able to see their score averages for each course. I know how to pull the data from SQL and GROUP BY course. I know how to AVG(Score) AS TotalAverage. Problem is, how can I average scores for each course AND for each player at the same time. John's average score at Visalia is 50 John's average score at Tulare is 52 See what I'm getting at. I tried something like: SELECT * from TABLE WHERE name=John GROUP BY course AVG(score) AS courseaverage but this is bad syntax, and wouldn't result in the data I'm looking for. Any ideas?
  4. ok, well, what does this actually do? list.php?sortby=name does this set a $sortby variable to "name"? Or does it act like a $_POST['sortby'] variable. Hopefully it does the first thing, because I think I can work with that. If it sets $sortby, I would just include $sortby in my SQL query right?
  5. I may understand. Let's say my form action (only for the sorting dropdown) is going to be link:http://www.domain.com/list.php?sortby=Computer Is this what you mean? No, that's not what you mean. Let me read a few more times.
  6. <?php $content .=" Sort by : <SELECT name=\"sortby\" size=\"1\" STYLE=background:#FFCC00;>"; $content .="<OPTION SELECTED>Site<OPTION>Service Tag<OPTION>User<OPTION>Computer Name"; $content .="<OPTION>Model<OPTION>Condition<OPTION>Status<OPTION>Newest<OPTION>Oldest</SELECT>"; ?> I know this is probably more of an HTML question, or a FORM question, but I've been trying to figure out how to make the "sortby" dropdown selection auto submit. So when someone clicks Sortby:Computer Name the page auto refreshes with the new ORDER by variable. Any help is appreciated. Thanks.
  7. Just an FYI, I posted a donation a few minutes ago for all the help PHP freaks has given me in the past few weeks. Thanks a lot.
  8. why not use the button type? ie: <input type=\"button\" name=\"Search\" etc etc
  9. like he said, create a `views` field in your table. Set them all to 0. Now when you query the table you'll get 0 views. After the query, make $views = ($results['views']) and add value to $views using $views++. Then INSERT $views back to the table. That's how I'd attempt it.
  10. Are you calling the INSERT query twice here? $result = mysql_query ($query) or die(mysql_error()); $result = mysql_query($query); If not, add some echo statements before and after the insert to help troubleshoot.
  11. $rowcs is looking for $resultcs, but $resultcs is commented out. That's why the fetch_array error arguement error.
  12. OK, I've been messing with PHP for about three weeks now (ever since I joined PHPFreaks). I wrote a little script here, which kinda turned in to a big mess. I mean, it works fine, but I know it's resourceful, and there's probably a few things you experts could share that would make it more efficient. I'm just looking for better ways to get things done in here. Any ideas? Also, when someone fills out the data and presses the submit button it completes the SQL insert, but the new data doesn't show up in the SELECT query until the user presses the REFRESH button. Is there any way to REFRESH the information shown without the user having to press refresh. Here's the link to the page so you can see what I mean: http://www.disctribution.com/forums/insert.php Please feel free to submit new information, I can easily delete anything you guys submit. Thanks in advance for any help. <? <?php $host = blocked; $user = 'blocked'; $password = 'blocked'; $dbName = 'blocked'; $dbTable = 'computeraudit'; $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY isite', $conn); if (($_POST['sortby'])=="Service Tag"): $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY iservice', $conn); endif; if (($_POST['sortby'])=="Computer"): $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY icomputer', $conn); endif; if (($_POST['sortby'])=="User"): $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY iuser', $conn); endif; if (($_POST['sortby'])=="Model"): $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY imodel', $conn); endif; if (($_POST['sortby'])=="Condition"): $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY icondition', $conn); endif; if (($_POST['sortby'])=="Status"): $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY istatus', $conn); endif; if (($_POST['sortby'])=="Newest"): $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY idate DESC', $conn); endif; if (($_POST['sortby'])=="Oldest"): $select_result = mysql_query('SELECT * FROM computeraudit ORDER BY idate', $conn); endif; // The rest of this loops through outputting the information echo date("l jS F Y, g:i A"); echo "<body bgcolor=64748B>"; $content = ""; $content .= "<br><b><br> Make a new entry: <br>"; $content .= "<form action=\"{$_SERVER['PHP_SELF']}\" method = \"post\">"; $content .= "<input type=\"text\" name=\"service\" maxlength=\"25\" size=\"20\" STYLE=background:#FFCC00;> Service Tag <font color=AA0011>(required)</font><br>"; //$content .= "<input type=\"text\" name=\"site\" maxlength=\"25\" size=\"20\" STYLE=background:#E6E6FA;> Site<br>"; $content .= "<SELECT name=\"site\" size=\"1\" STYLE=background:#E6E6FA;><OPTION SELECTED> <OPTION>Bakersfield<OPTION>Big Pine<OPTION>Big Sandy<OPTION>Bishop<OPTION>Cold Springs<OPTION>Fresno<OPTION>Handford<OPTION>HR<OPTION>Lake Isabella<OPTION>Lone Pine<OPTION>Porterville<OPTION>Ridgecrest<OPTION>Santa Rosa<OPTION>Tule River<OPTION>Visalia</SELECT> Site<br>"; $content .= "<input type=\"text\" name=\"computer\" maxlength=\"25\" size=\"20\" STYLE=background:#E6E6FA;> Computer Name<br>"; $content .= "<input type=\"text\" name=\"user\" maxlength=\"25\" size=\"20\" STYLE=background:#E6E6FA;> User<br>"; $content .= "<input type=\"text\" name=\"model\" maxlength=\"25\" size=\"20\" STYLE=background:#E6E6FA;> Model<br>"; $content .= "<input type=\"text\" name=\"lanmac\" maxlength=\"25\" size=\"20\" STYLE=background:#E6E6FA;> LAN MAC<br>"; $content .= "<input type=\"text\" name=\"wanmac\" maxlength=\"25\" size=\"20\" STYLE=background:#E6E6FA;> WWAN MAC<br>"; $content .= "<SELECT name=\"condition\" size=\"1\" STYLE=background:#E6E6FA;><OPTION SELECTED> <OPTION>Junk<OPTION>Poor<OPTION>Fair<OPTION>Good<OPTION>Excellent<OPTION>NEW</SELECT> Condition<br>"; $content .= "<SELECT name=\"status\" size=\"1\" STYLE=background:#E6E6FA;><OPTION SELECTED> <OPTION>Idle-Outdated<OPTION>Idle-Formatted<OPTION>Idle-Current<OPTION>In Use-Outdated<OPTION>In Use-Current<OPTION>New In Box</SELECT> Status<br>Please check all that apply...<br>"; $content .= "<input type=\"checkbox\" name=\"ad\" STYLE=background:#64748B;>Adobe<br>"; $content .= "<input type=\"checkbox\" name=\"av\" STYLE=background:#64748B;>Antivirus<br>"; $content .= "<input type=\"checkbox\" name=\"ja\" STYLE=background:#64748B;>Java RE<br>"; $content .= "<input type=\"checkbox\" name=\"nd\" STYLE=background:#64748B;>Network Drives<br>"; $content .= "<input type=\"checkbox\" name=\"sh\" STYLE=background:#64748B;>Shoretel<br>"; $content .= "<input type=\"checkbox\" name=\"sp\" STYLE=background:#64748B;>Anti-Spyware<br>"; $content .= "<input type=\"checkbox\" name=\"up\" STYLE=background:#64748B;>Microsoft Updates<br>"; $content .= "<input type=\"checkbox\" name=\"vp\" STYLE=background:#64748B;>VPN<br><br>"; $content .= "<input type=\"checkbox\" name=\"update\" STYLE=background:#AA0000;> Update Record?<br>"; $content .= "<input type=\"submit\" value=\"Refresh\">"; $content .= " Sort by : <SELECT name=\"sortby\" size=\"1\" STYLE=background:#FFCC00;><OPTION SELECTED>Site<OPTION>Service Tag<OPTION>User<OPTION>Computer Name<OPTION>Model<OPTION>Condition<OPTION>Status<OPTION>Newest<OPTION>Oldest</SELECT>"; $content .= "</form></b><br>"; $content .= "<b>AD</b> = Adobe <b>AV</b> = Antivirus <b>JA</b> = Java RE <b>ND</b> = Network Drives<br><b>SH</b> = Shoretel <b>SP</b> = Anti-Spyware <b>UP</b> = MS Updates <b>VP</b> = VPN<br><br><table bgcolor=D3DCE6 cellpadding=0 cellspacing=0 width=100% border=1>"; $content .= "<th align=center>Service Tag</th>"; $content .= "<th align=center>Site</th>"; $content .= "<th align=center>Computer Name</th>"; $content .= "<th align=center>User</th>"; $content .= "<th align=center>Model</th>"; $content .= "<th align=center>LAN MAC</th>"; $content .= "<th align=center>WWAN MAC</th>"; $content .= "<th align=center>Condition</th>"; $content .= "<th align=center>Status</th>"; $content .= "<th align=center>AD</th>"; $content .= "<th align=center>AV</th>"; $content .= "<th align=center>JA</th>"; $content .= "<th align=center>ND</th>"; $content .= "<th align=center>SH</th>"; $content .= "<th align=center>SP</th>"; $content .= "<th align=center>UP</th>"; $content .= "<th align=center>VP</th>"; $content .= "<th align=center>Last Update</th>"; while($list1 = mysql_fetch_assoc($select_result)): if (($list1['ad'])==0): $adimagesource = "http://www.disctribution.com/forums/images/unchecked.gif"; else: $adimagesource = "http://www.disctribution.com/forums/images/checked.gif"; endif; if (($list1['av'])==0): $avimagesource = "http://www.disctribution.com/forums/images/unchecked.gif"; else: $avimagesource = "http://www.disctribution.com/forums/images/checked.gif"; endif; if (($list1['ja'])==0): $jaimagesource = "http://www.disctribution.com/forums/images/unchecked.gif"; else: $jaimagesource = "http://www.disctribution.com/forums/images/checked.gif"; endif; if (($list1['nd'])==0): $ndimagesource = "http://www.disctribution.com/forums/images/unchecked.gif"; else: $ndimagesource = "http://www.disctribution.com/forums/images/checked.gif"; endif; if (($list1['sh'])==0): $shimagesource = "http://www.disctribution.com/forums/images/unchecked.gif"; else: $shimagesource = "http://www.disctribution.com/forums/images/checked.gif"; endif; if (($list1['sp'])==0): $spimagesource = "http://www.disctribution.com/forums/images/unchecked.gif"; else: $spimagesource = "http://www.disctribution.com/forums/images/checked.gif"; endif; if (($list1['up'])==0): $upimagesource = "http://www.disctribution.com/forums/images/unchecked.gif"; else: $upimagesource = "http://www.disctribution.com/forums/images/checked.gif"; endif; if (($list1['vp'])==0): $vpimagesource = "http://www.disctribution.com/forums/images/unchecked.gif"; else: $vpimagesource = "http://www.disctribution.com/forums/images/checked.gif"; endif; $content .= "<tr border=2 bgcolor=FFCC00>"; $content .= "<td align=center>".$list1['iservice']."</td>"; $content .= "<td align=center>".$list1['isite']."</td>"; $content .= "<td align=center>".$list1['icomputer']."</td>"; $content .= "<td align=center>".$list1['iuser']."</td>"; $content .= "<td align=center>".$list1['imodel']."</td>"; $content .= "<td align=center>".$list1['ilanmac']."</td>"; $content .= "<td align=center>".$list1['iwanmac']."</td>"; $content .= "<td align=center>".$list1['icondition']."</td>"; $content .= "<td align=center>".$list1['istatus']."</td>"; $content .= "<td align=center><img src=\"".$adimagesource."\"></img></td>"; $content .= "<td align=center><img src=\"".$avimagesource."\"></img></td>"; $content .= "<td align=center><img src=\"".$jaimagesource."\"></img></td>"; $content .= "<td align=center><img src=\"".$ndimagesource."\"></img></td>"; $content .= "<td align=center><img src=\"".$shimagesource."\"></img></td>"; $content .= "<td align=center><img src=\"".$spimagesource."\"></img></td>"; $content .= "<td align=center><img src=\"".$upimagesource."\"></img></td>"; $content .= "<td align=center><img src=\"".$vpimagesource."\"></img></td>"; $timeago = time() - $list1['idate']; $daysago = number_format(($timeago / 86400),1); $content .= "<td align=center>".$daysago." days ago</td>"; //$content .= "<td align=center>".$list1['idate']."</td>"; $content .= "</tr>"; endwhile; $content .= "</table>"; // Make sure the user entered values for all three fields if (strlen($_POST['service'])>0):// IF TRUE // Add the values to the $data array if (($_POST['update'])=="on") { if (($_POST['ad'])=="on"): $Pad = 1; echo "AD is".$Pad; else: $Pad = 0; endif; if (($_POST['av'])=="on"): $Pav = 1; else: $Pav = 0; endif; if (($_POST['ja'])=="on"): $Pja = 1; else: $Pja = 0; endif; if (($_POST['nd'])=="on"): $Pnd = 1; else: $Pnd = 0; endif; if (($_POST['sh'])=="on"): $Psh = 1; else: $Psh = 0; endif; if (($_POST['sp'])=="on"): $Psp = 1; else: $Psp = 0; endif; if (($_POST['up'])=="on"): $Pup = 1; else: $Pup = 0; endif; if (($_POST['vp'])=="on"): $Pvp = 1; else: $Pvp = 0; endif; if (($_POST['service'])!=="") { $uservice = $_POST['service']; $result2 = mysql_query('SELECT * FROM computeraudit WHERE iservice = \'$uservice\'', $conn); $list2 = mysql_fetch_assoc($result2); if ($Pad !== ($list2['ad'])): $uad = $Pad; $update_result = mysql_query("UPDATE computeraudit SET ad = '$uad' WHERE iservice = '$uservice' LIMIT 1;", $conn); else: echo $Pad." equals ".$list2['ad']."<br><br><br>"; endif; if ($Pav !== ($list2['av'])): $uav = $Pav; $update_result = mysql_query("UPDATE computeraudit SET av = '$uav' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if ($Pja !== ($list2['ja'])): $uja = $Pja; $update_result = mysql_query("UPDATE computeraudit SET ja = '$uja' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if ($Pnd !== ($list2['nd'])): $und = $Pnd; $update_result = mysql_query("UPDATE computeraudit SET nd = '$und' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if ($Psh !== ($list2['sh'])): $ush = $Psh; $update_result = mysql_query("UPDATE computeraudit SET sh = '$ush' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if ($Psp !== ($list2['sp'])): $usp = $Psp; $update_result = mysql_query("UPDATE computeraudit SET sp = '$usp' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if ($Pup !== ($list2['up'])): $uup = $Pup; $update_result = mysql_query("UPDATE computeraudit SET up = '$uup' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if ($Pvp !== ($list2['vp'])): $uvp = $Pvp; $update_result = mysql_query("UPDATE computeraudit SET vp = '$uvp' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; $utime = time(); $update_time = mysql_query("UPDATE computeraudit SET idate = '$utime' WHERE iservice = '$uservice' LIMIT 1;", $conn); if (($_POST['site'])!==""): $usite = $_POST['site']; $update_result = mysql_query("UPDATE computeraudit SET isite = '$usite' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if (($_POST['computer'])!==""): $ucomputer = $_POST['computer']; $update_result = mysql_query("UPDATE computeraudit SET icomputer = '$ucomputer' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if (($_POST['user'])!==""): $uuser = $_POST['user']; $update_result = mysql_query("UPDATE computeraudit SET iuser = '$uuser' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if (($_POST['model'])!==""): $umodel = $_POST['model']; $update_result = mysql_query("UPDATE computeraudit SET imodel = '$umodel' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if (($_POST['lanmac'])!==""): $ulanmac = $_POST['lanmac']; $update_result = mysql_query("UPDATE computeraudit SET ilanmac = '$ulanmac' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if (($_POST['wanmac'])!==""): $uwanmac = $_POST['wanmac']; $update_result = mysql_query("UPDATE computeraudit SET iwanmac = '$uwanmac' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if (($_POST['condition'])!==""): $ucondition = $_POST['condition']; $update_result = mysql_query("UPDATE computeraudit SET icondition = '$ucondition' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; if (($_POST['status'])!==""): $ustatus = $_POST['status']; $update_result = mysql_query("UPDATE computeraudit SET istatus = '$ustatus' WHERE iservice = '$uservice' LIMIT 1;", $conn); endif; echo "<br><font color=FF22CC>UPDATED!</font><br>"; } else { echo "<br><font color=\"FF0000\"><b>Service Tag MUST be entered to update!</b></font>"; } } else { if (($_POST['ad'])=="on"): $iad = 1; else: $iad = 0; endif; if (($_POST['av'])=="on"): $iav = 1; else: $iav = 0; endif; if (($_POST['ja'])=="on"): $ija = 1; else: $ija = 0; endif; if (($_POST['nd'])=="on"): $ind = 1; else: $ind = 0; endif; if (($_POST['sh'])=="on"): $ish = 1; else: $ish = 0; endif; if (($_POST['sp'])=="on"): $isp = 1; else: $isp = 0; endif; if (($_POST['up'])=="on"): $iup = 1; else: $iup = 0; endif; if (($_POST['vp'])=="on"): $ivp = 1; else: $ivp = 0; endif; $data = array('isite' => $_POST['site'],'icomputer' => $_POST['computer'],'iuser' => $_POST['user'],'imodel' => $_POST['model'], 'iservice' => $_POST['service'], 'ilanmac' => $_POST['lanmac'], 'iwanmac' => $_POST['wanmac'], 'icondition' => $_POST['condition'], 'istatus' => $_POST['status'], 'idate' => time(), 'ad' => $iad, 'av' => $iav, 'ja' => $ija, 'nd' => $ind, 'sh' => $ish, 'sp' => $isp, 'up' => $iup, 'vp' => $ivp); $field_names = array(); $values = array(); // Loop through the array foreach($data as $field_name => $value): if(empty($value)) continue; $field_names[] = $field_name; // Make sure no invalid information was put into the form $values[] = "'".mysql_real_escape_string($value, $conn)."'"; endforeach; // Add the results into the table $insert_result = mysql_query("INSERT INTO $dbTable (".join(',',$field_names).") VALUES(".join(',',$values).")", $conn); $content .= "<Font color=FF0000><b>Added data, please <i>REFRESH</i></b><br></font>"; } endif; echo $content; ?>
  13. here's an example of something I did that sores a URL in a variable. I don't think it's exactly what you're asking though. After rereading your post I realize I didn't get what you meant. lol <?php if (($_POST['answer'])=="Yes"): $link="http://www.domain.com/images/yes.gif"; else: $link="http://www.domain.com/images/no.gif"; endif; echo "Your colorful answer is <IMG SRC=\"".$link."\"></IMG>"; ?>
  14. Problem here is when the user hits the back button it refreshed a page that is stored in cache. It doesn't reload the page, hence why the time is the "old" time. In fact, the time is exactly what time the page was loaded the first time. The only thing I can think of is to create navigation buttons on your page, so that when someone presses your back button, it actually reloads the page, creating a new time. I'm not sure of another way to fix this, but I'm sure some of these guys might have an idea.
  15. here's how I would do it: <?php $ratio_query = "SELECT name, SUM(death) AS TotalDeaths, SUM(kills) AS TotalKills FROM `stats`,`members` WHERE `stats`.`key` = `members`.`key_hash` GROUP BY `stats`.`key` ORDER BY TotalKills ASC"; ?> However, I am a noob, and I doubt this is the result you're looking for. This would result in sorting Total Kills, whereas you're trying to sort the K/D ratio I believe. I'll keep thinking.
  16. Here's the line of code I used for inserting the arrays into the table: <?php $insert_result = mysql_query("INSERT INTO $dbTable (".join(',',$field_names).") VALUES(".join(',',$values).")", $conn); ?> However when I have more than 5 fields with values the SQL goes kaput as if there is a limit for each query syntax length. I know it's got to be something in my code because people obviously have more than 5 fields in there tables.
  17. Acutally those field names are just for show, the actual field names are like WANMAC,LANMAC,Service etc. Disregard the field names. Also, the data as of yet is just 'test'. I don't have a table full of data yet, I'm trying to create one. Thanks for any help.
  18. OK, I have a working insert script, but I was trying to create a new one when I ran in to a problem When using: <?php $insert = mysql_query("INSERT INTO $dbtable (Name,Location,Age) VALUES ('test','test','test')"); ?> the result seems to work fine, however, when I add fields and values I seem to hit a syntax boundary. <?php $insert = mysql_query("INSERT INTO $dbtable (Name,Location,Age,Sex,Games,Nick,Tables,Hands,Feet) VALUES ('test','test','test','test','test','test','test','test','test')"); ?> The last code results in no entries. When I checked my SQL portal it says syntax error. I'm guessing there's some kind of query length limit, am I right? I've tried inserting the data using a $field_names array and a $values array, but still get the same result. Any ideas?
  19. oh jeez I put one too many commas, nevermind. It works fine.
  20. [code]The following code works great: [code]<?php // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); // Pull the results from the table $select_result = mysql_query("SELECT Name, SUM(Score) as TotalScore FROM TLB GROUP BY Name ORDER BY TotalScore", $conn); while ($list = mysql_fetch_array($select_result)): if ($list['Name'] != ""): $content .= "<font color=silver>Name</font> <font color=red><b>".$list['Name']."</b></font>"; $content .= "<font color=silver> Total Score</font><font color=red><b> ".$list['TotalScore']."</b></font><br>"; endif; endwhile; echo $content; ?> however, when I the change the query line to this it doesn't work: <?php $select_result = mysql_query("SELECT Name, SUM(Score) as TotalScore, SUM(Purse) as TotalPurse, SUM(Aces) as TotalAces, FROM TLB GROUP BY Name ORDER BY TotalScore", $conn); ?> Am I trying the impossible? Is there too much going on in 1 query? [/code][/code]
  21. thanks teng. I'll write up the new code. Thanks to every1.
  22. Now I know why you're called a genius. Thanks. Oooh, in the SQL query, is TotalScore a table field I need to add to the table? Or is it a PHP variable in the script? I'm guessing I need to add a field named TotalScore as you didn't put a $ in front of it. If anyone else know's the answer please let me know.
  23. Is it really that easy? How can I change the query so that it adds duplicate names? Like, instead of SUM(score) for 'Mike' SUM(score) for duplicate names Thanks for your help!
  24. ok, Now that I know how to write and read using PHP/SQL I'm trying to move on to the next step. Manipulating results. Here's an example of raw table data displayed in an html <table> result: ------------------------------------- - Name -Score -Purse -Date - ___________________________ - Mike 10 $5 7/24 - Larry 8 $3 7/24 - Rob 7 $2 7/24 - Mike 9 $4 7/31 - Larry 8 $3 7/31 - Rob 4 $1 7/31 ___________________________ Now I now how to sort ASC and DESC to get the scores arranged using ORDER BY, here's my challenge. I'd like to take the contents of the table, or *, look for duplicates, such as Mike's record on 7/24 and Mike's record on 7/31, and add the fields together, to display a total score and total purse. I don't want to delete or update the table, just manipulate the results so I can display totals in a <table>. So...here's my code, which is a joke, to attempt to do something like this: <?php //assume db connected $result = mysql_query("SELECT * FROM table1 ORDER BY name ASC", $conn); while ($row = mysql_fetch_array($result)) { //This is where I am totally lost. How can you add row scores depending on if the name field is a duplicate? } endwhile; ?> ok so that's as far as I've gotten
×
×
  • 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.