PHP - Help Ordering Table Rows In Php Urgent!
hi
i have table in my database holding food items. i need users to be able to order those items individually for example...if apples are third from the top..they should be able to move them up or down the list 1 place at a time perhaps with an up and down arrow. i have a field in my table called item_order the only problem is...users are going to be able to insert new items to the database...but i dont know how they can populate the order field...i cant set it to auto increment because the item_id is the primary key auto incrementing...how can i populate the order field? and then once i have this problem sorted how do i then allow users to change this order? im looking for code if possible please because ive spent WAY to long on this now and im struggling to grasp things people advise me to do. terminology and methods of accomplishing this are just going over my head. please help. Similar TutorialsHi everyone. I'm putting together a client list for my company and I need to be able to move clients around from day to day and also change the order they are listed. My only problem is I can't figure out a way to adjust the orderid once moving them.
My database is set up something like this:
id | orderid | driverid | day | name | email
1 1 1 Mon - -
2 3 1 Tue - -
3 2 2 Wed - -
4 4 1 Mon - -
I need to be able to edit a rows orderid, lets say from 5 to 3 and re-order everyone so that there are no orderid duplicates and no gaps. I was thinking I need to submit the form with the changed orderid and if the new orderid is different from the old orderid, a query will select and add 1 to the rows with an orderid greater than the new one submitted and only for clients on that drivers day. Once that is done a new query will re-adjust all the orderid's again and re-order them so there are no gaps.
Am I on the right track here? How would I write this code out? I feel as if im doing it all wrong. Any help is greatly appreciated. Thanks
if ($orderid1 != $orderid2) { $result = mysql_query("SELECT * FROM clients WHERE driverid = '$driverid' and day = '$day'") or die (mysql_error()); while($row = mysql_fetch_assoc($result)){ $neworderid = $row['orderid'] + 1; mysql_query("UPDATE clients SET orderid = '$neworderid', WHERE orderid > '$orderid2' and clientid = '$row[clientid]'"); } } Edited by Kinger1613, 13 December 2014 - 11:15 AM. Hi, I am using multiple rows in my table and I want to order it in ascending order from a column. With SQL statement it is simple as saying ORDER BY column but how I can do this with just numbers? So I want for example: (goes in correct order) Col 1 Col 2 Col3 # 5 # # 43 # # 87 # # 113 # instead of: Col 1 Col 2 Col3 # 113 # # 43 # # 87 # # 5 # Thanks for any help!! Hi there, Firstly this is a link to my working code/script http://www.nexus-guild.eu/adornments/index.php When you click on one of the body images it pulls all the data from the database for that particular slot and feeds it into a table. I am wondering how i can make it so when you click on the table column descriptions such as the Name/Effect/Quality/Level/Colour/Faction Name/Faction Value it will reorder all the information in ascending order or descending order. Ive looked around quite a bit for this but i cant find anything on this. This is the code im currently using. It has alot of repeating code which makes up the majority of the file Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>neXus - Adornments Calculator</title> <style type="text/css"> <!-- body { background-color: #2f2626; } body,td,th { color: #000; font-family: Trebuchet MS, Arial, Helvetica, sans-serif; } --> </style></head> <body text="#FFFFFF" link="#ff8000" vlink="#ff8000" alink="#ff8000"> <center> <p> </p> <p> </p> <p><img src="character.png" border="0" usemap="#Map"/> <map name="Map" id="Map"> <area shape="rect" coords="2,2,44,44" href="index.php?slot=head" /> <area shape="rect" coords="45,2,85,44" href="index.php?slot=cloak" /> <area shape="rect" coords="2,46,44,86" href="index.php?slot=chest" /> <area shape="rect" coords="45,45,85,86" href="index.php?slot=shoulders" /> <area shape="rect" coords="45,87,85,129" href="index.php?slot=forearms" /> <area shape="rect" coords="2,87,44,129" href="index.php?slot=legs" /> <area shape="rect" coords="45,130,85,170" href="index.php?slot=hands" /> <area shape="rect" coords="3,130,44,170" href="index.php?slot=feet" /> <area shape="rect" coords="46,172,86,216" href="index.php?slot=charm" /> <area shape="rect" coords="3,172,45,215" href="index.php?slot=charm" /> <area shape="rect" coords="45,216,85,257" href="index.php?slot=drink" /> <area shape="rect" coords="3,216,44,256" href="index.php?slot=food" /> <area shape="rect" coords="362,2,403,43" href="index.php?slot=waist" /> <area shape="rect" coords="405,2,443,43" href="index.php?slot=neck" /> <area shape="rect" coords="362,45,403,86" href="index.php?slot=ear" /> <area shape="rect" coords="405,45,444,87" href="index.php?slot=ear" /> <area shape="rect" coords="363,88,402,129" href="index.php?slot=finger" /> <area shape="rect" coords="405,89,444,128" href="index.php?slot=finger" /> <area shape="rect" coords="363,131,402,171" href="index.php?slot=wrist" /> <area shape="rect" coords="405,130,443,170" href="index.php?slot=wrist" /> <area shape="rect" coords="362,174,404,213" href="index.php?slot=ranged" /> <area shape="rect" coords="405,173,443,212" href="index.php?slot=ammo" /> <area shape="rect" coords="362,216,404,256" href="index.php?slot=primary" /> <area shape="rect" coords="405,216,444,256" href="index.php?slot=secondary" /> </map> <br> <br> <p> <?php include 'db_connect.php'; if (isset($_GET["slot"])) { $slot = $_GET["slot"]; } else { $slot=startpage; }; $color1 = "#E1FAE2"; $color2 = "#ffffff"; $row_count = 0; //////////////////////////////////////////////////////////////////////////////// /////////////////////////////STARTPAGE - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// if ( $slot == "startpage" ) { echo "This is still in beta. If you find any bugs please send them to <a href=\"mailto:sosia@nexus-guild.eu\">Sosia</a>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////STARTPAGE - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////HEAD SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "head" ) { $sql = "SELECT * FROM $db_table WHERE for_head = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////HEAD SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////CLOAK - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "cloak" ) { $sql = "SELECT * FROM $db_table WHERE for_cloak = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////CLOAK SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////CHEST SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "chest" ) { $sql = "SELECT * FROM $db_table WHERE for_chest = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////CHEST SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////SHOULDERS SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "shoulders" ) { $sql = "SELECT * FROM $db_table WHERE for_shoulders = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////SHOULDERS SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////FOREARMS SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "forearms" ) { $sql = "SELECT * FROM $db_table WHERE for_forearms = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////FOREARMS SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////LEGS SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "legs" ) { $sql = "SELECT * FROM $db_table WHERE for_legs = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////LEGS SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////HANDS SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "hands" ) { $sql = "SELECT * FROM $db_table WHERE for_hands = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////HANDS SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////FEET SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "feet" ) { $sql = "SELECT * FROM $db_table WHERE for_feet = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////FEET SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////WAIST SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "waist" ) { $sql = "SELECT * FROM $db_table WHERE for_waist = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////WAIST SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////NECK SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "neck" ) { $sql = "SELECT * FROM $db_table WHERE for_head = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////NECK SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////EAR SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "ear" ) { $sql = "SELECT * FROM $db_table WHERE for_head = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////EAR SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////FINGER SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "finger" ) { $sql = "SELECT * FROM $db_table WHERE for_finger = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////FINGER SLOT - END//////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// /////////////////////////////WRIST SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "wrist" ) { $sql = "SELECT * FROM $db_table WHERE for_head = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////WRIST SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////CHARM SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "charm" ) { $sql = "SELECT * FROM $db_table WHERE for_charm = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////CHARM SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////PRIMARY SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "primary" ) { $sql = "SELECT * FROM $db_table WHERE for_primary = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////PRIMARY SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////SECONDARY SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "secondary" ) { $sql = "SELECT * FROM $db_table WHERE for_head = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////SECONDARY SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////RANGED SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "ranged" ) { $sql = "SELECT * FROM $db_table WHERE for_head = '1' ORDER BY name"; $result = mysql_query ($sql,$db); echo "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"90%\" bgcolor=\"#FFDCCC\">"; echo "<tr> <th align=\"left\">Name</th> <th align=\"left\">Effect</th> <th align=\"left\">Quality</th> <th align=\"left\">Level</th> <th align=\"left\">Colour</th> <th align=\"left\">Faction Name</th> <th align=\"left\">Faction Value</th></tr>"; while($row = mysql_fetch_array( $result )) { $row_color = ($row_count % 2) ? $color1 : $color2; // Print out the contents of each row into a table echo " <tr> <td bgcolor=\"$row_color\">" . $row["name"] . "</td> <td bgcolor=\"$row_color\">" . $row["effect"] . "</td> <td bgcolor=\"$row_color\">" . $row["quality"] . "</td> <td bgcolor=\"$row_color\">" . $row["level"] . "</td> <td bgcolor=\"$row_color\">" . $row["colour"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionname"] . "</td> <td bgcolor=\"$row_color\">" . $row["factionvalue"] . "</td> </tr> "; $row_count++; } echo "</table>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////RANGED SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////FOOD SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "food" ) { echo "<font color=#ffffff>Dream on sunshine there aint no food adorns yet</font>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////FOOD SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////DRINK SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "drink" ) { echo "<font color=#ffffff>Dream on sunshine there aint no drink adorns yet</font>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////DRINK SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /////////////////////////////DRINK SLOT - START////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// elseif ( $slot == "ammo" ) { echo "<font color=#ffffff>Dream on sunshine there aint no ammo adorns yet</font>"; } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////DRINK SLOT - END//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// else { echo "<font color=#ffffff>Either you have clicked something stupidly or edited the url or there is a bug with this script. You should never see this error message. If you do please contact Sosia :No Slot Choosen</font>"; } ?> </center> </body> </html> This is a little confusing so please bear with me. I was thinking of using left.join but couldn't figure out how to implement it properly. I am trying to order all of the results from a table names 'clans' based on how many points the clan has. To calculate the points you have to go into another table 'clanteams' and then loop every team in the clan pulling wins and losses from a row in a specific ladder table. Here is the code i have to calculate the points. Code: [Select] $total[wins] = 0; $total[loss] = 0; $members=mysql_query("SELECT id,clanid,teamid,DATE_FORMAT(datejoined,'%M %d, %Y') FROM clanteams WHERE clanid='$member[id]'"); while(list($id,$clanid,$teamid,$joined)=mysql_fetch_row($members)){ $team=mysql_query("SELECT name,ladderid FROM teams WHERE id='$teamid'"); if(mysql_num_rows($team) == 0) continue; $team=mysql_fetch_array($team); $ladder=mysql_query("SELECT name FROM ladders WHERE id='$team[ladderid]'"); $ladder=mysql_fetch_array($ladder); $linfo=mysql_query("SELECT rank,wins,loss FROM ladder_$team[ladderid] WHERE teamid='$teamid'"); $linfo=mysql_fetch_array($linfo); $total[wins] = $total[wins] + $linfo[wins]; $total[loss] = $total[loss] + $linfo[loss]; } $totalpoints = ($total[wins] * 2) - $total[loss]; So now i want to loop through every row in the clans table, and using the above code oder them by $total points. Ive spent hours wrapping my head around it and still cannot figure it out. Please help. I am reading in a table and ordering it by a column labeled "sub" and generating an HTML table. The "sub" column entries are in numerical order (i.e. 1 2 3 4 5 6 7 8 10 11 12 etc. etc.). There are over 100 entries in this table as well. The problem I'm facing is probably obvious to some of you as the display is
1 Obviously I'd like the display to be in numerical order.
What can I do?
Ok I was wondering is there a way I can select a mysql database, and order it but only show data of a certain criteria: for example Mysql database: ID | User | XP | Won | Lost 1 Freid 100 1 4 2 Smic 300 5 4 3 Retna 300 3 2 4 OBW 200 3 2 And then some php code that will retrieve this information but only display the users that have lost = 4 in a list. In other words some php code that will only list the players Freid and Smic from the msql database becuase they have Lost = 4 the code would not show Retna or OBW becuase there Lost is not = to 4 Any help would be great thanks Freid001 I have 2 queries that I want to join together to make one row
I Have Taken The User_name In Session and i want to Make a Table as User_name as Prefix and When The User Logs in i want to show tht Table To the User !!!! 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 On my site, I currently have a page that lists my team's fixtures: http://www.cfrclunj.co.uk/fixtures.php As can be seen, in between each separate month there is a row of blank, grey cells. I am now updating the site so that it takes all information from a database (for easier update). On my test page (at bottom) I have recreated the fixtures table using my db: http://www.cfrclunj.co.uk/db_test.php What I am wondering is if there is any way to get the grey monthly separater row into my table. Could this be done by inserting a row of data into the db table that uses an if statement to change it's appearance? Or could I somehow use MYSQL/PHP to make it put a row in for each separate month? I have to admit my PHP and MYSQL skills are still at a very basic level, and so any help would be great! I wonder if anyone can help me, I have a MySQL table of football teams (team_name; link; description; rival_1; rival_2; rival_3;) where each 'team_name' has its own page with the relevant information from the table and is named as the link field from the table. Within each team page I also want to display the rival_1,2 and 3 teams with links to their pages. I know how to just display the information but am struggling with picking up the link from the relevant row in the table. Is this possible or would I be better off just placing a <a href> link around each rival team when I enter it into the MySQL table?? I hope this makes sense, any help would be very much appreciated. Thanks Hi, I'm using a table to list results from a MySQL query. I wanted to make the rows of the table alternate colours and found the following code on this website which does the job perfectly: $counter++; $bgcolor = ($counter % 2)?"#e8edff":"#ffffff"; echo "<tr class='border'>\n <td bgcolor='".$bgcolor."'>$n</td>\n <td bgcolor='".$bgcolor."'>$player</td>\n <td bgcolor='".$bgcolor."'>$score</td>\n </tr>\n"; On my webpage i have six tables listing results from six MySQL queries and i use the above code after each query to construct the table and alternately colour the rows blue then white. My problem arises when there are an odd number of rows in the first table. This results in the first row of the second table being coloured white, not blue. I would like the first row of each table to be blue. Is there a simple way to reset the counter for each table? Any advice much appreciated. Thanks. Hi all, So I'm not completely sure on how to do this, but basically this i what i want. I want the users to be able to create "fields" in my table, so let's say we have a structure like this: Field 1 Field 2 Field 3 Data 1 Data 2 Data 3 Problem is, that i want my users to update both the <td> and <tr> information via mysql, without altering the database. And I'm not sure on how I can make sure, that everything gets out in the right order. I have this so far: Code: [Select] <table id="sort-table"> <thead> <tr> <?PHP echo ' <td> Identifier </td> '; $result = mysql_query("SELECT * FROM fields ORDER BY `order`"); while($row = mysql_fetch_array($result)) { echo ' <td> ' . $row["name"] . ' </td> '; } ?> <th style="width:128px">Options</th> </tr> </thead> This will display the field 1, 2, 3 etc.. My problem is.. How do i get the content displayed in the right order to the right fields.. :/ I hope you understand me, if not, please tell me so I can elaborate ^_^ I know this might seems like a noob question, and I'm sorry that I couldn't search, but I didn't know what to search for. Hi all, I have a data base with the following table: ---member_data--- id ^ mid ^fieldname^ fieldvalue 1 - 2 - applicant - Seth Smith 2 - 4 - firstname - Chris 3 - 4 - lastname - Cooper 4 - 7 - full_name - Joey Jones 5 - 7 - occupation - Programmer 6 - 7 - phone - 800-555-1212 And below is a snippet that I use to display the selected members data for editing ------------------------------- <table> <tr> <td>Name:</td> <td>Value:</td> </tr> <?php $query = "SELECT * FROM member_data WHERE mid='$mid'"; $result= mysql_query($query); while($row = mysql_fetch_array($result)) { $fieldname = $row["fieldname"]; $fieldvalue = $row["fieldvalue"]; ?> <tr> <td><input type="text" name="<?php echo $fieldname;?>" value="<?php echo $fieldname;?>"></td> <td><input type="text" name="<?php echo $fieldvalue;?>" value="<?php echo $fieldvalue;?>"></td> <?php } ?> </tr> </table> ------------------------------- My question is: - using the Db example above: - lets say Ive selected mid#7 (member id 7) to edit which is displayed using the snippet code from above. - once displayed how do I edit mid#7 given the fact that mid#7 is located on 3 seperate rows from the same table? Thank you, Dave *ALSO - I tried the snippet below which did Not work. foreach($_POST as $key => $val) { $sql = "UPDATE member_data SET fieldname='$key', fieldvalue='$val' WHERE mid='$mid'"; $result = mysql_query($sql); } Hi, I'm very new to these forums and php alike. I've been working on this bit of code for weeks now. I've written numerous versions and made endless revisions; trying pieces from many similiar source and well, it's still not quite working out for me. The form I've been trying to finish will have multiple rows. The user will input values specific to each row, but I'm trying to make it so that each row is synonymous with each other in regard to the database table. Like an order form, an inventory form, or a roster. I'd really like to make this code work out because I can think of numerous applications for it's use. I'm sure others could use it for even more. So, as you see; the html code represents the table that contains the form. Currently, I only have five of these rows in the form, but would like for anybody using the code to be able to add in code for as many rows in the table as needed. Code: [Select] <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <FORM action="post_multiple.php" method="POST"> <table width="80%" border="1"> <tr> <td>Vendor</td> <td>Item Description</td> <td>Quantity</td> <td>Price</td> </tr> <tr> <td><select name="vendor" id="vendor" > <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> </table> <input type="submit" name="Submit" value="Submit" /> </FORM> </body> </html> In the php script I've tried using the count, loop, if, several others functions to try to get it to insert all the completed rows from the form into the table but just can't seem to get it to work out. Anyways, here's a representation of what i'd like to achieve. Not necessarily the code I've written trying to accomplish this, I'd have to upload a book if that were the case. <?php ini_set('display_errors','On'); error_reporting(E_ALL); $host="localhost"; // Host name $username="root"; // Mysql username $password="password"; // Mysql password $db_name="testing"; // Database name $tbl_name="test_multiple"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //declarations $vendor = $_POST['vendor']; $description = $_POST['description']; $quantity = $_POST['quantity']; $price = $_POST['price']; // Check if button name "Submit" is active, do this $sql1="INSERT INTO $tbl_name (vendor, description, quantity, price) VALUES ('".$vendor."', '".$description."', '".$quantity."', '".$price."')"; $result1=mysql_query($sql1); mysql_close(); ?> If anybody can suggest where I need to go with that, that would be great. Like I said above, I've tried about everything I could find any reason to from forum threads I had found in google searches and whatnot. Also, if there is a good article, link or tutorial that would address this that anybody knows about that would be great. However, I'm not looking for a link to a product or plugin that will do this stuff for me. I'm trying to get halfway decent at php and would like to have working code for myself to build upon, modify, and learn from. Any help is greatly appreciated!!!! I know how much you guys hate people asking for help without any starting code but I'm not even sure how to start this.. I want a script to read this page and count all the admins and referees. If anyone is willing to help, here's a sample of the html code: Code: [Select] <div class="boxInner"><h3>Arena Referees</h3><table class="list"><thead><tr><th style="width:16px;"></th><th style="width:150px;">Name</th><th style="width:300px;">Position</th><th style="width="150px;">Gamertag</th></tr></thead><tbody><tr><td><a href="http://gamebattles.com/profile/GottaHaveFaith78"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td><td class="alt1">Faith</td><td><b>Head Referee</B></td><td class="alt1">GB CombatBarbie</td></tr><tr><td class="alt2"><a href="http://gamebattles.com/profile/Jack.-"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td><td>Jack</td><td class="alt2"><b>Asst. Head Referee</b></td><td>Get Jacked x</td></tr><tr><td><a href="http://gamebattles.com/profile/amghawk"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td><td class="alt1">Mike</td><td><b>Asst. Head Referee (IS)</b></td><td class="alt1">GB amghawk</td></tr><tr><td class="alt2"><a href="http://gamebattles.com/profile/cory94bailly"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td><td>Cory</td><td class="alt2">Referee</td><td>Cory xz</td></tr><tr><td><a href="http://gamebattles.com/profile/crago"><img src="http://media.gamebattles.com/icons/16/profile.png" class="icon16" /></a></td> I'm just wondering how I could even count them. Any help will be appreciated, thanks. Hey. Third question today. Very stuck on this one. I am displaying a ton of while loops to display a bunch of data from two different tables. there is NO possible way i can combine the two tables. I mean, I can, but I'm not going to because they are two totally different thins. Anyway. Here is what I'm trying to do: Lets say I have 3 items, a grape, an orange and an apple. - 3 apples - 2 oranges - 1 grape I'm displaying an update price box for each different fruit. (so 3 different boxes), and one submit button. I update it, and it does update the price but it only updates the very first row. I want to be able to update every row I types the price in for. Here is my code: (it is quite long): Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<banner></banner><nav>$shownavbar</nav><ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar>$ubear</ubar><content><center><font size=6>User Shops</font><br><br>"; $action = $_GET['action']; if(!isset($action)) { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br>"; } if(isset($action)) { $getshopq = "SELECT * FROM usershops WHERE owner='$showusername'"; $getshop = mysql_query($getshopq); while($tri = mysql_fetch_array($getshop)) { $theid = $tri['ushopid']; $owner = $tri ['owner']; $desc = $tri['description']; $image = $tri['image']; $name = $tri['name']; $status = $tri['status']; $discount = $tri['discount']; } $countq = "SELECT * FROM usershops WHERE owner='$showusername'"; $countit = mysql_query($countq); if($action == "edit") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Edit Shop</font><br><br>"; if(mysql_num_rows($countit)) { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <?php } if(!mysql_num_rows($countit)) { $create = $_POST['create']; $thename = $_POST['thename']; $thedesc = $_POST['thedesc']; $thestatus = $_POST['thestatus']; $theimage = $_POST['theimage']; if(!isset($create)) { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> Shop Name: <input type="text" name="thename"><br>Description<br><textarea name="thedesc" rows="5" cols="25"></textarea><br> Status: <select name="thestatus"> <option>Open</option> <option>Closed</option> <option>Gallery</option> </select><br><br> <input type="submit" name="create" value="Create Shop"></form> <?php } if(isset($create)) { if($thename == "" || $thedesc == "") { echo "<font color=red>Error! Please fill out the entire form!</font><br><br>"; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> Shop Name: <input type="text" name="thename"><br>Description<br><textarea name="thedesc" rows="5" cols="25"></textarea><br> Status: <select name="thestatus"> <option>Open</option> <option>Closed</option> <option>Gallery</option> </select><br><br> <input type="submit" name="create" value="Create Shop"></form> <?php } if($thename != "" && $thedesc != "") { mysql_query("INSERT INTO usershops (owner, name, description, image, status, discount) VALUES ('$showusername', '$thename', '$thedesc', 'image.gif', '$thestatus', 'None')"); echo "<font color=green>Success! You have created your shop! Click <a href=?action=view>here</a> to view it.</font><br><br>"; } } } } if($action == "view") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Shop Name Here</font><br><br>"; $wowq = "SELECT * FROM uitems WHERE username='$showusername' AND location='2'"; $wow = mysql_query($wowq); while($wrow = mysql_fetch_array($wow)) { $umid = $wrow['uitemid']; $umiid = $wrow['theitemid']; $umloc = $wrow['location']; $umprice = $wrow['price']; $infoq = "SELECT * FROM items WHERE itemid='$umiid'"; $info = mysql_query($infoq); while($row = mysql_fetch_array($info)) { $myname = $row['name']; $myid = $row['itemid']; $myimage = $row['image']; $mydesc = $ow['description']; $myrarity = $row['rarity']; echo "$myname"; } } } if($action == "stock") { $setprice = $_POST['price']; $updateprice = $_POST['updateprice']; echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Stock Shop</font><br><br>"; $eq = "SELECT * FROM uitems WHERE username='$showusername' AND location='2' GROUP BY theitemid"; $ee = mysql_query($eq); while($erow = mysql_fetch_array($ee)) { $eeloc = $erow['location']; $eeid = $erow['theitemid']; $eenowid = $erow['uitemid']; $eeprice = $erow['price']; $wq = "SELECT * FROM items WHERE itemid='$eeid'"; $ww = mysql_query($wq); while($wrow = mysql_fetch_array($ww)) { $cq = mysql_query("SELECT * FROM uitems WHERE username='$showusername' AND location='2' AND theitemid='$eeid'"); $lcq = mysql_num_rows($cq); $fid = $wrow['itemid']; $fname = $wrow['name']; $fimage = $wrow['image']; $frarity = $wrow['rarity']; $fdesc = $wrow['description']; echo "$fname<br><img src=/images/items/$fimage>"; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="text" name="price" maxlength="5"><br><br> <?php } } if(isset($updateprice)) { mysql_query("UPDATE uitems SET price='$setprice' WHERE username='$showusername' AND theitemid='$fid'"); echo "<font color=green>Success! Your prices have been set and updated!</font>"; } ?> <input type="submit" name="updateprice" value="Update Prices"> <br> <?php } if($action == "quick") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Quick Stock</font><br><br>"; } } } ?> </html> To help you find it, I'm asking about the "stock" $_GET part, about three quarters down. Thanks in advance for anybody who can help me, I've been stuck on this script all day! Thanks again! Hi, I have a problem regarding counting rows in a mysql table. Here is the code: Code: [Select] <?php require_once('includes/connection.inc.php'); $conn = dbConnect('read'); $check = 'SELECT COUNT(*) FROM images'; $checkRes = $conn->query($check) or die(mysqli_error()); if($checkRes <= 0) { header('Location: empty_blog.php'); // redirect to another page } else { // do something else... } ?> The error I'm getting: "Notice: Object of class mysqli_result could not be converted to int in C:\xampp\htdocs\photoblog\index.php on line 6" Any help is greatly appreciated! i'm trying to echo out the results from a query onto a page, but rather than having them echo out as rows in a table, i want them to be displayed in columns, i.e. first column would have the first 10 results and the second column would have the next to. Any ideas on how i could do this? at the moment i'm using this code to display my results $read=mysql_query("SELECT * FROM entry WHERE category_id=".$id." ORDER BY entry_title") or die("query failed".mysql_error()); $result=mysql_num_rows($read); for($j = 0; $j < $result; $j++) { $row = mysql_fetch_array($read); echo "<a href=article.php?id=".$row['entry_id']. ">".$row['entry_title']."</a><br />"; } but this just displays it as a list down the middle thanks <?php $servername = "xxx"; $username = "xxxx"; $password = "xxxx"; $dbname = "web216-admin-6d5"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $class_id = $_POST['class_id']; // This value is from a dropdown $checkbox = $_POST['checkbox']; // This is a checkbox next to each record $user_id = $_POST['user_id']; // this is a hidden value output from the database (in a textbox) if(isset($_POST['submit'])) { for($i=0;$i<count($checkbox);$i++){ $query="INSERT INTO Class_List(user_id,class_id)VALUES('".$user_id[$i]."','".$class_id."')"; if (mysqli_query($conn, $query)) { echo "The selected records have been added successfully !"; echo "<meta http-equiv=\"refresh\" content=\"2;url=search_courses.php\"/>"; } else { echo "Error: " . $sql . ":-" . mysqli_error($conn); } mysqli_close($conn); } ?> Hi, I am trying to figure out how to insert the following values into another table if they have a checked box:
$class_id = $_POST['class_id']; // This value is from a dropdown on the top of the page basically, each row in the table has a checkbox If the checkbox is checked then it should insert the user_id field from the checked rows and the value from a drop down (class_id) at the top of a page into another table. I have managed the code up to here but I need a tutorial or guidance to do the rest. At the moment I am getting error HTTP 500 I understand that the code is subject to sql injection, but will sort that out later Edited August 11, 2020 by PythonHelp |