Jump to content

rocky48

Members
  • Posts

    261
  • Joined

  • Last visited

Everything posted by rocky48

  1. I am trying to check for the YEAR that I enter on a previous form and if the YEAR is 2015, do the first condition else if the YEAR is 2014 do the second condition. THe reason for sorting on YEAR is to go to a diffierent table in the database. When the YEAR satisfys the first condittion (2015), I get the correct data outputted, but when the second condition is entered (2014), no data is outputted. In phpMyAdmin I have pasted the MYSQL query and substituted the Month and Year with correct data, it outputs data correctly for 2014. Here is the code: <?php include("RelHol_connect.php"); doDB3(); $Year = $_POST["Year"]; echo $Year; if ($Year= 2015){ $get_Event_sql = "SELECT Events15.ID, Events15.Event_Date, Events15.Event_Description, Religion.ID, Religion.Religion FROM Events15 LEFT JOIN Religion ON Religion.ID = Faith_ID WHERE MONTHNAME(Events15.Event_Date) = '".$_POST["Month"]."' And YEAR(Events15.Event_Date)= '".$_POST["Year"]."' ORDER BY Events15.Event_Date ASC"; $get_Event_res = mysqli_query($mysqli, $get_Event_sql) or die(mysqli_error($mysqli)); $array = array($get_Event_res); print_r(array_values($array)); } else{ $get_Event_sql = "SELECT Events.ID, Events.Event_Date, Events.Event_Description, Religion.ID, Religion.Religion FROM Events LEFT JOIN Religion ON Religion.ID = Faith_ID WHERE MONTHNAME(Events.Event_Date) = '".$_POST["Month"]."' And YEAR(Events.Event_Date)= '".$_POST["Year"]."' ORDER BY Events.Event_Date ASC"; $get_Event_res = mysqli_query($mysqli, $get_Event_sql) or die(mysqli_error($mysqli)); } print_r($get_Event_res); //create the display string $display_block = "<h2> <table width=\"100%\" cellpadding=\"3\" cellspacing=\"0\" border=\"1\" BGCOLOR=\"#87CEEB\" > <tr> <th>Date</th> <th>Event</th> <th>Faith</th> </tr>"; while ($Event_info = mysqli_fetch_array($get_Event_res)) { $Event_Date = $Event_info['Event_Date']; $Event_text = nl2br(stripslashes($Event_info['Event_Description'])); $Faith = $Event_info['Religion']; $Date = new DateTime(".$Event_Date."); $Date_frmt=$Date->format('d - F'); //add to display $display_block .= " <tr> <td width=\"7%\" valign=\"top\">".$Date_frmt."</td> <td width=\"30%\" valign=\"top\">".$Event_text."</td> <td width=\"15%\" valign=\"top\">" .$Faith."</td> </tr>"; } //free results mysqli_free_result($get_Event_res); //close connection to MySQL mysqli_close($mysqli); //close up the table $display_block .= "</table>"; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta charset="utf-8"> <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)"> <meta name="dcterms.created" content="Sat, 02 Mar 2013 20:21:23 GMT"> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="viewport" content="width=768px, minium-scale=1.0, maximum-scale=1.0" /> <title>Religious Holidays & Festivals</title> <link rel="stylesheet" href="stylesheets/ipad.css" /> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div id="wrap"> <div id="header"> <img src="images/Head!.png" width="100%" height="150px" alt="" title=" 1066 cards4U" border="0" /> <h1>1066 cards4U</h1> </div> <div id="content"> <div id="main"> <h1>Religious Holidays and Festivals for <? echo $_POST["Year"];?> </h1> </br> <?php echo $display_block; ?> </div> <div id="side"> <div id="sidea"> <h3>Main Menu</h3> <p><ul> <li><a href="index1.html">Home</a></li> <li><a href="iLinks.html">Links</a></li> <li><a href="iTechniques.html">Techniques</a></li> <li><a href="iVerse_Menu.html">Verse's</a></li> <li><a href="icontact.html">Contact Us</a></li> <li><a href="iNews.html">News</a></li> <li><a href="iAboutUs.html">About Us</a></li> <li><a href="iGallery.html">Gallery</a></li> <li><a href="iStats_Menu.html">Stats</a></li> </ul></p> </br> </div> <div id="sideb"> </div> <div id="sidec"> </div> </div> </div> <div id="footer"> <p>© 2012 Content:1066 Cards 4U. All rights reserved. <br /> With thanks to Matt Taylor - matthewjamestaylor.com</p> </div> </div> </body> </html> Have I got the syntax wrong? I do not get any error messages?? Your help would be appreciated.
  2. Tried UPDATE but that gives the same result: UPDATE `ctryvisits15` SET `Qtr`=[1] WHERE `WNo`<14; Is it because I am only trying to update just 1 column in the table?
  3. I am trying to INSERT data into a column that I have added to the table, but I keep getting a syntax error. Here is the line: INSERT INTO `ctryvisits15`(`Qtr`) VALUES (2) WHERE `WNo` <27 The message is : #1064 - 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 '2) WHERE `WNo` <27' at line 1 I have tried every thing I can think of but can't see where I am going wrong. I am using phpMyAdmin to update my data.
  4. Must have been on the juice the day I wrote the script. Firtstly I was sorting on the ID and not the Week No (WNo). Also the script I wrote to upload the stats was not writing to the Week No (WCom), which was badly named as it stored the week No. These are the changes I made to the incorrect script: $limitStart = $_POST['QUARTER'] - 13; $Visit_data="SELECT Visits15.ID, Visits15.WVisits, Visits15.WCom, WeekNo15.WNo, WeekNo15.WCom FROM Visits15 LEFT JOIN WeekNo15 ON Visits15.WCom = WeekNo15.WNo <<< Changed here ORDER BY Visits15.WCom <<< Changed here LIMIT {$limitStart}, 13"; $Visit_data_res = mysqli_query($mysqli, $Visit_data) or die(mysqli_error($mysqli)); $display_block = " <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Week No</th> <th>Week Commencing</th> <th>Visits</th> </tr>"; while ($C_info = mysqli_fetch_array($Visit_data_res)) { $Cid = $C_info['WNo']; <<< Changed here $Visits = ($C_info['WVisits']); $WeekNo = ($C_info['WCom']); Psycho - I take your point that limit does only work on the results set, but if you keep the data tidy it should not cause a problem. I found this out when I inadvertantly put the same data in twice. Barand - Thanks for the tip. I did not change it in this case, but I'll remember that in the future.
  5. I have a query that filters the data (based on week numbers) so that it displays the data in Quarters. I have the same logic in two scripts, in one it works, but in the other it does not. The only difference is that the one that does not work it is preceeded by a form with two selections (country & Quarter), whereas the one that works has only one selection (Quarter). This is the query that works: include('connect_visits.php'); doDB7(); $limitStart = $_POST['QUARTER'] - 13; $Visit_data="SELECT Visits15.ID, Visits15.WVisits, Visits15.WCom, WeekNo15.WNo, WeekNo15.WCom FROM Visits15 LEFT JOIN WeekNo15 ON Visits15.ID = WeekNo15.WNo ORDER BY Visits15.ID LIMIT {$limitStart}, 13"; $Visit_data_res = mysqli_query($mysqli, $Visit_data) or die(mysqli_error($mysqli)); $display_block = " <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Week No</th> <th>Week Commencing</th> <th>Visits</th> </tr>"; while ($C_info = mysqli_fetch_array($Visit_data_res)) { $Cid = $C_info['ID']; $Visits = ($C_info['WVisits']); $WeekNo = ($C_info['WCom']); //add to display $display_block .= " <tr> <td width=\"1%\" valign=\"top\">".$Cid."<br/></td> <td width=\"8%\" valign=\"top\">".$WeekNo."<br/></td> <td width=\"5%\" valign=\"top\">".$Visits."<br/></td> </td></tr>"; } mysqli_free_result($Visit_data_res); ?> Here is the query that does not work: <? include('connect_visits.php'); doDB7(); echo $_POST['QUARTER']," ", $_POST['country']; echo $_POST['QUARTER'] - 13; $limitStart = $_POST['QUARTER'] - 13; $Visit_data="SELECT WeekNo15.WNo, WeekNo15.WCom, Countries.Country, ctryvisits15.CVisits FROM ctryvisits15 LEFT JOIN Countries ON ctryvisits15.country = Countries.CID LEFT JOIN WeekNo15 ON ctryvisits15.WNo=WeekNo15.WNo WHERE Countries.CID = '{$_POST['country']}' ORDER BY ctryvisits15.WNo LIMIT {$limitStart}, 13"; $Visit_data_res = mysqli_query($mysqli, $Visit_data) or die(mysqli_error($mysqli)); $display_block = " <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Week No</th> <th>Week Commencing</th> <th>Visits</th> </tr>"; while ($C_info = mysqli_fetch_array($Visit_data_res)) { $Cid = $C_info['WNo']; $Visits = ($C_info['CVisits']); $WeekNo = ($C_info['WCom']); //add to display $display_block .= " <tr> <td width=\"1%\" valign=\"top\">".$Cid."<br/></td> <td width=\"8%\" valign=\"top\">".$WeekNo."<br/></td> <td width=\"5%\" valign=\"top\">".$Visits."<br/></td> </td></tr>"; } mysqli_free_result($Visit_data_res); $CNo2Cty ="SELECT CID, Country FROM Countries WHERE CID='{$_POST['country']}'"; $CNo2Cty_res =mysqli_query($mysqli, $CNo2Cty) or die(mysqli_error($mysqli)); if (mysqli_num_rows($CNo2Cty_res)<1){ $display_block="<p><em>Invalid Country, Please try again</em></p>"; } while ($C_name = mysqli_fetch_array($CNo2Cty_res)) { $Country = ($C_name['Country']); } mysqli_free_result($CNo2Cty_res); mysqli_close($mysqli); ?> I added a couple of echos to see if the POST's where working and the $limitstart was being calculated OK. Which it was! It would appear that the LIMIT clause is not working in the incorrect script, as the list for the first quarter shows weeks greater than 13, when the 1st Quarter is selected and nothing when 2nd Quarter is selected. I am using the LIMIT offset, count parameters, which for quarter 2 will be LIMIT 13, 13, that is display data from row 14 and display 13 rows (NB. rows number starts at 0). Can anyone explain why this query is not working for the script with 2 POST's?
  6. How can I display the Week No as well as the Week Commencing date in a dropdown list? Here is the code: <?php include("connect_visits.php"); //connect to database doDB7(); //Function to build select options based on passed array $WeekNos[] = array($WkNo_info['WNo'], $WkNo_info['WCom']); buildSelectOptions($WeekNos); function buildSelectOptions($options) { $optionsHTML = "<select name=\"WeekNo\">\r\n"; foreach($options as $id => $label) { $optionsHTML .= "<option value='{$id}'>{$label}</option>\n"; } return $optionsHTML; } //Run query to get the Week No and Week Commencing from the table //Then populate into an array $WkNoList_sql = "SELECT WNo, WCom FROM WeekNo15"; $WkNoList_res = mysqli_query($mysqli, $WkNoList_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($WkNoList_res) < 1) { //this Week No does not exist $display_block = "<p><em>You have selected an invalid Week.<br/> Please try again.</em></p>"; } $WeekNos = array(); while($WkNo_info = mysqli_fetch_array($WkNoList_res)) { $WeekNos [$WkNo_info['WNo']] = $WkNo_info['WCom']; } $WNo_Options = buildSelectOptions($WeekNos); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Yosemite Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20091106 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>1066 Cards 4U - Stats Menu</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"><!-- start #wrapper --> <div id="menu"><!-- start #menu --> <ul> <li class="current_page_item"><a href="index.php">Home</a></li> <li><a href="Links.html">Links</a></li> <li><a href="Verse_Menu.html">Verses</a></li> <li><a href="Techniques.html">Techniques</a></li> <li><a href="blog.php">Blog</a></li> <li><a href="Gallery.html">Gallery</a></li> <li><a href="contact.html">Contact</a></li> <li><a href="AboutUs.html">About Us</a></li> <li><a href="Stats_Menu.html">Stats</a></li> </ul> </div><!-- end #menu --> <div id="header"><!-- start #header --> <div id="logo"> <!-- start logo --> <h1><a href="http://www.1066cards4u.co.uk">1066 Cards 4U</a></h1> </div><!-- end logo --> </div><!-- end #wrapper --> </div><!-- end #header --> <div id="page"><!-- start page --> <div id="page-bgtop"><!-- start page-bgtop --> <div id="page-bgbtm"><!-- start page-bgbtm --> <div id="content"><!-- start #content --> <h2>Stats for Week Commencing for the year 2015</h2> <p>Please select Week Commencing Date to get the stats</p> <p><form action="VByWeek15.php" method="post"> Week Commencing: <SELECT name="WeekNo"> <option value= "<?php echo $WNo_Options;?>" </option> </select> </br></br> <input type="submit" value="Submit Choice"> </form></p> </div><!-- end #content --> <div id="sidebar"><!-- start #sidebar --> <div id="search" ><!-- start #search --> <h2><font color="blue">SITE SEARCH</h2> <script> (function() { var cx = '018330043583532205772:h1v3z6ucuna'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); })(); </script> <gcse:search></gcse:search> </div><!-- end #search --> <div style="clear: both;"> </div> <br /><br /><br /><br /> <p>We LOVE 1066 Country!<br /> Visit the UK and come to 1066 Country. </p> </div><!-- end #sidebar --> <div style="clear: both;"> </div> </div><!-- end #page-bgtop --> </div><!-- end #page-bgbtm --> </div><!-- end #page --> <div id="footer"><!-- start #footer --> <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/" rel="nofollow">FreeCSSTemplates.org</a>.</p> </div><!-- end #footer --> </body> </html> The users find it difficult to relate the dates to the week nos hence my wish to change,
  7. I am still as confused as ever! How do I use the jscript variables in the form? Do I put the form Submit tag at the end? I have a multi part form using HTML tags. Can I put this jscript code in with it or do I have to run it separately? An example of similar code would help enormously.
  8. II am new to jscript and AJAX and have a problem that I need to solve. I have a form on which I need to input the RGB values of a color that will be used in the next PHP file. I have choosen a color chooser written in jscript called JS-Color. There are a number of pre-written scripts for choosing the color, of which I have used the following: <script type="text/javascript" src="jscolor/jscolor.js"></script> R<input id="red" size="5"> G<input id="grn" size="5"> B<input id="blu" size="5"> - - - H<input id="hue" size="5"> S<input id="sat" size="5"> V<input id="val" size="5"> <p> Choose any color: <input class="color" id="myColor" onchange=" document.getElementById('red').value = this.color.rgb[0]*100 + '%'; document.getElementById('grn').value = this.color.rgb[1]*100 + '%'; document.getElementById('blu').value = this.color.rgb[2]*100 + '%'; document.getElementById('hue').value = this.color.hsv[0]* 60 + '°'; document.getElementById('sat').value = this.color.hsv[1]*100 + '%'; document.getElementById('val').value = this.color.hsv[2]*100 + '%';"> I am trying to work out how to use this to get the 3 values that I can post in a form. Looking at the internet, I have found that AJAX is the easiest way to POST from jscript. I have attempted to write some script, but I'm sure I'm way off the mark. Here is my attempt: <!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Yosemite Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20091106 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" href="style.css" /> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> </head> <body> <div id="wrapper"><!-- start #wrapper --> <div id="menu"><!-- start #menu --> <ul> <li class="current_page_item"><a href="index.php">Home</a></li> <li><a href="Links.html">Links</a></li> <li><a href="Verse_Menu.html">Verses</a></li> <li><a href="Techniques.html">Techniques</a></li> <li><a href="blog.php">Blog</a></li> <li><a href="Gallery.html">Gallery</a></li> <li><a href="contact.html">Contact</a></li> <li><a href="AboutUs.html">About Us</a></li> <li><a href="Stats_Menu.html">Stats</a></li> </ul> </div><!-- end #menu --> <div id="header"><!-- start #header --> <div id="logo"> <h1><a href="http://www.1066cards4U.co.uk">1066 Cards 4U</a></h1> </div> </div><!-- end #header --> <div id="page"><!-- start #page --> <div id="page-bgtop"><!-- start #page-bgtop --> <div id="page-bgbtm"><!-- start #page-bgbtm --> <div id="content"><!-- start #content --> <h1>Page Title</h1> <script type="text/javscript"> $(function (){ $('#form_id').on('submit', function(e){ e.preventDefault(); $.ajax({ type: "POST", url: "/test_input.php", data: $(this).color.rgb[0]*255, $(this).color.rgb[1]*255, $(this).color.rgb[2]*255, success: function() { alert('success'); } }); }); }); </script> <form method="post" id="form_id"> <script type="text/javascript" src="jscolor/jscolor.js?refresh=adsl"></script> <script type="text/javascript"> jscolor.dir = "jscolor/"; </script> <script type="text/javascript" src="jscolor/jscolor.js"></script> R<input id="red" size="5"> G<input id="grn" size="5"> B<input id="blu" size="5"> H<input id="hue" size="5"> S<input id="sat" size="5"> V<input id="val" size="5"> <p> Choose any color: <input class="color" id="myColor" onchange=" document.getElementById('red').value = this.color.rgb[0]*255; document.getElementById('grn').value = this.color.rgb[1]*255; document.getElementById('blu').value = this.color.rgb[2]*255; document.getElementById('hue').value = this.color.hsv[0]* 60 + '°'; document.getElementById('sat').value = this.color.hsv[1]*100 + '%'; document.getElementById('val').value = this.color.hsv[2]*100 + '%';"> <input type="submit" id="submit" name="submit" value="Send"> </form> <br /><br /><br /><br /> </div><!-- end #content --> <div id="sidebar"><!-- start #sidebar --> <div id="search" ><!-- start #search --> <h2><font color="blue">SITE SEARCH</h2> <script> (function() { var cx = '018330043583532205772:h1v3z6ucuna'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); })(); </script> <gcse:search></gcse:search> </div><!-- end #search --> <div style="clear: both;"> </div><!-- start and end #style --> </div><!-- end #sidebar --> <div style="clear: both;"> </div> </div><!-- end #page-bgbtm --> </div><!-- end #page-bgtop --> </div><!-- end #page --> </div><!-- end #wrapper --> <div id="footer"><!-- start #footer --> <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/" rel="nofollow">FreeCSSTemplates.org</a>.</p> <p>Copyright (c) 2013 - 1066 Cards 4U - content and design</p> <p><a href="sitemap.html"><font color="blue">Sitemap</font></a></p> </div><!-- end #footer --> </body> </html> Which is the variable that I can use? Is it this.color.rgb[0]*255; for example? I have created a variable $red etc, but it does not even open the test_input.php file. None of the examples I have seen on the internet relate to the task I am trying to figure out. Can anyone advise me?
  9. I agree! But that was the only thing I changed. Do all fields that you want to use have to be in the query?
  10. Your observation alone did not solve the problem. I noticed that the field ctryvisits.country was not in the SELECT query. After adding that it worked. Thanks very much! when you are working on the same code sometimes you miss the most obvious.
  11. No! I have table that stores week nos viz. weeks 1 to 52. That table has a date against each week no. Each year will have a separate table. I am away from my PC at the moment I will check the script.
  12. I am querying my database to show the visit statistics for a particular week and it shows the number of visits for the countries, but does not display the country name. I have proved that the MySQL works by going into phpMyAdmin and pasting the query into SQL query tab, replacing the POST with 1, for week 1. I can't see why it is not displying the country. Here is the code: <?php include('connect_visits.php'); doDB7(); $WVisit_data="SELECT WeekNo15.WNo, WeekNo15.WCom, Countries.Country, Countries.CID, ctryvisits15.CVisits FROM ctryvisits15 LEFT JOIN Countries ON ctryvisits15.country = Countries.CID LEFT JOIN WeekNo15 ON ctryvisits15.WNo = WeekNo15.WNo WHERE ctryvisits15.WNo = '{$_POST['WeekNo']}' ORDER BY ctryvisits15.CVisits DESC"; $WVisit_data_res = mysqli_query($mysqli, $WVisit_data) or die(mysqli_error($mysqli)); $display_block =" <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Country</th> <th>Visits</> </tr>"; while ($WV_info = mysqli_fetch_array($WVisit_data_res)){ $Ctry = $WV_info['country']; $Visits = $WV_info['CVisits']; //add to display $display_block .=" <tr> <td width=\"10%\" valign=\"top\">".$Ctry."<br/></td> <td width=\"5%\" valign=\"top\">".$Visits."<br/></td> "; } mysqli_free_result($WVisit_data_res); mysqli_close($mysqli); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Yosemite Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20091106 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>1066 Cards 4U - Stats for country</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="menu"> <ul> <li class="current_page_item"><a href="index.php">Home</a></li> <li><a href="Links.html">Links</a></li> <li><a href="Verse_Menu.html">Verses</a></li> <li><a href="Techniques.html">Techniques</a></li> <li><a href="blog.php">Blog</a></li> <li><a href="Gallery.html">Gallery</a></li> <li><a href="contact.html">Contact</a></li> <li><a href="AboutUs.html">About Us</a></li> <li><a href="stats1.html">Stats</a></li> </ul> </div><!-- end #menu --> <div id="header"> <div id="logo"> <h1><a href="http://www.1066cards4u.co.uk">1066 Cards 4U</a></h1> </div><!-- end #wrapper --> </div><!-- end #header --> <div id="page"> <div id="page-bgtop"> <div id="page-bgbtm"> <div id="content"> <h3>Statistics for Week Commencing <? echo $WkCom; ?> in 2015</h3> <div id="table"> <?php echo $display_block; ?></div> </div><!-- end #content --> </body> </html> Can you help please?
  13. Found that <form> tag was not closed.
  14. I have been using some CSS written by Matthew Taylor (www.http://matthewjamestaylor.com), for displaying my web page on iPad orsimilar device. It works in most cases but for some reason it gives strange results when I try to output a table in the main screen area. It puts the title heading in the right place, but the table for some reason underneath the footer and the page menu disappears completely. It is usually caused by unclosed div tags, but I have checked them and they appear to be correct. There is a good explaination of how the CSS works on his web site. Here is the code for the PHP/HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)"> <meta name="dcterms.created" content="Sat, 02 Mar 2013 20:21:23 GMT"> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="viewport" content="width=768px, minium-scale=1.0, maximum-scale=1.0" /> <title></title> <link rel="stylesheet" href="stylesheets/ipad.css" /> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div id="fb-root"> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script></div><!--end fb-root--> <div id="wrap"> <!--Start wrap--> <div id="header"> <!--Start header--> <img src="images/Head!.png" width="100%" height="150px" alt="" title="" border="0" /> <h1>1066 cards4U</h1> </div><!-- end header --> <div id="content"> <!--Start content--> <div id="main"> <!--Start main--> <h3>Statistics for <? echo $Country; ?> in 2014</h3> <h4>If only the header is shown, there is no data for this country</h4> <?php include('connect_visits.php'); doDB7(); $limitStart = $_POST['QUARTER'] - 13; $Visit_data="SELECT WeekNo.WNo, WeekNo.WCom, Countries.Country, ctryvisits.CVisits FROM ctryvisits LEFT JOIN Countries ON ctryvisits.country = Countries.CID LEFT JOIN WeekNo ON ctryvisits.WNo=WeekNo.WNo WHERE Countries.CID = '{$_POST['country']}' ORDER BY ctryvisits.WNo LIMIT {$limitStart}, 13"; $Visit_data_res = mysqli_query($mysqli, $Visit_data) or die(mysqli_error($mysqli)); $display_block = " <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Week No</th> <th>Week Commencing</th> <th>Visits</th> </tr>"; while ($C_info = mysqli_fetch_array($Visit_data_res)) { $Cid = $C_info['WNo']; $Visits = ($C_info['CVisits']); $WeekNo = ($C_info['WCom']); //add to display $display_block .= " <tr> <td width=\"1%\" valign=\"top\">".$Cid."<br/></td> <td width=\"8%\" valign=\"top\">".$WeekNo."<br/></td> <td width=\"5%\" valign=\"top\">".$Visits."<br/></td> </td></tr>"; } mysqli_free_result($Visit_data_res); $CNo2Cty ="SELECT CID, Country FROM Countries WHERE CID='{$_POST['country']}'"; $CNo2Cty_res =mysqli_query($mysqli, $CNo2Cty) or die(mysqli_error($mysqli)); if (mysqli_num_rows($CNo2Cty_res)<1){ $display_block="<p><em>Invalid Country, Please try again</em></p>"; } while ($C_name = mysqli_fetch_array($CNo2Cty_res)) { } mysqli_free_result($CNo2Cty_res); //mysqli_close(mysqli); ?> <?php echo $display_block; ?> <div class="fb-comments" data-href="http://www.1066cards4u.co.uk" data-width="470"></div><br /> <div class="fb-like" data-href="http://www.1066cards4u.co.uk" data-send="true" data-layout="box_count" data-width="300" data-show-faces="true" data-font="arial"></div> <!-- end fb-like --> </div> <!--end main--> <div id="side"> <!--Start side--> <div id="sidea"> <!--Start sidea--> <h3>Main Menu</h3> <p><ul> <li><a href="index1.html">Home</a></li> <li><a href="iLinks.html">Links</a></li> <li><a href="iTechniques.html">Techniques</a></li> <li><a href="iVerse_Menu.html">Verse's</a></li> <li><a href="icontact.html">Contact Us</a></li> <li><a href="iblog.php">Blog</a></li> <li><a href="iAboutUs.html">About Us</a></li> <li><a href="iGallery.html">Gallery</a></li> <li><a href="iStats_Menu.html">Stats</a></li> <li><a href="iRelHol_Menu.html">Religious Holiday's</a></li> <li><a href="iSub_form.html">Subscribe to Newsletter</a></li> </ul></p> </br> </div> <!--end sidea--> <div id="sideb"> <!--Start sideb--> </div> <!--end sideb--> <div id="sidec"> <!--Start sidec--> </div> <!--end sidec--> </div> <!--end side--> </div> <!--end content--> <div id="footer"> <!--Start footer--> <p>© 2012 Content:1066 Cards 4U. All rights reserved. <br /> With thanks to Matt Taylor - matthewjamestaylor.com</p> </div> <!--end footer--> </div> <!--end wrap--> </body> </html> Here is the CSS: * { margin:0; padding:0; } h2 { padding:1em 0 0 0; } p { line-height:1.4em; } p + p { text-indent:2em; } body { font-size:100%; text-align:center; background:#ddd; } pre { display:block; margin:1em 0 0 0; width:488px; } pre code { background:#eee; display:block; padding:10px; } .r { float:right; padding:0 0 10px 20px; } /* Landscape mode (default) */ #wrap { margin:0 auto; width:1024px; position:relative; overflow:hidden; text-align:left; background:#fff; } #header { float:left; width:1024px; padding:10px 0 20px 0; background:#fff; border-bottom:1px solid #000; } #header h1 { padding:10px 30px 0 30px; } #header p { padding:0 30px; line-height:1.4em; } #content { float:left; width:1024px; background:#eee; position:relative; left:768px; } #main { float:left; width:708px; position:relative; right:738px; padding:20px 0; } #side { float:right; width:216px; position:relative; right:788px; padding-bottom:20px; } #sidea, #sideb, #sidec { clear:left; float:left; width:216px; } #footer { clear:both; float:left; width:1024px; border-top:1px solid #000; background:#ddd; } #footer p { padding:20px 30px; } @media only screen and (orientation:portrait){ /* portrait mode */ #header, #wrap, #footer { } #content { left:0; background:#fff; } #main { float:left; width:708px; position:relative; right:0; left:30px; padding:20px 0; } #side { clear:left; float:left; width:768px; right:0; padding-bottom:20px; background:#eee; } #sidea { clear:none; width:216px; float:left; position:relative; left:30px; padding-top:20px; } #sideb { clear:none; width:216px; float:left; position:relative; left:60px; padding-top:20px; } #sidec { clear:none; width:216px; float:right; position:relative; right:30px; padding-top:20px; } #footer { position:absolute; bottom:0; width:100%; height:60px; /* Height of the footer */ background:#6cf; width:768px; } } I have spent hours trying different things, but I can't find a solution. I believe its a CSS problem, but if you think it is HTML can the moderator move it? Your help would be appreciated.
  15. Thanks I have now got the code to work Hereis the completed code snippet: <?php include("connect_visits.php"); //connect to database doDB7(); //Function to build select options based on passed array $countries[] = array($Ctry_info['CID'], $Ctry_info['Country']); buildSelectOptions($countries); function buildSelectOptions($options) { $optionsHTML = "<select name=\"Countries\">\r\n"; foreach($options as $id => $label) { $optionsHTML .= "<option value='{$id}'>{$label}</option>\n"; } return $optionsHTML; } //Run query to get the ID and Name from the table //Then populate into an array $clist_sql = "SELECT CID, Country FROM Countries"; $clist_res= mysqli_query($mysqli, $clist_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($clist_res) < 1) { //this Country not exist $display_block = "<p><em>You have selected an invalid Country.<br/> Please try again.</em></p>"; } $countries = array(); while($Ctry_info = mysqli_fetch_array($clist_res)) { $countries [$Ctry_info['CID']] = $Ctry_info['Country']; } $countryOptions = buildSelectOptions($countries); ?> Many thanks all!
  16. Right it now works! It needed quotes around the php code: <option value= "<?php echo $countryOptions;?>" </option> But I need to POST to the next programme the CID value and only show the country name in the box for the users to choose. How do I acheive that? The code so far: <? include("AddStats_admin_connect.php"); //connect to database doDB(); //Function to build select options based on passed array $countries[] = array($Ctry_info['CID'], $Ctry_info['Country']); function buildSelectOptions($options) { $optionsHTML = "<select name=\"Countries\">\r\n"; foreach($options as $id => $label) { $optionsHTML .= "<option value='{$id}'>{$label}</option>\n"; } return $optionsHTML; } //Run query to get the ID and Name from the table //Then populate into an array $clist_sql = "SELECT CID, Country FROM Countries"; $clist_res= mysqli_query($mysqli, $clist_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($clist_res) < 1) { //this Country not exist $display_block = "<p><em>You have selected an invalid Country.<br/> Please try again.</em></p>"; } $countries = array(); while($Ctry_info = mysqli_fetch_array($clist_res)) { $countries [$Ctry_info['CID']] = $Ctry_info['Country']; } $countryOptions = buildSelectOptions($countries); //print_r($countries) ?> <!DOCTYPE html> <html lang="en"> <head> <title>Stats</title> <link rel="stylesheet" href="stylesheets/style.css" /> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <!--<? echo $countryOptions; ?> </br></br></br></br></br></br></br></br> <!Later in the HTML for the page <!-- You need to set up the select element to house the options. This will be set in $_POST as $_POST['country'] --> <form action="CountryOptions.php" method="post"> <select name="country"> <option value= "<?php echo $countryOptions;?>" </option> </select> <input type="submit" value="Submit Choice"> </form></p> </body> </html> Nearly there!
  17. Here is the code so far: <? include("AddStats_admin_connect.php"); //connect to database doDB(); //Function to build select options based on passed array $countries[] = array($Ctry_info['CID'], $Ctry_info['Country']); function buildSelectOptions($options) { $optionsHTML = "<select name=\"Countries\">\r\n"; foreach($options as $id => $label) { $optionsHTML .= "<option value='{$id}'>{$label}</option>\n"; } return $optionsHTML; } //Run query to get the ID and Name from the table //Then populate into an array $clist_sql = "SELECT CID, Country FROM Countries"; $clist_res= mysqli_query($mysqli, $clist_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($clist_res) < 1) { //this Country not exist $display_block = "<p><em>You have selected an invalid Country.<br/> Please try again.</em></p>"; } $countries = array(); while($Ctry_info = mysqli_fetch_array($clist_res)) { $countries[$Ctry_info['CID']] = $Ctry_info['Country']; } $countryOptions = buildSelectOptions($countries); print_r($countries) ?> <!DOCTYPE html> <html lang="en"> <head> <title>Stats</title> <link rel="stylesheet" href="stylesheets/style.css" /> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <!--<? echo $countryOptions; ?> </br></br></br></br></br></br></br></br> <!Later in the HTML for the page <form action="CountryOptions.php" method="post"> <!-- You need to set up the select element to house the options. This will be set in $_POST as $_POST['country'] --> <select name="country"> <?php echo $optionsHTML; ?> </select> <input type="submit" value="Submit Choice"> </form></p> </body> </html> By the way the value I need to POST is the CID, but need the country for the user to identify the country. Your help is appreciated! Happy New Year! I guess in about 6 hours for you.
  18. OK! I have corrected this line: <option value='{$id}'>{$label}</option>\n And this line: foreach($options as $id => $label) added a print_r to check the array output. It prints all of the data, but still the combo box is empty! The line 6: $countries[] = array($Ctry_info['CID'], $Ctry_info['Country']); Why is this before the function? I wondered that this should have replaced line 30: $countries = array(); But this did not make any difference. Still an empty combo box.
  19. Right! Looked at all your comments and incorperated both maxxd code where different and Handsford's 2 cents, regarding function. Here is the code as I see it: <? include("AddStats_admin_connect.php"); //connect to database doDB(); //Function to build select options based on passed array $countries[] = array($Ctry_info['CID'], $Ctry_info['Country']); function buildSelectOptions($options) { $optionsHTML = "<select name=\"countries\">\r\n"; foreach($options as $c) { $optionsHTML .= "<option value=\"{$c[0]}\">$c[1]</option>\r\n"; } $optionsHTML .= "</select>\r\n"; return $optionsHTML; } //Run query to get the ID and Name from the table //Then populate into an array $clist_sql = "SELECT CID, Country FROM Countries"; $clist_res= mysqli_query($mysqli, $clist_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($clist_res) < 1) { //this Country not exist $display_block = "<p><em>You have selected an invalid Country.<br/> Please try again.</em></p>"; } $countries = array(); while($Ctry_info = mysqli_fetch_array($clist_res)) { $countries = $Ctry_info['Country']; } $countryOptions = buildSelectOptions($countries); ?> <!DOCTYPE html> <html lang="en"> <head> <title>Stats</title> <link rel="stylesheet" href="stylesheets/style.css" /> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <!--<? echo $countryOptions; ?> </br></br></br></br></br></br></br></br> <!Later in the HTML for the page <form action="CountryOptions.php" method="post"> <!-- You need to set up the select element to house the options. This will be set in $_POST as $_POST['country'] --> <select name="country"> <?php echo $optionsHTML; ?> </select> <input type="submit" value="Submit Choice"> </form></p> </body> </html> I now get a small empty combo box with no data in it? I think the trouble must be the Function, but I am not an expert. I did not understand the line: $countries[$Ctry_info['CID'] = $Ctry_info['Country']]; So changed it to this: $countries = $Ctry_info['Country']; But got the following error when run: Warning: Invalid argument supplied for foreach() in /homepages/43/d344817611/htdocs/Admin/CountryOptions.php on line 12 I guess that the function was not being run, as the code dropped out before it got to the function. I'm guessing this am I right? Any more ideas! By the way I will look at PDO, but thats one step too far at the momment.
  20. This is a continuation of a previous post. I am trying to get the names of countries that are in a database table. It's not working! All I get is a Submit button, but no data. This is what I understand from the code that Psycho suggested: I am unfamiliar with the function and the use of the FOREACH constuct. looking at the PHP manual there are two syntaxes. It appears that Psyhco has used the second form where the current element's key is assigned to $key variable for each itteration. foreach (array_expression as $key => $value The 2 variables he used are $id and $label I assume that the line: $optionsHTML = ''; is the array built from the expression: $optionsHTML .= "{$label}\n"; Because I was not familiar with the PDO method, but have used mysqli, I had to rewrite the data retrival part which I believe is OK. I guess that the line : $countryOptions = buildSelectOptions($countries); is used in conjunction with the function to build the array. The HTML part that Psycho wrote puts the variable into the Form format for a selection list. Why is the $optionsHTML also inclosed in the option tags? Have I got the HTML part correct or is it the data extraction part that is incorrect? Here is the code: <? include("AddStats_admin_connect.php"); //connect to database doDB(); //Function to build select options based on passed array function buildSelectOptions($options) { $optionsHTML = ''; foreach($options as $id => $label) { $optionsHTML .= "<option value='{$id}'>{$label}</option>\n"; } return $optionsHTML; } //Run query to get the ID and Name from the table //Then populate into an array $clist_sql = "SELECT CID, Country FROM Countries"; $clist_res= mysqli_query($mysqli, $clist_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($clist_res) < 1) { //this Country not exist $display_block = "<p><em>You have selected an invalid Country.<br/> Please try again.</em></p>"; } $countries = array(); while($Ctry_info = mysqli_fetch_array($clist_res)) { $countries[$Ctry_info['CID'] = $Ctry_info['Country']]; } $countryOptions = buildSelectOptions($countries); ?> <!DOCTYPE html> <html lang="en"> <head> <title>Stats</title> <link rel="stylesheet" href="stylesheets/style.css" /> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <? echo $countryOptions; ?> </br></br></br></br></br></br></br></br> <!Later in the HTML for the page <form action="Ctrystats.php" method="post"> <option name="country" value=<? echo $countryOptions;?>Country</option></br></br> <input type="submit" value="Submit Choice"> </form></p> </body> </html> I think I am nearly there so I would appreciate some help to finish this coding. Note: If you make your questions easy to read, then you have better chances of a quality answer. Use [ code ] ] tags.
  21. When I statred to write a reply to you, I realised my error. I was trying to JOIN ON to the date and not the foriegn key in the table. Many thanks!
  22. I am trying to write some code to display the visits to my site each week in batches of 13 weeks (1 quarter). I am getting the Week No and the number of hits, but the actual date, which is in a separate table is not being displayed. I have tried LEFT JOIN and INNER Join and even RIGHT JOIN (this only displays the Date). I can't see where I am going wrong! Here is the code: <? include('connect_visits.php'); doDB7(); $limitStart = $_POST['QUARTER'] - 13; $Visit_data="SELECT Visits.ID, Visits.WVisits, Visits.WCom, WeekNo.WNo, WeekNo.WCom FROM Visits LEFT JOIN WeekNo ON Visits.ID = WeekNo.WCom ORDER BY Visits.ID LIMIT {$limitStart}, 13"; $Visit_data_res = mysqli_query($mysqli, $Visit_data) or die(mysqli_error($mysqli)); $display_block = " <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Week No</th> <th>Week Commencing</th> <th>Visits</th> </tr>"; while ($C_info = mysqli_fetch_array($Visit_data_res)) { $Cid = $C_info['ID']; $Visits = ($C_info['WVisits']); $WeekNo = ($C_info['WCom']); //add to display $display_block .= " <tr> <td width=\"1%\" valign=\"top\">".$Cid."<br/></td> <td width=\"8%\" valign=\"top\">".$WeekNo."<br/></td> <td width=\"5%\" valign=\"top\">".$Visits."<br/></td> </td></tr>"; } mysqli_free_result($Visit_data_res); ?> Where am I going wrong?
  23. Thanks for the help! I did change the rows part to 13, as when I choose 2nd and 3rd quarter the rest of the year data.
  24. I have got a set of data for a country for each week of the year, but want to display the data a quarter at a time, using a form which posts a value into LIMIT, which was OK for the 1st quarter, but for subsequent quarters I needed to use LIMIT in the form LIMIT start, rows. I found by experiment that this had to be the last statement in the query. when I added the start I got an error: Parse error: syntax error, unexpected ',' in /homepages/43/d344817611/htdocs/Admin/Visitdata.php on line 10 Here is the SQL part of my code: $Visit_data="SELECT WeekNo.WNo, WeekNo.WCom, Countries.Country, ctryvisits.CVisits FROM ctryvisits LEFT JOIN Countries ON ctryvisits.country=Countries.CID LEFT JOIN WeekNo ON ctryvisits.WNo=WeekNo.WNo WHERE Countries.Country = '".$_POST["Country"]."' ORDER BY ctryvisits.WNo LIMIT '".$_POST["QUARTER"]."'" - 13, '".$_POST["QUARTER"]."'"; Is this the best way of doing what I require or is there an easier way of achieving what I want?
×
×
  • 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.