Jump to content

kaplanyo

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by kaplanyo

  1. Thanks! I am using PHP and loving it! That did the trick - very much THANKS to you!!! I'm using a variable with that mysql_insert_id(); and passing it in through a function and bam!! right into the ole foreign key... that's so nice! Have a good one! Dave
  2. Hello, I'm using the primary key of one table (work) as a foreign key in another table (workimages), I'm getting how that works. What I'm wondering is if it's necessary to create or insert an entry for the 'work' table, which would then give me a primary key, before I can use that primary key in my other table 'workimages' as a foreign key. In the past I had to create the 'work' entries and then in a separate form use a select drop down menu in order to get the primary key for the 'workimages' upload. I'm trying to create the work entry and at the same time upload images to the workimages in one form. Doesn't seem possible to get the primary key until after it's been inserted. Sorry about my noobness. Any advice would be appreciated. Dave
  3. Greetings, This isn't my area of expertise so I'm looking for an opinion or a few what's better to use for an XHTML site, XML or PHP/mySQL. I've got a Flash site built that uses XML for its content display. That XML is generated using PHP/mySQL through a custom CMS that I've cobbled together, I mean crafted... What I'd like to do now is build an XHTML version of the site for -ahem- non-Flash browsers using either the XML or PHP/mySQL. What's better or maybe easier to work with when it comes to XHTML, XML or PHP/mySQL? I've made 'printable' non-Flash versions for some of the site content using PHP/mySQL and that was pretty cool, just wondering if it's even easier, better or cleaner to use my XML data, now that I have it all, to make a full non-Flash version of the site. Any advice would be much appreciated. Thanks!
  4. Hi, I have what I think is a good system for generating XML from PHP. The PHP scripts run and dynamically generate some XML. So I get XML output from a PHP file. What I'd like to do what I think of as 'publishing' the XML file, or creating an actual .XML file from the PHP. Is there function in PHP that would allow me write a file? PHP file > script runs > makes an actual .XML file. I'm loading this XML into Flash and trying to optimize the loading, sometimes it seems like the dynamically generated XML takes a few seconds to get created by the PHP, sometimes it's fast (non-cached). I thought it might be better to load the XML from a 'static' XML file that I generated with my PHP script. Any push in the right direction would be great, thanks. Dave
  5. I would like to know if it's a bad idea to not use the primary key from one table as the foreign key in another. What if I use a different field as the foreign key. I have a Project List and a Project Image Library. I want to associate a field in the library with one of the projects. I started by using the PK of the Projects as the FK of a library image, but I'd rather use a name instead of the id, it makes more sense for listing and selection for the user. I've got it working without using the PK and using the name field, but I'm just wondering if that approach is ok. Maybe I can explain more... if I have a table called 'projects' with a field called 'project_id' (the primary key) and 'name'... is it a bad idea to use 'name' as my foreign key in another table, project_images - that table has 'item_id' (the primary key) and 'project_name'. I want to use 'name' from 'projects' and put it in 'project_name' in the 'project_images'. Thanks. Any advice would be really great. I can also post a link or take some screen shots to show what I mean. Dave I'm using: MySQL client version: 5.0.22 Used PHP extensions: mysql
  6. I figured it out. I used a function to run through and replace the odd key inputs. The quotes and apostrophes look great in the fancy winery names. http://www.sepiachicago.com/dev/wine.html function convert_smart_quotes($string) { $search = array(chr(145),chr(146),chr(147),chr(148)); $replace = array("‘", "’", '“', '”'); return str_replace($search, $replace, $string); } // then in my loop echo "<winesbyglass menu_name=\"WINES BY THE GLASS\">\n"; while ($rowGlass = mysql_fetch_assoc($resultGlass)) { // use the htmlentities to get the accented characters in flash. // run the conversion function first for the characters that aren't covered in htmlentities $convertRowGlass = convert_smart_quotes($rowGlass); echo "\t<category category_name=\"".htmlentities($rowGlass['category'])."\">".htmlentities($convertRowGlass['menuitems'])."</category>\n";} mysql_free_result($resultGlass); echo "</winesbyglass>\n"; Part of my problem is I don't grasp the basics quick enough. I found this great page to learn about using php functions: http://www.tizag.com/phpT/phpfunctions.php
  7. I've been doing some searching and reading about smart quotes, but I'm not sure how to invoke the function in my case. I'm using php/mysql to output some db content as xml that gets loaded in flash. I would like to run the conversion so that my xml gets the Entity Name instead of the keystroke, which in Flash just ends up blank. I saw a couple different approaches, but I'm still a rookie and can't figure out where to invoke the function to get my conversion. Any help would be very nice and greatly appreciated. I've got some nice features going, like scrollwheel functionality and a a lovely embedded font, but the real quotes and apostrophes, either pasted from an outside word file or keystroked would be the cherry on top. Here's what my Flash and XML output are looking like: flash: http://www.sepiachicago.com/dev/wine.html xml output using php/mysql: http://www.sepiachicago.com/winemenu_output_xml.php Here's some of the code I'm working with in my output. echo "<winesbyglass menu_name=\"WINES BY THE GLASS\">\n"; while ($rowGlass = mysql_fetch_assoc($resultGlass)) { // you need to use the htmlentities to get the accented characters in flash. // unfortunately, curly quotes are outside the set of entities that can be converted. echo "\t<category category_name=\"".htmlentities($rowGlass['category'])."\">".htmlentities($rowGlass['menuitems'])."</category>\n";} mysql_free_result($resultGlass); echo "</winesbyglass>\n"; and I've seen, which looks like what I want to use, but I'm not sure where to invoke it during my xml outputting. function get_html_translation_table_CP1252() { $trans = get_html_translation_table(HTML_ENTITIES); $trans[chr(130)] = '‚'; // Single Low-9 Quotation Mark $trans[chr(131)] = 'ƒ'; // Latin Small Letter F With Hook $trans[chr(132)] = '„'; // Double Low-9 Quotation Mark $trans[chr(133)] = '…'; // Horizontal Ellipsis $trans[chr(134)] = '†'; // Dagger $trans[chr(135)] = '‡'; // Double Dagger $trans[chr(136)] = 'ˆ'; // Modifier Letter Circumflex Accent $trans[chr(137)] = '‰'; // Per Mille Sign $trans[chr(138)] = 'Š'; // Latin Capital Letter S With Caron $trans[chr(139)] = '‹'; // Single Left-Pointing Angle Quotation Mark $trans[chr(140)] = 'Œ'; // Latin Capital Ligature OE $trans[chr(145)] = '‘'; // Left Single Quotation Mark $trans[chr(146)] = '’'; // Right Single Quotation Mark $trans[chr(147)] = '“'; // Left Double Quotation Mark $trans[chr(148)] = '”'; // Right Double Quotation Mark $trans[chr(149)] = '•'; // Bullet $trans[chr(150)] = '–'; // En Dash $trans[chr(151)] = '—'; // Em Dash $trans[chr(152)] = '˜'; // Small Tilde $trans[chr(153)] = '™'; // Trade Mark Sign $trans[chr(154)] = 'š'; // Latin Small Letter S With Caron $trans[chr(155)] = '›'; // Single Right-Pointing Angle Quotation Mark $trans[chr(156)] = 'œ'; // Latin Small Ligature OE $trans[chr(159)] = 'Ÿ'; // Latin Capital Letter Y With Diaeresis ksort($trans); return $trans; }
  8. Thanks for your help. I'm not sure how to do what your saying about the JOIN, but I'll look it up. I'm starting to see what you mean about just using the flat file, the relational stuff is confusing me. In my little sketch diagram it seemed like it was better to keep all the items in one table and organize them by category, i reckon i should do that without having to use the relational db.
  9. Thanks very much for taking the time to look at this. Here's the code above the DOCTYPE <?php // some session and connection info here. // include for magicQuotes and make db connection include('../includes/corefuncs.php'); // remove backslashes nukeMagicQuotes(); // prepare an array of expected items $expected = array('category', 'description', 'additional', 'item_id', 'category_id'); // set required field $required = array('description', 'item_id', 'category_id'); // create empty array for missing fields $missing = array(); // create database connection $conn = dbConnect('admin'); // get details of selected record if ($_GET && !$_POST) { if (isset($_GET['item_id']) && is_numeric($_GET['item_id'])) { $item_id = $_GET['item_id']; } else { $item_id = NULL; } if ($item_id) { $sql = "SELECT * FROM dinner WHERE item_id = $item_id"; $result = mysql_query($sql) or die (mysql_error()); $row = mysql_fetch_assoc($result); } } // if form has been submitted, update record if (array_key_exists('update', $_POST)) { // prepare expected items for insertion in to database foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } elseif (in_array($key, $expected)) { ${$key} = mysql_real_escape_string($value); } } // abandon the process if primary key invalid if (!is_numeric($item_id)) { die('Invalid request is now happening'); } // check the value of image_id if (empty($category_id) || !is_numeric($category_id)) { $category_id = NULL; } // prepare the SQL query if missing is empty if (empty($missing)) { $sql = "UPDATE dinner SET category_id = $category_id, category = '$category', description = '$description', additional = '$additional' WHERE item_id = $item_id"; // submit the query and redirect if successful $done = mysql_query($sql) or die(mysql_error()); } // if successful, redirect to list of existing records if ($done || !isset($item_id)) { header(''); exit; } } ?> and then here's what my update form looks like <?php if ($_POST && isset($missing)) { ?> <p class="warning">Please complete the missing item(s) indicated.</p> <?php } ?> <?php if (empty($row) && (!$missing)) { ?> <p class="warning">Invalid request: record does not exist.</p> <?php } else {?> <form id="form1" name="form1" method="post" action=""> <p> <label for="category_id">Menu category:</label> <select name="category_id" id="category_id"> <option value="">Select category dude</option> <?php //get details of categories $getCategories = 'SELECT * FROM dinner_categories ORDER BY category_id'; $categoryList = mysql_query($getCategories) or die (mysql_error()); while ($categories = mysql_fetch_assoc($categoryList)) {?> <option value="<?php echo $categories['category_id'];?>" <?php if ($categories['category_id'] == $row['category_id']) { echo ' selected="selected"'; }?>><?php echo $categories['category_name']; ?></option> <?php } ?> </select> </p> <p> <label for="description">Description: <?php if (isset($missing) && in_array('description', $missing)) { ?> <span class="warning">Please add a description.</span><?php } ?> </label> <textarea name="description" class="widebox" id="description" cols="60" rows="8"><?php if (!$missing) { echo ($row['description']); } else { echo htmlentities($_POST['description']); } ?></textarea> </p> <p> <label for="additional">Additional:</label> <input name="additional" type="text" class="widebox" id="additional" <?php if (!$missing) { echo 'value="'.htmlentities($row['additional']).'"'; } else { echo 'value="'.htmlentities($_POST['additional']).'"'; } ?> /> </p> <input name="item_id" type="hidden" <?php if (!$missing) { echo 'value="'.htmlentities($row['item_id']).'"'; } else { echo 'value="'.htmlentities($_POST['item_id']).'"'; } ?> /> <p> <input type="submit" name="update" value="Update menu item" /> <input name="cancel" type="submit" value="Cancel" /> </p> </form> <?php } ?>
  10. I'll get the rest of the code in here. Yes and I'd like to use the cat_name in the item table too. would it look like this then?: category item --------- ---------- cat_id ---+ item_id | item_name +--- cat_id cat_name ---+--- cat_name I'm planning to sort these out by the cat_id but use the cat_name for display. Does that make sense? I have a feeling I might need to rethink what i'm try to accomplish. Thanks!
  11. I apologize if this is the wrong place to ask... I'm brand new here. And I'm not sure if my problem is in my PHP or mySQL. Here's my problem. Any guidance would be much appreciated. I'll try and describe it the best way I can. I've got a list of 'items' and those 'items' have unique 'categories'. I have 1 table for 'categories' that contains a list of category_ids and their 'category_names'. The other table is the 'item' list. And here's where I'm running into difficulty, I'd like to have the 'item' table contain the category_id from my 'categories' table as a Foreign Key and that category_id's 'category_name' in a 'category' field. I'm getting the Foreign Key, but I can't seem to grab the 'category_name' and assign it to my $category variable in the 'item' table. I've got a page to insert items and a page to update these items. I was working with the update first. And I'm able to grab the list of categories and select the correct one, but I'm not seeing where to assign the category_name to the $category variable. Here's dropdown list: <p> <label for="category_id">Menu category:</label> <select name="category_id" id="category_id"> <option value="">Select category dude</option> <?php //get details of categories $getCategories = 'SELECT * FROM dinner_categories ORDER BY category_id'; $categoryList = mysql_query($getCategories) or die (mysql_error()); while ($categories = mysql_fetch_assoc($categoryList)) {?> <option value="<?php echo $categories['category_id'];?>" <?php if ($categories['category_id'] == $row['category_id']) { echo ' selected="selected"'; }?>><?php echo $categories['category_name']; ?></option> <?php } ?> </select> </p> It seems like I want to say something like this somewhere: $category = $categories['category_name']; Is this more of a mySQL/db question than a PHP because I'm trying to insert?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.