PHP - Problem Adding Information At The End Of The Table Or At The Beginning Of The Table
hi... i have a table ... i add and remove data in the table...when i add new record , information add to center of the table ! whats problem? i want add data in first of table. please guide me.thanks
Similar TutorialsHello guys, im using this code atm and it's working, but the new rows created are put in the end of the table. I want them to stack up from the beginning pushing older rows down. What should i do to make that work? <?php $con = mysql_connect("localhost","*****","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ananaz_se", $con); $sql="INSERT INTO stuff (adult, namn, url) VALUES ('$_POST[adult]','$_POST[namn]','$_POST[url]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 row added"; mysql_close($con) ?> Hi Everyone, I'm trying to figure out a way to put my MySql data into a table. I'm close to getting this completed by I'm having some trouble. The data I'm inserting isn't being put into the correct tables. I'm not quite sure what I'm doing wrong. Any help? http://whatsmyowncarworth.com/practice/table.php Code: [Select] <?php include('init.php'); $result = mysql_query("SELECT * FROM info") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Last Name</th> <th>Address</th> <th>City</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['first_name']; echo "</td><td>"; echo $row['last_name']; echo "</td></tr>"; echo "<tr><td>"; echo $row['address']; echo "</td><td>"; echo $row['city']; echo "</td></tr>"; } echo "</table>"; ?> Hi, I have two variables: $latest_note and $notes. Whenever I update $latest_note, I also want this (and today's date) to be added to $notes, such that $notes becomes a sort of archive of all of the latest notes, listed by date. I tried creating a third variable called $full_notes and saying $full_notes = $latest_note.$notes; ... then when I run my mysql update, I set notes='$full_notes' but it's not working properly. Is there a way to simply add one variable to the beginning of another in the db directly, concatenating the two? Thanks! Hi, I am very new to php and im trying to work out a bit of code... I googled for help but im just stuck at this point... <input type="text" name="rates1" value="<?php echo $rates; ?>"> How can I echo rates1 to reflect whats in a table... Thanks in advance... Have never done this before, but I'm sure many of you have. What I am trying to do is take the information that the user fills out in this form and when they hit submit, it will be displayed into a html table on the next page. I don't need someone to do the entire table for me, just looking for some help to get started and a general idea of what to do. Here is my code for my form that I have created... 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> <title>Lab 4</title> </head> <body> <?php ?> <form method="POST" action="lab4form.php"> <label for="first_name">First Name:</label> <input type="text" id="first_name" name="first_name" /><br /> <label for="last_name">Last Name:</label> <input type="text" id="last_name" name="last_name" /><br /> <label for="coverage_amount">Coverage Amount:</label> <input type="text" id="coverage_amount" name="coverage_amount" /><br /> <label for="gender">Gender:</label> <br> <input id="male" type="radio" value="radiobutton" name="male" /> <label for="male">Male</label> <input id="female" type="radio" value="radiobutton" name="female" /> <label for="female">Female</label> <br /> <br> <label for="Age">Age:</label> <input type="text" id="age" name="age" /><br /> <br> <label for="health">Health Conditions</label> <br /> <input type="checkbox" name="health" value="heart" /> <label for="health">Heart Disease</label><br /> <input type="checkbox" name="health" value="diabetes" /> <label for="health">Diabetes</label><br /> <input type="checkbox" name="health" value="blood" /> <label for="health">High Blood Pressure</label><br /> <input type="checkbox" name="health" value="Smoker" /> <label for="health">Smoker</label><br /> <input type="checkbox" name="health" value="lung" /> <label for="health">Lung disease</label><br /> <FORM METHOD=POST ACTION="lab4form.php"> <P>Employment Status<BR> <SELECT NAME="employment"> <OPTION VALUE="lab4form.php">Unemployed <OPTION VALUE="lab4form.php">Full-Time <OPTION VALUE="lab4form.php">Part-Time <OPTION VALUE="lab4form.php">Student </SELECT><br /> <br> <label for="comments">Comments</label> <input type="text" id="comments" name="comments"/><br /> <br> <input type="submit" value="Add User" name="btn_add" /> </form> </body> </html> Hi all, I'm working on a webpage that dynamically shows sales of products over a number of years. It's going well apart from the data isn't showing as I want it to. The data is showing the number of sales per month in a given year. What I want to do is add up all sales of the same product within a year to give one row for each product for each year. The below screenshot shows what my current output is. I want to be able to have one row showing sales all year rather than month by month. Code: [Select] <?php error_reporting(E_ERROR | E_PARSE); $desiredProduct = $_POST['product']; $server = 'SQL2008'; $connectionInfo = array( "Database"=>"rde_400792"); $conn = sqlsrv_connect($server,$connectionInfo); $describeQuery="select ProductCode , SalesVolume, Year, Month from MonthlySales where ProductCode = $desiredProduct"; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Product Code</th><th bgcolor = "LightBlue" >Sales Volume</th><th bgcolor = "LightBlue">Month</th><th bgcolor = "LightBlue">Year</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['ProductCode'].'</td>'; echo '<td>' .$row['SalesVolume'].'</td>'; echo '<td >' .$row['Month'].'</td>'; echo '<td>' .$row['Year'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Can somebody help me? I have a store number that i want to add and echo. This resembles an invoice so i my table has unit_price and total_value which is defined by by multiplying unit_price and pieces. Now that i want to print invoice i want to know how to add all items that are from that invoice_id Code: [Select] //get the total value for order $sql_value = "SELECT total_value FROM `".TABLE_ORDERDETAILS."`WHERE order_id = $record_order[order_id]"; $rows_value = $db->fetch_all_array($sql_value); foreach($rows_value as $record_value){ $value = $record_value[total_value]; } I am trying to add a line to a table (actually a shopping cart) at the moment there is a box around the word Checkout and the lines are too close. I've tried adding in a line using <tr> at the beginning and then </tr> at the end but am having no luck I am completely new to any kind of coding what so ever so i'm sorry if it is a dumb question. At the moment the coding round the checkout is: <td id='cart-widget-links' colspan="5"> <a target="_parent" href="<?php echo get_option('shopping_cart_url'); ?>" title="<?php _e('Checkout', 'wpsc'); ?>" class="gocheckout"><?php _e('Checkout', 'wpsc'); ?></a> <form action="" method="post" class="wpsc_empty_the_cart"> <input type="hidden" name="wpsc_ajax_action" value="empty_cart" /> <a target="_parent" href="<?php echo htmlentities(add_query_arg('wpsc_ajax_action', 'empty_cart', remove_query_arg('ajax')), ENT_QUOTES, 'UTF-8'); ?>" class="emptycart" title="<?php _e('Empty Your Cart', 'wpsc'); ?>"><?php _e('', 'wpsc'); ?></a> If anyone can help be I would really really appreciate it... I can beg if you want Megan Can someone five me the correct code or format to use that will allow my TINYINT columns to carry TWO decimal places when creating my table? I have a script for creating the table and columns, but only recently learned that I need to ADD the TWO decimal place FUNCTION in order to get whole dollar values to display WITH the trailing zeros (ie.:2.00). I don't expect to need any values greater than xxx.xx in my columns, I'm just not clear on how to get the desired script when running the initial CREAT script. Thanks I have MySQL table with the following fields: user=>varchar product=>varchar Amount=>int Date=>date Note=>tinytext I can't add value to these field by the following php code: $date = date("Y.m.d"); $query = "INSERT INTO order VALUES ('farhad', 'Mango', '10', '$date', 'hello')"; $result = mysql_query($query) or die(mysql_error()); I receive the following warning: Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead in C:\inetpub\wwwroot\Okern\~order.php on line 10 Call Stack: 0.0047 325856 1. {main}() C:\inetpub\wwwroot\Okern\~order.php:0 0.0274 344912 2. date() C:\inetpub\wwwroot\Okern\~order.php:10 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order VALUES ('farhad', 'Mango', '10', '2011.04.17', 'hello')' at line 1 Im not much of a coder, and I obviously did this wrong since it is not working. Im trying to bring a new field value in to an existing php file. I created a new table, and an admin page to control that field. I cant, however, figure out how to use that value in a different php file. Actually, there are 2 files. Each using a different field from that new table. I will post what my current code is below with the additions I tried to add. I bolded the lines that contain the tags Im trying to use. Any and help you can give in fixing this to make it work is greatly appreciated. Code: [Select] <?php # INCLUDE ALL NECESSARY FILES. include_once("Constants.php"); include_once("Database.php"); include_once("SiteSetting.php"); [b]$query = "SELECT arcade_multiplier FROM tbl_point_rewards"; mysql_query($query) or die("Invalid query". mysql_error() ); $result = mysql_fetch_array($result); $arcade_multiplier = $result["arcade_multiplier"];[/b] $dbObj = new database(); # SAVE ARCADE GAME POINTS INTO THE DATABASE function saveGamePoints( $game_id, $user_id, $game_score, $calculate_score_flag, $play_date ){ global $dbObj; $user_max_plays = getUserMaxPlaysLimit( $user_id, $game_id ); //$_SESSION["arcade_game"]["save_score"] = ($user_max_plays < $_SESSION["arcade_game"]["max_plays"]) ? "yes" : "no" ; if($user_max_plays < $_SESSION["arcade_game"][$_SESSION["url_gameid"]]["max_plays"]){ $total_points = calculatePointRatio($game_id, $game_score); //$total_points = $game_score; $x_gameid = md5($game_id); if($_SESSION["arcade_game"][$x_gameid]["play_time"] > 0){ $playTime['start'] = $_SESSION["arcade_game"][$x_gameid]["play_time"]; $playTime['end'] = time(); $playTime = ($playTime['end'] - $playTime['start']); } else { $playTime = 0; } # update total points into main score [b] $update_sql = "update tbl_users set points_gained = (points_gained+(".ceil($total_points)." * $arcade_multiplier)) where usrid={$user_id}";[/b] $rs = mysql_query($update_sql) or die("Invalid query: {$update_sql} - ". mysql_error()); $table = "tbl_arcade_game_score"; $fields = array("game_id", "user_id", "game_score", "calculate_score_flag", "play_date", "game_time"); $values = array($game_id, $user_id, $game_score, $calculate_score_flag, $play_date, $playTime); // return $dbObj->cgi( $table, $fields, $values, 1 ); $insertid = $dbObj->cgi( $table, $fields, $values, "" ); $ceiling_point = getCeiling($game_id); if($game_score >= $ceiling_point) { $chk_authourity = isAlreadyTrophyOwner($user_id, $game_id); //if($chk_authority < 1) if($chk_authourity < 1) { # store award details into the database (tbl_trophy_award) //$trophy_id = getTrophy( $game_id ); $trophy = getTrophyDetails($game_id); $trophy_id = $trophy['ctoon_id']; $tbl_fields = array('userid', 'game_id', 'award_date', 'trophy' ); $tbl_values = array($user_id, $game_id, $play_date, $trophy_id ); $insert_tbl_trophy_award_id = $dbObj->cgi('tbl_trophy_award', $tbl_fields, $tbl_values , "" ); # award trophy to user (tbl_users_ctoons) $table = "tbl_users_ctoons"; $fl = array("usrid", "ctoon_id", "del_status", "ctoons_auction", "auction_id", "location", "batpts"); $vl = array($user_id, $trophy_id, '0', '', 0, 1, 0); $dbObj->cgi($table, $fl, $vl , "" ); # send a pm to the user about the trophy include_once("send_pm_message.php"); $game = getGameDetails($game_id); $msgSub = "Grats! You just got a trophy!"; $message = "Grats! You got the ".$trophy["toon_name"]." trophy for the ".$game["game_name"]." game!<br> <img src=\"{$game['path']}\">"; //echo $message; //echo "<br><hr><br>"; sendMessage($user_id, 0, 0, $msgSub, $message, 1); sendMessage(2034, $user_id, 0, $msgSub, $message, 1); } } return $insertid; } }//end function function getCeiling($game_id) { $sql = "SELECT ceiling FROM tbl_game WHERE game_id = '".$game_id."'"; $rs = mysql_query($sql); $result = mysql_fetch_assoc($rs); return $result['ceiling']; } function isAlreadyTrophyOwner($user_id, $game_id) { $sql = "SELECT * FROM tbl_trophy_award WHERE game_id = {$game_id} and userid = {$user_id}"; $rs = mysql_query($sql); $num_rows = 0; $num_rows = mysql_num_rows($rs); if($num_rows > 0) { return $num_rows; } else { return $num_rows; } } # calculate game ratio function calculatePointRatio($game_id, $game_score){ //return $game_score; $sql = "select gs.* from arcade_game_setting as gs where gs.game_id={$game_id}"; $rs = mysql_query($sql) or die( "Invalid query". mysql_error() ); if($rs){ $row = mysql_fetch_array($rs); switch($row["calculation_type"]){ case "divide": $x_score = round($game_score / $row["r_no"]); break; case "multiply": $x_score = round($game_score * $row["r_no"]); break; default : $x_score = ceil($game_score); break; }//switch $row["r_no"]; if($row["game_cap"] > 0){ if($x_score > $row["game_cap"]){ $x_score = $row["game_cap"]; } } return $x_score; }//if }// end function # get user total plays function getUserMaxPlaysLimit($user_id, $game_id){ global $d_start_time, $d_end_time; $sql = "select * from tbl_arcade_game_score where user_id={$user_id} and game_id={$game_id} and play_date between {$d_start_time} and {$d_end_time}"; $rs = mysql_query($sql) or die("Invalid query :". mysql_error() ); if($rs){ return mysql_num_rows($rs); }//if } # get game details function getGameDetails($game_id){ $sql = "select g.game_id, g.game_name, g.award_ctoonid, c.toon_name, c.toon_cat, c.toon_subcat, c.toon_small_img from tbl_game as g, tbl_ctoon as c where g.game_id = {$game_id} and g.award_ctoonid=c.ctoon_id"; $rs = mysql_query($sql); if($rs){ $row = mysql_fetch_array($rs); if($row['toon_cat']!="" && $row['toon_subcat']!=0) $tpth="imgtoon/".$row['toon_cat']."/".$row['toon_subcat']."/thumb"; elseif($row['toon_cat']!="" && $row['toon_subcat']==0) $tpth="imgtoon/".$row['toon_cat']."/thumb"; $game["game_name"] = $row["game_name"]; $game["award_ctoon_id"] = $row["award_ctoonid"]; $game["toon_name"] = $row["toon_name"]; $game["path"] = SITEROOT ."/" . $tpth ."/" . $row["toon_small_img"]; return $game; } else { return false; } } # send pm message to winner function sendPMToWinner($user_id, $game_id, $game_score){ include_once("send_pm_message.php"); $g = $game_id; //$point_prize = calculatePointRatio($game_id, $game_score); $point_prize = $game_score; $game = getGameDetails($game_id); //# select ctoon //$sql = "select award_ctoonid from tbl_game where game_id=".$g; //$rsctoon = mysql_query($sql) or die("Invalid query: {$sql} - ". mysql_error()); //$row_ctoon = mysql_fetch_array($rsctoon); //$ctoon_id = $row_ctoon["award_ctoonid"]; //# award ctoon //$insert_user_ctoon = "insert into tbl_users_ctoons (usrid, ctoon_id, del_status, ctoons_auction, auction_id, location, batpts) //values('{$user_id}', '{$ctoon_id}', '0', '', '', '1', '0')"; //mysql_query($insert_user_ctoon) or die("Invalid insert query:".mysql_error() ); //# update points $update_points_sql = "update tbl_users set points_gained = (points_gained+1500) where usrid={$user_id}"; mysql_query($update_points_sql) or die("Invalid updates points query". mysql_error() ); $dbObj = new database(); $msgSub = "Grats! You got a Top Score for ".$game["game_name"]." !"; $message = "Grats! You had one of the Top 10 scores in the ".$game["game_name"]." game last month, and got a 1500 point bonus!<br>"; //<img src=\"{$game['path']}\">"; // echo $message; // echo "<br><hr><br>"; sendMessage($user_id, 0, 0, $msgSub, $message, 1); } /** * function getTrophy( $game_id ) * @param $game_id */ function getTrophy( $game_id ){ $sql = "select award_ctoonid from tbl_game where game_id=".$game_id; $rs = mysql_query( $sql ) or die( mysql_error() ); if( $rs ){ $row = mysql_fetch_assoc( $rs ); } return $row["award_ctoonid"]; } // Updated function from above // Will get more information about the trophy function getTrophyDetails($game_id) { $sql = "select b.ctoon_id,b.toon_name,b.toon_small_img from tbl_game as a,tbl_ctoon as b where a.game_id = '$game_id' and b.ctoon_id = a.award_ctoonid LIMIT 1"; $rs = mysql_query( $sql ) or die( mysql_error() ); if( $rs ){ $row = mysql_fetch_assoc( $rs ); } return $row; } ?> Code: [Select] <?php include_once("Constants.php"); include_once("Database.php"); include_once("SiteSetting.php"); /**************************************************/ # SAVE DONETION IN DATABASE # @param $uid # @param $donation_amt /**************************************************/ function saveDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type){ if($transaction_id != "") { $flag = checkExist($uid); if($flag > 0){ updateDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type); }else{ addDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type); } } } /**************************************************/ /**************************************************/ # CHECK IS RECORD EXITS IN DONETION TABLE # @param $uid /**************************************************/ function checkExist($uid){ $dbObj = new database(); $sql = "select user_id from tbl_donation where user_id={$uid}"; $dbObj->myquery($sql); if($dbObj->row_count > 0){ return $dbObj->f_user_id; }else{ return 0; } } /**************************************************/ /**************************************************/ # INSERT DONETION RECORD IN tbl_donation # @param $uid # @param $donation_amt /**************************************************/ [b]$query = "SELECT arcade_multiplier FROM tbl_point_rewards"; mysql_query($query) or die("Invalid query". mysql_error() ); $result = mysql_fetch_array($result); $arcade_multiplier = $result["arcade_multiplier"];[/b] function addDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type){ $dbObj = new database(); $months = floor($donation_amt / 5); $exp_time = mktime(date("H"),date("i"),date("s"),date("m") + $months,date("d"),date("Y")); $fields = array("transaction_id", "subscr_id", "user_id", "donation_amt", "donation_date", "exp_date", "donation_type", "transaction_details"); $values = array($transaction_id, $subscr_id, $uid, $donation_amt, time(), $exp_time, $type, serialize($_SESSION["recurring_td"])); # update points [b]$update_points_sql = "update tbl_users set points_gained = (points_gained+(($donation_amt / 5) * $donation_pts)) where usrid={$uid}";/[b] mysql_query($update_points_sql) or die("Invalid updates points query". mysql_error() ); if($donation_amt < 5){ // The user donated less than $5 }else{ upgradeAccount($uid); } return $dbObj->cgi("tbl_donation", $fields, $values, false); } /**************************************************/ /**************************************************/ # UPDATE EXISTING DONETION RECORD # @param $uid # @param $donation_amt /**************************************************/ function updateDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type){ if(strlen($subscr_id) > 0){ $cd = " AND subscr_id='".$subscr_id."'"; } $sql_select = "select exp_date, donation_amt from tbl_donation where user_id=".$uid; //$sql_select = "select exp_date, donation_amt from tbl_donation where user_id=".$uid." and donation_type like '%recurring%'"; $rs_select = mysql_query($sql_select) or die("Invalid query".mysql_error()); if($rs_select){ $row = mysql_fetch_array($rs_select); $expdt = $row["exp_date"]; $damt = ($row["donation_amt"] + $donation_amt); $months = floor($donation_amt / 5); $exp_time = mktime(23, 59, 59, date("m",$row["exp_date"]) + $months, date("d", $row["exp_date"]), date("Y", $row["exp_date"])); } $dbObj = new database(); $sql = "update tbl_donation set transaction_id='".$transaction_id."', donation_amt=(donation_amt + {$donation_amt}), donation_date = ".time().", exp_date=".$exp_time.", donation_type='".$type."', transaction_details='".serialize($_SESSION["recurring_td"])."' where user_id={$uid}"; # update points [b]$update_points_sql = "update tbl_users set points_gained = (points_gained+(($donation_amt / 5) * $donation_pts)) where usrid={$uid}";[/b] mysql_query($update_points_sql) or die("Invalid updates points query". mysql_error() ); $dbObj->myquery($sql, 1); if($donation_amt < 5){ // The user donated less than $5 }else{ upgradeAccount($uid); } } /**************************************************/ /**************************************************/ # UPDATE EXISTING RECURRING DONETION RECORD # @param $uid # @param $donation_amt /**************************************************/ function updateRecurringDonetion($subscr_id, $transaction_amt){ $sql_subscr = "select donation_id, transaction_id, user_id from tbl_donation where subscr_id = '".$subscr_id."'"; $rs_subscr = mysql_query($sql_subscr) or die("Invalid query".mysql_error()); if(strlen($rs_subscr) > 0){ $row_subscr = mysql_fetch_assoc($rs_subscr); $uid = $row_subscr["user_id"]; $donation_amt = $transaction_amt; $transaction_id = $row_subscr["transaction_id"]; $subscr_id = $subscr_id; $type = "Recurring"; updateDonetion($uid, $donation_amt, $transaction_id, $subscr_id='', $type); } } /**************************************************/ /**************************************************/ # UPDATE USER STATUS FROM STANDERED TO PREMIUM # @param $uid /**************************************************/ function upgradeAccount($uid){ $dbObj = new database(); $sql = "UPDATE tbl_users SET acc_type = 'P' WHERE usrid={$uid} LIMIT 1 "; # update points $update_points_sql = "update tbl_users set points_gained = (points_gained+0) where usrid={$uid}"; mysql_query($update_points_sql) or die("Invalid updates points query". mysql_error() ); $dbObj->myquery($sql, 1); }//function upgradeDonation($uid) ?> Hi, I'm making a website that uses data stored in SQL. One of my pages allows the user to enter a new product into a product table. I was wondering if somebody could help me with some validation or Query that will not allow the user to enter a product name that already exists in the table? Code: [Select] $nameNew = $_POST['new]; $nameID = $_POST['newID]; $namePrice = $_POST['newPrice]; INSERT INTO products VALUES ($nameNew, $newID, $newPrice) $describeQuery = "SELECT ID, Name, Price FROM Products"; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Name</th><th bgcolor = "LightBlue" >ID</th> <th bgcolor = "LightBlue" >Price</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['Name'].'</td>'; echo '<td>' .$row['ID'].'</td>'; echo '<td>' .$row['Price'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Thanks As I title says; I need to have an image showed the number of times, the value of a table/field.. How can I do this? I'm reading through this book which is actually not bad but, on page 286 there's a shopping_cart.php code (which I downloaded from the web site). The code that seems relevant to me is this: <?php $totalPrice = 0; foreach ( $_SESSION["cart"] as $product) { $totalPrice += $product->getPrice(); //<<<LINE 94 ?> The error I get is Fatal error: Call to a member function getPrice() on a non-object in C:\usr\web\shopping_cart.php on line 94 Should $product be a cast to the Product object? class Product { private $productId; private $productName; private $price; public function __construct( $productId, $productName, $price ) { $this->productId = $productId; $this->productName = $productName; $this->price = $price; } public function getPrice() { return $this->price; } //etc. } Hi all, just to get this out of the way i have now been working on html / css / php / mysql coding for about 3 weeks. So i dont know too much, on to the problem... I am creating a database for asset managment in and out of our shop I have setup the db and it works with no issues. So I am currently trying to add fluff as i put it. The guys in the shop want the web page to have a table of information on what is in the shop and when they click on the asset number in the table they want it to open a new page where you can edit the database information of that item. I have no clue how to emplement this after reading diffrent ideas for about 4 hours today I am just stuck and confused. any ideas or tips would be helpfull This first block of code is my status page. Code: [Select] <style> tr {font-size:24px;} button {width:120px} </style> <body topmargin="50px"> <?php session_start(); include("../../Connections/db_connection.php"); $table = "shop_inventory"; mysql_select_db("$db_database", $connect); unset ($db_username, $db_password); $currenttime = getdate(); $result = mysql_query("SELECT * FROM shop_inventory WHERE In_Shop='1'"); $test = mysql_fetch_array($result); echo "<table border='1' align='center' style='text-align:center' cellpadding='10' width='100%'> <tr> <th>Asset number</th> <th>Building</th> <th>Room number</th> <th>In date</th> </tr>"; $_SESSION['array_row'] = $test; while($row = mysql_fetch_array($result)) { $style = ''; //if ($currenttime - $row['Entered_Shop_Time'] == 0 || 1) $style = 'style="background-color:#00FF00"'; echo "<tr>"; echo "<td> <button onClick=../subpages/edititems.php>" . $row['Asset'] . "</button> </td>"; echo "<td>" . $row['Building'] . "</td>"; echo "<td>" . $row['Room_Number'] . "</td>"; echo "<td $style>" . date("F j, Y", strtotime($row['Entered_Shop_Time'])) . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($connect); ?> </body> This second block of code is the page where i want to dump the table info into for editing. Code: [Select] <?php session_start(); include("../../Connections/db_connection.php"); $table = "shop_inventory"; mysql_select_db("$db_database", $connect); unset ($db_username, $db_password); //$Asset = $_POST['Asset']; $Session = $_SESSION['array_row']; //$data = mysql_query("SELECT * FROM shop_inventory WHERE Asset=$session"); //$query = mysql_query($data) or die ("Cannot select database." . mysql_error()); //$Session = mysql_fetch_array($data); ?> <!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>Add Items</title> </head> <body> <div style=" padding-top:5px;"> <h1><center>Add New Items</center></h1> </div> <form name="myForm" action="afteredititems.php" method="post"> Asset Number: <input type="text" name="Asset" value="<?php echo $Session['Asset']?>"/><br /><br /> Manufactu <input type="text" name="Manufacture" value="<?php echo $Session['Manufacture']?>"/><br /><br /> Model: <input type="text" name="Model" value="<?php echo $Session['Model']?>"/><br /><br /> Serial Number: <input type="text" name="Serial_Number" value="<?php echo $Session['Serial_Number']?>"/><br /><br /> Building: <input type="text" name="Building" value="<?php echo $Session['Building']?>"/><br /><br /> Room Number: <input type="text" name="Room_Number" value="<?php echo $Session['Room_Number']?>"/><br /><br /> <input type="hidden" name="In_Shop" value="1"/> Type of Equipment: <select name="Type" value="<?php echo $Session['Type']?>"> <option value="desktop">Desktop</option> <option value="laptop">Laptop</option> <option value="ipad">Ipad</option> <option value="ipod">Ipod</option> <option value="projector">Projector</option> <option value="printer">Printer</option> </select><br /> <br /> <center><input type="submit" value="Add Item"/></center> </form> </body> </html> And lastly I have a page that redisplays the edited information. Code: [Select] <?php //$Asset = $_POST['Asset']; //$data = mysql_query("SELECT * FROM shop_inventory WHERE Asset=$Asset"); //$query = mysql_query($data) or die ("Cannot select database." . mysql_error()); //$data2 = mysql_fetch_array($data); include("../../Connections/db_connection.php"); $table = "shop_inventory"; mysql_select_db("$db_database", $connect); unset ($db_username, $db_password); $Asset = $_POST['Asset']; $Manufacture = $_POST['Manufacture']; $Model = $_POST['Model']; $Sn = $_POST['Serial_Number']; //<---- possibly fubar check sn everywhere $Building = $_POST['Building']; $Room_Number = $_POST['Room_Number']; $Type = $_POST['Type']; $data = mysql_query("UPDATE `shop_inventory` SET Manufacture='$Manufacture', Model='$Model', Serial_Number='$Sn', Building='$Building', Room_Number='$Room_Number', Type='$Type' WHERE Asset=$Asset"); //$query = mysql_query($data) or die("could not execute query.". mysql_error()); ?> <!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>Untitled Document</title> </head> <body> <!-- display changes --> Asset: <?php echo $Asset ?><br /> Manufactu <?php echo $Manufacture ?><br /> Model: <?php echo $Model ?><br /> Serial number: <?php echo $Sn ?><br /> Building: <?php echo $Building ?><br /> Room Number: <?php echo $Room_Number ?><br /> Type: <?php echo $Type ?><br /><br /> </body> </html> I know there is a lot of poorly formated code and more then likely it is hard to read as I was going to do cleanup after I had all my features working. After doing all the digging i found out about sessions and how they are used to pass data, I thought it would be a good method but I just could not figure out how to send information from the table if the table is reciving its info from an array. any help would be appreciated thanks. Hi All,
I want to copy into a table values from another table that partially match a given value, case-insensitively. So far I do as follows but I wonder whether there is a quicker way.
$input_table=array('1'=>'toto','2'=>'tota','3'=>'hello','4'=>'TOTO','5'=>'toto'); $input_table_2 = array_map('strtolower', $input_table); $value_to_look_for='Tot'; $value_to_look_for_2=strtolower($value_to_look_for); $output_table=array(); foreach ($input_table_2 as $k=>$v) { if(false !== strpos($v, $value_to_look_for_2)) { $output_table[]=$input_table[$k]; } }One drawback is that $input_table_2 is 'foreached' whereas there might be no occurrences, which would lead to a loss of time/resources for big arrays. Thanks. Hello, I need some help. Say that I have a list in my MySQL database that contains elements "A", "S", "C", "D" etc... Now, I want to generate an html table where these elements should be distributed in a random and unique way while leaving some entries of the table empty, see the picture below. But, I have no clue how to do this... Any hints? Thanks in advance, Vero Hi
I am very new to PHP & Mysql.
I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion.
Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself.
Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows).
Ripon.
Below is my Code:
<?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?>Output is attached. Hi All ,
I have a small table with 4 fields namely Day_ID, Dues, Last_Visit, Points. where Day_ID is an auto-increment field. The table would be as follows:
Day_ID -- Dues --- Last_Visit --- Points.
1 --------- 900 -------- 1/12 -------- 6
2 --------- 700 -------- 4/12 -------- 7
3 --------- 600 -------- 7/12 -------- 5
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
So this is the record of a person's visit to say a club. The last row indicates the last date of his visit to the club. His points on this date are 6. Based on this point value of 6 in the last row I want to retrieve all the previous BUT adjoining all records that have the same Points i.e. 6.
So my query should retrieve for me, based on the column value of Points of the last row (i.e. Day_ID - 6 ), as follows:
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
This problem stated above had been completely resolved, thanks to a lot of help from Guru Barand by this following query :-
$query = "SELECT cv.day_id, cv.dues, cv.last_visit, cv.points FROM clubvisit cv WHERE last_visit >= ( SELECT MAX(last_visit) FROM clubvisit WHERE points <> ( SELECT points as lastpoints FROM clubvisit JOIN ( SELECT MAX(last_visit) as last_visit FROM clubvisit ) as latest USING (last_visit) ) )";I am using this and it works perfectly except that now there is a slight change in the table because the criteria for points is now dependent on more than one column cv.points and is more like cv.points1, cv.points2, cv.points3 etc. So now I need to make a selection based on each of these cv.points columns. As of now I can still get the results by running the query multiple times for each of the cv.points columns ( seperately for cv.points1, cv.points2, cv.points3) and it works correctly. However I am wondering if there is a better way to do this in just one go. This not only makes the code repetitive but also since the queries are interconnected, involves the use of transactions which I wish to avoid if possible. The values that I require for each of the cv.point columns is 1. day_id of the previous / old day on which the cv.points value changed from the current day value, and 2. cv.points on that old/ previous day. So for example if the table is as below: Day_ID -- Dues --- Last_Visit --- Points1 --- Points2. 1 --------- 900 -------- 1/12 ----------- 9 ------------ 5 2 --------- 600 -------- 4/12 ----------- 6 ------------ 6 3 --------- 400 -------- 7/12 ----------- 4 ------------ 7 4 --------- 500 -------- 9/12 ----------- 5 ------------ 8 5 --------- 600 -------- 10/12 ---------- 6 ------------ 8 6 --------- 600 -------- 11/12 ---------- 6 ------------ 8 7 --------- 600 -------- 13/12 ---------- 6 ------------ 7 8 --------- 500 -------- 15/12 ---------- 5 ------------ 7 9 --------- 500 -------- 19/12 ---------- 5 ------------ 7 Then I need the following set of values : 1. day_id1 -- Day 7, points1 ---- 6, days_diff1 -- (9-7 = 2) . // Difference between the latest day and day_id1 2. day_id2 -- Day 6, points2 ---- 8, days_diff2 -- (9-6 = 3) 3. day_id3 -- .... and so on for other points. Thanks all ! Hello everyone. I need help with the following PHP APP. I am running on (Version PHP 7.2.10) I am trying to have a page table form on table.php pass the input variable of “5-Numbers” to another page called table_results.php I want that variable string of “5-Numbers” to be compared against 4 arrays and output any duplicates found within each of those 4 lists. If nothing is found, I still want some visual output that reads “None found”.
Lets pretend I have the following example .. On table.php, I typed inside my table form the 5-Numbers .. INPUT: 2,15,37,13,28 On table_results.php, the 4 arrays to be compared against my input numbers “ 2,15,37,13,28” are ..
$array_A = array(2,6,8,11,14,18,24); $array_B = array(1,2,9,10,13,14,25,28,); $array_C = array(1,3,7,9,13,15,20,21,24); $array_D = array(4,5,12,22,23,27,28,29);
So my output should read as follows below .. OUTPUT:
TABLE COLUMN 1 COLUMN 2 ROW 1 Matches Found Results .. ROW 2 GROUP A: 2 ROW 3 GROUP B: 2,13,28 ROW 4 GROUP ? 13,15 ROW 5 GROUP ? 28 ROW 6 5#s Input: 2,15,37,13,28
Please let me know if anyone has any suggestions on how to go about it. Thanks. Edited January 1, 2019 by Jayfromsandiego Wanted to include image example |