
kingnutter
Members-
Posts
147 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
kingnutter's Achievements

Member (2/5)
0
Reputation
-
GROUP BY, NULL values and endless iterations.
kingnutter replied to kingnutter's topic in MySQL Help
I appreciate that. I'm trying to do too much at once. I'll spilt it up into stages and come back when stuck on a certain point. Many thanks. -
I am trying to echo a list which is essentially an index of a publication. It lists page number, title and a relevant link. Some links have no title, some titles pertain to several links. My existing code works to an extent. It is listing all of my records, grouping by title.name/id and ordering by location (page number). Neat. I have two problems: 1) Some of my links records have a title value of 0 (should it be NULL?). I don’t wish to group all of these together, but list them individually ordered by location mixed in with above. 2) All my attempts at working out whether a grouped title pertains to several links and then iterating through them is producing multi-nested conditions and queries which I am certain are superfluous. Here is my existing code. Apologies if some of the echos are not needed here. NB: I am using codeigniter hence the odd “anchor” but I want to sort this out as straight MySQL to start with. $result2 = mysql_query(" SELECT links.id, links.link, links.title, links.itemtype_id, links.notes, MIN(links.location), titles.id, titles.name FROM links JOIN titles ON links.title=titles.id WHERE heading = $id AND links.hidden = 0 GROUP BY titles.id ORDER BY MIN(links.location); "); while($linkarray = mysql_fetch_array($result2)){ echo "<div style='text-indent:" . $headings['depth'] . "em;'>" . "pg. " . $linkarray['MIN(links.location)'] . " <b>" . $linkarray['name'] . $linkarray['title'] . "</b> "; echo "<div style='text-indent:" . $headings['depth'] . "em;'>"; if ($linkarray['itemtype_id']==1){ echo "<a href='http://$linkarray[link]' target='_blank'>"; } echo $linkarray['link']; if ($linkarray['itemtype_id']==1){ echo "</a>"; } echo " "; // DELETE LINK echo anchor("edit/deleteLink/" . $linkarray['id'], "X<br />", array('class'=>'deleteLink')); echo "</div>"; echo "<div class='notes'>" . $linkarray['notes'] . " </div>"; } Here are the relevant table structures: MySQL client version: 5.1.30 CREATE TABLE IF NOT EXISTS `links` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `link` varchar(256) NOT NULL, `title` mediumint( unsigned NOT NULL DEFAULT '0', `heading` int(10) unsigned NOT NULL DEFAULT '0', `itemtype_id` tinyint(3) unsigned NOT NULL, `notes` varchar(256) DEFAULT NULL, `location` int(10) unsigned NOT NULL, `instance_id` smallint(5) unsigned NOT NULL, `hidden` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=215 ; CREATE TABLE IF NOT EXISTS `titles` ( `id` mediumint( unsigned NOT NULL AUTO_INCREMENT, `name` varchar(256) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=201 ; Any help appreciated. Please let me know if any more information is required. Thanks.
-
Cookie Not Repopulating Textarea in Form
kingnutter replied to kingnutter's topic in PHP Coding Help
Thanks so much. Sorted. -
Hi everyone, I have a form which is repopulated with cookies of user entries following an unsuccessful submit. It works on all fields except the textarea which is just blank. Can anybody suggest why this isn't working? Here is the form page code: <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <?php include("functions.php"); getcompanyname(company); ?> <html> <head> <title>Nominate <?php echo getuserdetails("company", company); ?> for The WOW! Awards</title> <link href="mobile.css" rel="stylesheet" type="text/css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript" src="javascript/form.js"></script> </head> <div id = "header"> <img src="images/mobile_banner.png"); </div> <div id="content"> <?php mobileerror(); ?> <h2>NOMINATE US!</h2> <div id = "rulesheading"> <b>There are just four criteria to be met:</b><br /> </div> <div id = "rules"> <ol> <li>It has to be for service that made you go WOW!</li> <li>It should be a recent experience</li> <li>It must have happened to you personally</li> <li>Employees of LoveFilm may not nominate</li> </ol> </div> <form id= "contactform" action="mobile_proc_nominate.php" method="post"> <fieldset><legend>Nomination Form</legend> <input type="hidden" name="type" value="nomination"/> <input type="hidden" name="jobtitle" value=" "/> <input type="hidden" name="department" value=" "/> <input type="hidden" name="mobile" value="1" /> <h4>Your Nomination Details</h4> <p> <?php if (!isset($_COOKIE['nominee'])){ ?> <!-- These stop the Java labels overwriting user text if error --> <label for="nominee">Tell us who WOW!ed you today (required)</label> <?php } ?> <input type="text" name="nominee" id="nominee" value="<?php echo readcookie('nominee'); ?>" title="Tell us who WOW!ed you today"/> </p> <p> <?php if (!isset($_COOKIE['comment'])){ ?> <label for="comment">How, where and when did they WOW! you? (required)</label> <?php } ?> <textarea name="comment" id="comment" value="<?php echo $_COOKIE["comment"]; ?>" title="How, where and when did they WOW! you? (required)" /></textarea> </p> <h4>Your Details</h4> <p> <?php if (!isset($_COOKIE['name'])){ ?> <label for="name">Your Name (required)</label> <?php } ?> <input type="text" name="name" id="name" value="<?php echo readcookie('name'); ?>" title="Please tell us your name"/> </p> <p> <?php if (!isset($_COOKIE['email'])){ ?> <label for="email">Your Email (required)</label> <?php } ?> <input type="text" name="email" id="email" value="<?php echo readcookie('email'); ?>" title="Please enter your email address"/> </p> <p> <?php if (!isset($_COOKIE['phone'])){ ?> <label for="phone">Your Phone Number</label> <?php } ?> <input type="text" name="phone" id="phone" value="<?php echo readcookie('phone'); ?>" title="And your phone number"/> </p> <input class="button" type="submit" value="Send" /> </fieldset> </form> </div> <div id="footer"> </div> </body> </html> And here is the form processing script: <?php include("functions.php"); checkaccess(0); require_once("includes/browser.php"); $browser = new Browser(); $thebrowser = ereg_replace("[^A-Za-z]", "", $browser->getBrowser()); $ver = $browser->getVersion(); setcookie("nominee",$_POST['nominee'],time()+3600); setcookie("comment",$_POST['comment'],time()+3600); setcookie("name",$_POST['name'],time()+3600); setcookie("email",$_POST['email'],time()+3600); setcookie("phone",$_POST['phone'],time()+3600); $email = $_POST['email']; if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $email_error="TRUE"; } if ($thebrowser.$ver != "InternetExplorer6.0") { /* if(!captcha() ) { header("location: nominate.php?err=Spam Protection Code"); } else*/ if($_POST['name']=="" || $_POST['name']=="Your Name (required)" || $_POST['nominee']=="Tell us who WOW!ed you today (required)" || $_POST['nominee']=="" || $_POST['comment']=="How, where and when did they WOW! you? (required)" || $_POST['comment']=="" || $_POST['email']=="" || $_POST['email']=="Your Email (required)" || $email_error=="TRUE" ) { header("location: mobile.php?err=Please complete the required fields"); } else { connect(); $name=format_text_for_database($_POST['name']); $email=format_text_for_database($_POST['email']); $phone=format_text_for_database($_POST['phone']); $nominee=format_text_for_database($_POST['nominee']); $jobtitle=format_text_for_database($_POST['jobtitle']); $department=format_text_for_database($_POST['department']); $comment=format_text_for_database($_POST['comment']); $type=format_text_for_database($_POST['type']); $cid=company; $mobile=format_text_for_database($_POST['mobile']); $sql=mysql_query("insert into comments (date, name, email, phone, department, nominee, jobtitle, comment, type, cid, mobile) values (now(), '$name', '$email', '$phone', '$department', '$nominee', '$jobtitle', '$comment', '$type', $cid, $mobile)"); $lastid=mysql_insert_id(); disconnect(); senduseremail($lastid); sendclientemail($lastid); header("location: mobile_thanks.php"); } } if ($thebrowser.$ver == "InternetExplorer6.0") { /* if(!captcha_spam() ) { header("location: nominate.php?err=Please re-enter the Spam Protection Code"); } else*/ if($_POST['name']=="" || $_POST['email']=="" || $_POST['comment']=="") { header("location: nominate.php?err=Please complete the required fields"); } else { connect(); $name=format_text_for_database($_POST['name']); $email=format_text_for_database($_POST['email']); $phone=format_text_for_database($_POST['phone']); $nominee=format_text_for_database($_POST['nominee']); $jobtitle=format_text_for_database($_POST['jobtitle']); $department=format_text_for_database($_POST['department']); $comment=format_text_for_database($_POST['comment']); $type=format_text_for_database($_POST['type']); $cid=company; $sql=mysql_query("insert into comments (date, name, email, phone, department, nominee, jobtitle, comment, type, cid) values (now(), '$name', '$email', '$phone', '$department', '$nominee', '$jobtitle', '$comment', '$type', $cid)"); $lastid=mysql_insert_id(); disconnect(); senduseremail($lastid); sendclientemail($lastid); header("location: mobile_thanks.php"); } } ?> Any pointers would be greatly appreciated. KN
-
Insert Multiple Data From One Table To Another
kingnutter replied to kingnutter's topic in MySQL Help
Thanks. That works perfectly and I will refer to this syntax on all my future similar queries. -
Hi there, I'm trying to insert multiple values from one table to another along with a few set values. Hopefully you can see what I'm trying to do from the code below. Could anyone tell me the correct syntax? I am doing this through PHPmyadmin. Many thanks in advance. INSERT INTO node (nid, vid, type, language, title, uid, status, created, changed, comment, promote, moderate, sticky, tnid, translate) (SELECT moj_id FROM mojocd, SELECT moj_id FROM mojocd, 'mojocd', 'en', SELECT moj_title FROM mojoocd, 0, 1, 1293671713, 1293671713, 0, 0, 0, 0, 0, 0)