PHP - Many To Many Or Single Table
So I'm rebuilding an existing joomla component in laravel and this time I want to get it right. Hopefully my explanation is not too complicated.
I have this situation:
I have an order. The order has many products. The product has many parameters in the form of input fields such as radio, select list and text (think of color, size, engraving, logo select). An order also has some parameters such as address etc.
My question is how I should structure this considering the following:
1. The parameters of either an order itself or a product can change from time to time. Sometimes I need to add several fields for a certain amount of time.
2. Each product has 1 or more production pages (production steps) where some of the parameters set by the order need to be visible. Each production step has its own set of parameters (3d model, logo file). This means that the step1 page should show its own parameters INCLUDING a predetermined set of product parameters. So the columns could look like this: color - engraving - logo select - 3d model - logo file.
3. Each production page lists all the products belonging to that step.
4. Each product can belong to 1 or more production steps.
5. A product is only visible at 1 step at a time. The steps have a specific ordering.
A little note: it's not a usual webshop, but rather we sell custom sports products. Currently we have 3 products where 1 product has 2 production steps and another has 3 production steps.
Don't get me wrong, I have a working application for this, but currently it's just a database mess. The application kept growing as per bosses request so thinking it through was not possible at the time.
Similar TutorialsI am trying to insert data from a mysql in a table. I want the data to appear with the image on the left, item name on the top right followed by description underneath. <?php $sql = 'SELECT * FROM tbl_products ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; $output[] = '<table border="3" bordercolor="#000000">'; while ($row = $result->fetch()) { $output[] = '<tr>'; $output[] = '<td><img src="images/'.$row['pic'].'" width="67" height="100" /></td>'; $output[] = '<td class="style10"><strong>'.$row['item_name'].'</strong></td>'; $output[] = '<td>'.$row['item_description'].'</td>'; $output[] = '</tr>'; } $output[] = '</table>'; echo join('',$output); ?> I would like the items to appear the same way as this page http://aafcollection.info/items/list.php This sounds like it should be pretty simple but I've looked for a while and I'm having trouble finding an answer. What I have is a simple table with 3 columns with predetermined widths. When the text that is queried from the database is inserted into the table, and the text string is longer than the column width, it pushes the text to a second line, which throws the whole table out of whack. Instead, I want the text to be cut off before going to the next line. For example: This is what is happening: This is a sample string of text. This is what I'm trying to do: This is a sample string... Can anyone tell me where to find the solution to this problem? Not that it's needed, but here is some simple code that I'm working with: Code: [Select] <?php $message = "This is a sample string of text."; echo "<table width=\"150\" height=\"20\"border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr>"; echo "<td width=\"50\" height=\"20\" align=\"left" valign=\"top\">Column 1</td>"; echo "<td width=\"50\" height=\"20\" align=\"left" valign=\"top\">Column 2</td>"; echo "<td width=\"50\" height=\"20\" align=\"left" valign=\"top\">$message</td>"; echo "</tr>"; echo "</table>"; ?> Hi, I need to compare records in a table based on the 'datetime' field, like if the difference between time is less than 15min. need to combine the records(rows) as a single resultant row until the time difference between them is less than 15min and when a record's time difference is >15min that should return as another row and so on. Please find following sample table and the required output format Sample Table: Code: [Select] ID NAME DATETIME 1 aaa 2011-10-10 06:30:00 2 bbb 2011-10-10 06:33:00 3 ccc 2011-10-10 06:38:00 4 ddd 2011-10-10 06:40:00 5 eee 2011-10-10 07:10:00 6 ffff 2011-10-10 07:14:00 7 sss 2011-10-10 08:16:00 8 jjj 2011-10-10 08:26:00 9 kkk 2011-10-10 08:28:00 10 mm 2011-10-10 09:46:00 11 ppp 2011-10-10 09:49:00 12 qqq 2011-10-10 09:52:00 Output Needed : Code: [Select] IDs START DATETIME END DATETIME 1,2,3,4 2011-10-10 06:30:00 2011-10-10 06:40:00 5,6 2011-10-10 07:10:00 2011-10-10 07:14:00 7,8,9 2011-10-10 08:16:00 2011-10-10 08:28:00 10,11,12 2011-10-10 09:46:00 2011-10-10 09:52:00 You can see 1st row in the output table having IDs 1,2,3,4 coz the time difference between them is less than 15minutes (it doesn't means time difference between start and end; it is actually the time difference between current record and previous one ; ie; ID-1 and ID-2 have difference less than 15min and ID-2 & ID-3 have difference less than 15min and ID-3 & ID-4 have difference less than 15min, so those 4 records combine together as a single row also shows their start time and end time. Then you can see diff between ID-4 and ID-5 is greater than 15 min so it should display as new row, and so on) How can I acheive above Output with mysql query ?? Please help.. PHP script return 20Â UL LISTÂ values like, < ul >
A < /ul > How to display UL LIST into row wise 5 columns like
A B C D Hi, I've been scratching my head for a while now about how to do this, I'm relatively new to php and mysql and perhaps foolishly taking on creating a user area for a website. I have everything else working, all of my register account functions and confirmations and all of the login scripts etc. I have created a profile page which returns various information to the user (this bit works fine) and I've got some nice show/hide toggles running with some javascript/css but my intention is to allow the user to change thier information (e-mail address, contact phone number and also whether they are subscribed to the e-mail list), it also displays any support tickets or messages. So after the long intro, here's what I'm struggling with... I have a form in a visibility toggled <div> which submits a 'change_email' script, so a user wants to change their e-mail, clicks on change, the <div> appears, they bang in the new e-mail and hit submit. My php script appears to work (because it doesn't throw up any errors), until you realise that actually it's not updated the record in the db... I'm using mysql_query("UPDATE users SET email='$new_email' WHERE username='$user'"); Do I need to setup variables for all of the information in the db (name, username, password, email, contno etc etc) and include them in the command to get it to work or should that just pick the correct record and then update it? If that is the case is there a way I can include 'blank' variables so I don't have to set them all up... e.g. mysql_query("UPDATE users SET user='',password='',email='$new_email', etc WHERE username='$user'"); Many thanks in anticipation How to pull just I record of a column out of the 20 columns? This is not showing the results. $SomeVar = 'pets'; $query = "SELECT field1 FROM db1 WHERE id1 = '".$SomeVar."'"; $results=mysql_query($link); echo $link; Hi, I'm trying to delete a string that's single quoted. From: Cyto's to Cyto, but doesn't work. It works when I add 's to the string with stripslashes, but I can't seem to delete a quote from a string. Does someone know how? My $_post code: Code: [Select] $name=mysql_real_escape_string(stripslashes($_POST["ename"])); Cheers how do I call only a single column in a MySQL? This is not working. $SomeVar = $_POST['finco']; $query = "SELECT * FROM idb WHERE name = '".$SomeVar."'"; $results = mysql_query($query); $psend = $results["fincos"]; echo($psend); I was talking to some friends, who are just as new as me in programming, and they think it would be better to use a single navigation file for every link in a web site. Something like this: Code: [Select] <a href="nav.php?id=home&otherparams" >Home</a> <a href="nav.php?id=products&otherparams" >Products</a> <a href="nav.php?id=contact&otherparams" >Contact</a> I told them I think this might be easier to maintain, but also might take up on loading time, as the site viewer will have to go through an extra node to get where he wants. Is this single navigation file a good practice or should it be avoided? Thanks for any comments... hello. I have some oop code that pulls information about a page out of a mysql db but i dont want to put the code on every page. Instead in want to put it in the a function and pass it back to each page. do i put it in a function in my functions.php file or can i put it into my includes/pages.php includes file ?? the code looks for the page name on the page and then pulls that pages info from the db. this code works on the page - home.php Code: [Select] <?PHP require_once("../includes/initialize.php"); $currentPages = Pages::find_all(); $pName = "adminHome"; $page_id = ""; $visible = ""; $pageZones = ""; $pageCRUD = ""; $pageTypes = ""; $module = ""; $title = ""; $sub_title = ""; $description = ""; $image = ""; $about = ""; foreach($currentPages as $currentPage){ $page_id = $currentPage->id; $pageName = $currentPage->pageName; $visible = $currentPage->visible; $pageZone = $currentPage->pageZones_id; $pageCRUD = $currentPage->pageCRUD_id; $pageType = $currentPage->pageTypes_id; $module = $currentPage->module_id; $title = $currentPage->title; $sub_title = $currentPage->sub_title; $description = $currentPage->description; $image = $currentPage->image; $about = $currentPage->about; if($pageName == $pName){ echo $pageName.'<br/>'; echo $page_id.'<br/>'; echo $visible.'<br/>'; echo $pageZone.'<br/>'; echo $pageCRUD.'<br/>'; echo $pageType.'<br/>'; echo $module.'<br/>'; echo $title.'<br/>'; echo $sub_title.'<br/>'; echo $description.'<br/>'; echo $image.'<br/>'; echo $about.'<br/>'; } } ?> i would like to be able to just put global $page or something like that to get all the db info for each page. i tried this in my includes/pages.php includes file but it cant get the page name. Code: [Select] public static function find_by_pageName(){ global $database; global $pName; $sql = "SELECT * FROM ".self::$table_name." WHERE pageName=".$pName.""; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } any suggestions ???? whats the best way to do this ? thanks ricky This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358810.0 ==> MySQL version 5.0.91-community So once upon a time I was working on a CMS. I worked on it for 3 months, had to wipe my computer - but didn't worry about it because I backed up the files on a flash drive... which got smushed by some boxes when I moved <.< awesome -.- Anyway, a year later (ie: today), I've decided to start again from scratch. For me - for whatever reason - the simplest things always seem to give me the most trouble. I decided to start with a "user" table - naturally - and began working on the first page: user_view.php and added an include file that connects to the database (connectDB.php). Since I started today, everything is simple - no design elements yet - just good 'ol code. The View Users Page is simply a page that grabs all the rows from Table: users and prints the information to the screen, as if you were viewing a Members page on a forum. This Page works fine. No complaints, does everything I need it to, prints all the rows and cols from Table Users. Then I created the Edit User Page. When I did this a year ago, and I wanted to print out all the data from the table, I used the while loop. When I wanted to only grab certain variables from a table, I just created a new set of variables, as show below. Using the same method from a year ago, I started working on printing various data to the screen (such as "Welcome $username"). 5 minutes of typing... refresh page... nada. So I stripped away just about every tag but the essentials and it still wouldn't work Code: [Select] <?php ... $userID = 3; $sql = "SELECT * FROM users WHERE userID='$userID'"; $result = mysql_query($sql); $rows = mysql_fetch_row($result); echo $rows['username']; ... ?> Normally, this would just grab the username from a row in Table users where the userID = 3 But instead - it does nothing. I just see a blank page. It's a simple 5 lines of code and it's like "im just gonna do w.e the fk i wanna do mmmk thxforplaying" PS: Keep in mind there is nothing wrong with the connection to the database, and as already stated I'm able to print ALL values from the Users Table using this same method: Code: [Select] <?php ... $user_sql = "SELECT * FROM users ORDER BY username ASC"; $user_result = mysql_query($user_sql); while ( $user_rows = mysql_fetch_array($user_result) ) ... ?> Hi Guys, This is what I am trying to do. I have multiple link one 1 page and when a user clicks on that link it will print that file for them. Code: [Select] page.php containts 20+ images image1 - Print image2 - Print image3 - Print etc.... <a href="page.php?cid=1">Print</a> <a href="page.php?cid=2">Print</a> <a href="page.php?cid=3">Print</a> So what I need to do is if user clicks cid=2 then it goes to page.php?cid=2 shows the image and prints with javascript. That is not a problem I already to this with html but I am changing over to php mysql due to simplicity and ease of use. and also to reduce to pages from 30+ pages down to 1 page for this section. so this is what I am having trouble with Code: [Select] switch($cid) case $cid { echo image and print } default { echo all images and print link } So the problem I am having is the case $cid The problem is that this is so simple and I have been playing with it for so long I don't see the fix. hey everyone will you please assist. I'm getting data from a mysql database. And I want to assign the data to a single value, if possible For example, in my database I have 2 columns, name and group Lets say John, Peter and Cathy belongs to group 555, where Sally and Marcus belongs to group 777. So my sql query outputs all users in group 555 Is there a way to assign the search result to a vlue, for example $result = ??? and If I said echo $result, it should show the users who belongs to group 555 as an example. I tried to use row[Name][1]; but it doesnt work. The thing is, I can display the data the way I am familiar with, but I'm sending an automated email to myself, containing the users. So if I would used a for each statement, the mail will trigger and send a copy for every count, in this case, 3 times. And thats my huge problem. The mail must trigger only once, containing the users in my search query, in this case, group 555. Any help will be appreciated Thank you I want to use all five results separately in order to use in a Jquery slider. Code: [Select] <?php $a = "SELECT * FROM blog_posts ORDER BY id DESC LIMIT 5"; $query = mysql_query($a) or die (mysql_error()); $query_results = mysql_fetch_array($query); ?> I know if i was going to grab vars from an normal array i would just use... Code: [Select] <?php echo $array_reults['0'] ?> Can any one help me with this problem? Hello, I have a simple multiple-step form and I use sessions to save the data. Now i have 1 single checkbox and i would like to know how i can save that data (if one checked it or not). I am not very advanced with sessions, nor PHP, thus i tried the following: Code: [Select] if (isset($_POST['newsletter'])) { $_SESSION['newsletter']=$_POST['newsletter']; } $newsletter = $_SESSION['newsletter']; // do not really know what if statement to use if($newsletter == 'yes') { $newsl = '1'; } //checkbox html here <input type="checkbox" class="styled" name="newsletter" value="yes" /> Obviously the above won't work. Can explain to me how to save checkbox data in a session? Thanks a lot in advance. I can use the first while loop, but there is no data in the second while loop. Is there a better way as I have never done this before... Code: [Select] <?php $featured_results = mysql_query("SELECT * FROM products LEFT JOIN product_images ON products.product_id=product_images.product_id WHERE products.product_featured='1' AND products.product_active='1' AND thumb='1'"); $fa=0; while($featured_row = mysql_fetch_assoc($featured_results)) { $fthumb_result = mysql_query("SELECT image_name FROM product_images WHERE product_id='".$featured_row['product_id']."' AND thumb='1'"); $fthumb = mysql_fetch_row($fthumb_result); if ($fa==0) { echo "\n<img id=\"home-slider-photo-".$fa."\" class=\"home-slider-photo preload\" src=\"/includes/getimage.php?img=".$fthumb[0]."&w=370&h=370\" alt=\"\" />"; } else { echo "\n<img id=\"home-slider-photo-".$fa."\" class=\"home-slider-photo preload home-slider-photo-unsel\" src=\"/includes/getimage.php?img=".$fthumb[0]."&w=370&h=370\" alt=\"\" />"; } $fa++; } echo "<div id=\"home-slider-photo-price\">"; $fb=0; while($featured_row2 = mysql_fetch_assoc($featured_results)) { if ($fb==0) { echo "\n<div id=\"home-slider-photo-price-".$fb."\" class=\"home-slider-photo-price\">\n<span>only</span>$".$featured_row2['product_price']."\n</div>"; } else { echo "\n<div id=\"home-slider-photo-price-".$fb."\" class=\"home-slider-photo-price home-slider-photo-price-unsel\">\n<span>only</span>$".$featured_row2['product_price']."\n</div>"; } $fb++; } echo "</div>"; ?> I am having a problem applying pagination to my page when I only have one record displayed. I would like to have it set up to where one record is followed by the next one in the list. I have tried several ways but they are for whole tables moving to the next page. I think I am missing something small but not sure. Any help will be greatly appreciated, thanks. Could somebody please point me in the right direction.... I want to block the US, AUS, NZ, CAN, IRE from the index.php of my site. But not the rest of the site. The following site (like many others) provides a pretty neat list for the htaccess http://www.ipinfodb.com/ip_country_block.php I did a test. I got the list for blocking the UK. After copying the UK list to my htaccess i couldn't view my site. The thing i don't get is... my ip address was not in the list but i was still blocked, The 1st 2 sets from my ip are '2.100' The only ip's in the list starting with 2 a deny from 2.24.0.0/13 deny from 2.96.0.0/13 deny from 2.120.0.0/12 deny from 2.136.0.0/13 How exactly is this all working? And what's the best way of blocking the above countries from just my index.php? Any links to manuals or anything here would be great... Thank You. John Greetings, I'm trying to execute a shell command with a user-supplied password as input. The password may contain apostrophes and and virtually any other character. Unfortunately, when using escapeshellarg(), the password argument is interpreted as two separate arguments, as escapeshellarg() will handle apostrophes (single quotes) by breaking out of the already quoted text and using a backslash escape. $password = escapeshellarg("ex'ample!%"); // The password will actually be supplied by an HTML form. $command = ('echo '.$password); echo "$command"; // Returns 'ex'\''ample!%' Does anyone have any input on how to accomplish what I'm trying to do? I'd like to allow obscure passwords without disallowing specific characters, while still being "safe" in passing the information to a shell command. Double quotes would work for passing single quotes, but I'm afraid I might break other characters there. Thanks. |