PHP - Colouring Alternate Table Rows
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. Similar TutorialsHi guys, I would like to know on How to alternate table row colors in Php Mysql result? CSS or Html? Thanks Code: [Select] <? $result = mysql_query("SELECT * FROM tbl_sta WHERE fiesta_date > '$now' ORDER BY sta_date LIMIT 5"); echo "<table id='table1' cellspacing='1' cellpadding='3'> <tr> <th>Upcoming Fiesta</th> </tr>"; while($row = mysql_fetch_array($result)){ $date = date("l, F j ",strtotime($row["sta_date"])); echo "<tr>"; echo "<td><a href='fiestasd.php' style='font-size:12px;font-weight:bold;'>" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "</a> <br /> $date </td>"; echo "</tr>"; } echo "</table>"; ?> Thank you.. more power phpfreaks! I have 2 queries that I want to join together to make one row
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 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. 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, 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! 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!!!! 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. 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); } 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! I'm trying to set different colors on rows of a table using an array, Problem is I cannot get it to work right, i'm not sure where to place my for loop so that it works right and generates a different color for different row. Code: [Select] $color = array(red,green,blue); while ($row = mysql_fetch_assoc($exec)) { echo '<tr>'; echo '<td>'.$row['brand_name'].'</td>'; echo '<td>'.$row['contact_name'].'</td>'; echo '<td>'.$row['contact_info'].'</td>'; echo '<td>'.$row['email'].'</td>'; echo '<td>'.$row['description'].'</td>'; echo '</tr>'; } I tried putting for loop only for tr, but it didnt work. Code: [Select] for ($i=0;$i<=count($color);$i++) { echo "<tr bgcolor=\"".$color[$i]."\">"; } I cannot put it within the while loop, it'll repeat the rows for all the colors. So where exactly do I place the for loop so that it works right? I'm racking my brain trying to figure out the most effective way (any way) to insert some information into a table if it hasn't been previously inserted. Here's a simplified sample that I'm working with: -- Column 1 Column 2 Coloumn3 Sue Cat Adopted Jack Dog Adopted Cujo Dog Not Adopted -- The column I'm trying to scrub my loop against is column 3. Here's what I have so far... <?PHP $question = "ADOPTED"; $res = mysql_query("SELECT file FROM temp_data"); while($rw = mysql_fetch_array($res)){ $arr[] = $rw['file']; if (in_array($question, $arr)){ echo "ADOPTED"; //Leave it alone... } else { echo "NOT ADOPTED<br />"; //Insert My New Data } ?> I think I'm on the right path by using the 'in_array' function to check if '$question' variable is within the the '$arr' array, however, logically (to me) it makes sense but it is not working. Suggestions? I should also mention that I'm not receiving any error messages but rather, a completely inaccurate result instead. 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 ok, I'm not sure I know how to ask this question, but I've created a table that allows the user to add rows. The problem is, upon submit only the last row creates variables. How can I make sure every cell in every row sets a different variable? This is going to be a purchase order system. Here is my code: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Insert Table Row using DOM</title> <script language="javascript"> function addRow() { var tbody = document.getElementById("po_table").getElementsByTagName("tbody")[0]; var row = document.createElement("TR"); var cell1 = document.createElement("TD"); var cell2 = document.createElement("TD"); var cell3 = document.createElement("TD"); var inp1 = document.createElement("INPUT"); inp1.setAttribute("type","text"); inp1.setAttribute("name","quantity"); cell1.appendChild(inp1); var inp2 = document.createElement("INPUT"); inp2.setAttribute("type","text"); inp2.setAttribute("name","description"); cell2.appendChild(inp2); var inp3 = document.createElement("INPUT"); inp3.setAttribute("type","text"); inp3.setAttribute("name","unit_cost"); cell3.appendChild(inp3); row.appendChild(cell1); row.appendChild(cell2); row.appendChild(cell3); tbody.appendChild(row); //alert(row.innerHTML); } </script> </head> <body> <form method="post" action="review_po.php"> <table id="po_table" border="1"> <tbody> <tr> <th bgcolor="#c1c1c1">Quantity</th> <th bgcolor="#c1c1c1">Description</th> <th bgcolor="#c1c1c1">Unit Cost</th> </tr> <tr> <td><input type=text name="quantity"></td> <td><input type=text name="description"></td> <td><input type=text name="unit_cost"></td> </tr> </tbody> <tfoot> <tr> <th bgcolor="#e0e0e0">1</th> <th bgcolor="#e0e0e0">Shipping</th> <td><input type=text name="shipping"></td> </tr> <tr> <th bgcolor="#e0e0e0">1</th> <th bgcolor="#e0e0e0">Tax</th> <td><input type=text name="tax"></td> </tr> </tfoot> </table> <input type="button" value="Insert Row" onClick="addRow();"> <input type="submit" value="Review" name="review_po"> </form> </body> </html> right now it goes to this page: Code: [Select] <?php //convert to variables $quantity = $_POST['quantity']; $description = $_POST['description']; $unit_cost = $_POST['unit_cost']; $extended_cost = $_POST['extended_cost']; $shipping = $_POST['shipping']; $tax = $_POST['tax']; ?> <?php echo $quantity; ?><br> <?php echo $description; ?><br> <?php echo $unit_cost; ?><br> <?php echo $extended_cost; ?><br> <?php echo $shipping; ?><br> <?php echo $tax; ?><br> here is the page: http://po.shopphgmag.com/create_po.html Thanks for looking Here is a link to the website I am designing. http://173.167.65.189/singleton/ the username and password is ksingleton at the bottom where the calendar is the query is searching for scheduled events, i am only posting the company_id right now, the problem I am having is I want a scheduled event that continues through the week to stay in line with the one before. But if the schedule before ended and a new one continues it moves the next date company_id up. How can i align the table rows or create an empty table row on all other days if there was a schedule before. here is the code for the calendar. Quote <?php $db = new mysqli(); $setdate=strtotime($_GET['date']); $session=$_GET['session']; $calview=$_GET['calview']; if ($setdate <> "") { $date=$setdate; } else { $date=time(); } $day=date('d',$date); $month=date('m',$date); $year=date('Y',$date); $first_day=mktime(0,0,0,$month,1,$year); $title=date('F',$first_day); $day_of_week = date('D', $first_day); switch($day_of_week) { case "Sun": $blank = 0;break; case "Mon": $blank = 1;break; case "Tue": $blank = 2;break; case "Wed": $blank = 3;break; case "Thu": $blank = 4;break; case "Fri": $blank = 5;break; case "Sat": $blank = 6;break; } $days_in_month = cal_days_in_month(0, $month, $year); echo "<table cellpadding=0 cellspacing=0 border=0>"; echo "<tbody>"; echo "<tr>"; echo "<td><a href=?session=$session&calview=day>Day</a></td>"; echo "<td><a href=?session=$session&calview=week>Week</a></td>"; echo "<td><a href=?session=$session&calview=month>Month</a></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=3>"; if ($calview=="month") { echo "<table border=1 width=800>"; echo "<tbody>"; echo "<tr height=25><th colspan=7> $title $year </th></tr>"; echo "<tr height=25><td width=58 align=center>Sunday</td><td width=58 align=center>Monday</td><td width=58 align=center>Tuesday</td><td width=58 align=center>Wednesday</td><td width=58 align=center>Thursday</td><td width=58 align=center>Friday</td><td width=58 align=center>Saturday</td></tr>"; $day_count = 1; echo "<tr height=50>"; while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } $day_num = 1; while ($day_num <= $days_in_month ) { $newdate = $month ."/". $day_num ."/". $year; $msqlnewdate = date('m/d/Y',strtotime($newdate)); echo "<td valign=top><table cellpadding=0 cellspacing=0 border=0><tr><td><a href=?session=$session&calview=day&date=$newdate> $day_num </a></td></tr>"; $db = new mysqli('localhost','username','password', 'rsdata'); if (!$db) { echo 'ERROR: Could not connect to database.'; } else { $query = $db->query("SELECT * FROM rentals WHERE date_format(str_to_date(pdate_out,'%Y-%m-%d'), '%m/%d/%Y') <= '$msqlnewdate' AND date_format(str_to_date(pdate_in, '%Y-%m-%d'), '%m/%d/%Y') >= '$msqlnewdate'"); if ($query) { while ($result = $query->fetch_object()) { echo "<tr><td>".$result->company_id."</td></tr>"; } } echo "</table>"; } $day_num++; $day_count++; if ($day_count > 7) { echo "</tr><tr>"; $day_count=1; } } while ($day_count >1 && $day_count <=7 ) { echo "<td></td>"; $day_count++; } echo "</tr></table>"; } else if ($calview=="week") { } else { } echo "</td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; ?> MOD EDIT: DB credentials edited out. <?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 PythonHelpThis topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=343705.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355753.0 Hello,
I am trying to check whether the values in rows are equal or same?
I have two tables orders and line_items. I will store more than 1 line items in line_items table with the same order_id getting from orders table. In line items if i have 3 line items for same order_id, when each line items gets dispatched i will set the status to 'Dispatched' in line_items table. When all the 3 becomes 'Dispatched', i will update the order status as 'Completed' in orders table.
Now i am not getting how to check whether all the 3 line items status id 'Dispatched'.
I tried doing like this
$q1 = "select orders.order_id, orders.item_status as istatus, orders.status as ostatus, orders.authorise, line_items.order_id, line_items.status as bstatus, COUNT(line_items.id) as bid from orders inner join line_items on orders.order_id=line_items.order_id where line_items.order_id=".$id." AND line_items.id<>'Dispatched'"; $q2 = mysql_query($q1); while($q3 = mysql_fetch_array($q2)) { echo $q3['bstatus']; if($q3['bstatus']==''); { echo "HELLLOOOO"; } }But its not working. It goes into if loop even if a single value is 'Dispatched' Please help me. |