PHP - Why Does It Show Jan When I Select Nov Or Dec?
I'm going insane. whenever I select Oct, Nov, Dec from the drop down it doesn't show the corresponding month appropriately.
I do this in the code and it shows 10, 11 or 12 corresponding to oct, nov, dec but then it shows no month if it's october, january if it's november or december. Help me please. echo '<br /><br /> form month var dump: '; var_dump($form_month); Code: [Select] $time = time(); $actual_month = date('m', $time); $actual_year = date('Y', $time); $word_month = date('M', $time); $word_year = date('Y', $time); if (isset($_POST['form_month']) && isset($_POST['form_year']) && !empty($_POST['form_month']) && !empty($_POST['form_year']) ) { $form_month = $_POST['form_month']; //multidimensional array but it should have only one value in it at a time I think $form_year = $_POST['form_year']; echo '<br /><br /> form month var dump: '; var_dump($form_month); //echo '<br /><br />'. $form_month['1']; $insert_month = $form_month['0']; //maybe this will work $insert_year = $form_year; }else{ $insert_month = $actual_month; $insert_year = $actual_year; } // I don't know how to convert the number 01 to Jan - so i'm doing this: $wtf_word_month = ""; switch ($insert_month) { case 1: $wtf_word_month = "Jan"; break; case 2: $wtf_word_month = "Feb"; break; case 3: $wtf_word_month = "Mar"; break; case 4: $wtf_word_month = "Apr"; break; case 5: $wtf_word_month = "May"; break; case 6: $wtf_word_month = "June"; break; case 7: $wtf_word_month = "July"; break; case 8: $wtf_word_month = "Aug"; break; case 9: $wtf_word_month = "Sep"; break; case 10: $wtf_word_month = "Oct"; break; case 11: $wtf_word_month = "Nov"; break; case 12: $wtf_word_month = "Dec"; break; } ?> <h2><?php echo $wtf_word_month ." ". $insert_year; ?></h2> <form id="form_month_changer" action="account-overview.php" method="POST"> Choose a month: <select name="form_month"> <option value="<?php echo '$insert_month'; ?>" ><?php echo $wtf_word_month; ?></option> <option value="1">Jan</option> <option value="2">Feb</option> <option value="3">Mar</option> <option value="4">Apr</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">Aug</option> <option value="9">Sept</option> <option value="10">Oct</option> <option value="11">Nov</option> <option value="12">Dec</option> </select> Choose a year <input type="text" name="form_year" maxlength="4" size="4" value="<?php echo $insert_year; ?>"> <input type="submit" value="Show me the calendar"> </form> <?php echo draw_calendar($insert_month,$insert_year); ?> Similar TutorialsThis topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=321311.0 I want to show a cookie of a referral's username on a sign up page. The link is like this, www.mysite.com/signup?ref=johnsmith. The cookie doesn't show if I go to that url page. But it does show up once I reload the page. So I'm wondering if it's possible to show the cookie the first time around, instead of reloading the page? Here is my code. // This is in the header $url_ref_name = (!empty($_GET['ref']) ? $_GET['ref'] : null); if(!empty($url_ref_name)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "ref", $url_ref_name, $date_of_expiry,"/"); } else if(empty($url_ref_name)) { if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; } } else {} // This is for the sign up form if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; ?> <fieldset> <label>Referred By</label> <div id="ref-one"><span><?php if(!empty($user_cookie)){echo $user_cookie;} ?></span></div> <input type="hidden" name="ref" value="<?php if(!empty($user_cookie)){echo $user_cookie;} ?>" maxlength="20" placeholder="Referrer's username" readonly onfocus="this.removeAttribute('readonly');" /> </fieldset> <?php }
hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks I am displaying rows from a database onto a page using: while($row=mysql_fetch_array($query)){ echo $row['name']; } I need to figure out how to limit the rows shown to the page to 100. And if there are 100 rows on the page, a link will be displayed at the bottom, that says "Next 100". Then this will display the next 100 rows. Can you give an example how to do this please? Thanks Hi , I know my code sucks but i'm learning fast!! I'm trying to show a form if the qty value in a database == 10 or a different form if the value ==20. I tried but failed. Any help really appreciated. Code: [Select] <?php require_once('Connections/book.php'); ?> <?php $colname_cardpayment = "-1"; if (isset($_GET['orderid'])) { $colname_cardpayment = (get_magic_quotes_gpc()) ? $_GET['orderid'] : addslashes($_GET['orderid']); } mysql_select_db($database_book, $book); $query_cardpayment = sprintf("SELECT * FROM cards WHERE orderid = '%s' ORDER BY qty ASC", $colname_cardpayment); $cardpayment = mysql_query($query_cardpayment, $book) or die(mysql_error()); $row_cardpayment = mysql_fetch_assoc($cardpayment); $totalRows_cardpayment = mysql_num_rows($cardpayment); // Database connect $con = mysql_connect("mysql1.myhost.ie","admin_book","root123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("book_test", $con); //Parse Values from Coupon.php Form $orderid = mysql_real_escape_string(trim($_POST['orderid'])); $name = mysql_real_escape_string(trim($_POST['name'])); $surname = mysql_real_escape_string(trim($_POST['surname'])); $add1 = mysql_real_escape_string(trim($_POST['add1'])); $add2 = mysql_real_escape_string(trim($_POST['add2'])); $town = mysql_real_escape_string(trim($_POST['town'])); $county = mysql_real_escape_string(trim($_POST['county'])); $postcode = mysql_real_escape_string(trim($_POST['postcode'])); $phone = mysql_real_escape_string(trim($_POST['phone'])); $email = mysql_real_escape_string(trim($_POST['email'])); $letterstyle = mysql_real_escape_string(trim($_POST['letterstyle'])); $sql="INSERT INTO custdetails (orderid, name, surname, add1, add2, town, county, postcode, phone, email, letterstyle) VALUES ('$orderid','$name','$surname','$add1','$add2','$town','$county','$postcode','phone','$email','$letterstyle')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Digital Scribe Books</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } </script> </head> <body onload="MM_preloadImages('images/buttons/home_over.png','images/buttons/books_over.png','images/buttons/cards_over.png','images/buttons/letters_over.png')"> <div id="snow"> <div id="wrapper"> <div id="header"> <div id="logo"><img src="images/digital_scripe.png" width="218" height="91" /></div> <div id="menu"><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Home','','images/buttons/home_over.png',1)"><img src="images/buttons/home_act.png" name="Home" width="131" height="132" border="0" id="Home" /></a><a href="books.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Books','','images/buttons/books_over.png',1)"><img src="images/buttons/books_act.png" name="Books" width="131" height="132" border="0" id="Books" /></a><a href="cards.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Cards','','images/buttons/cards_over.png',1)"><img src="images/buttons/cards_act.png" name="Cards" width="131" height="132" border="0" id="Cards" /></a><a href="letters.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Letters','','images/buttons/letters_over.png',1)"><img src="images/buttons/letters_act.png" name="Letters" width="131" height="132" border="0" id="Letters" /></a></div> </div> <div id="content"> <?php echo 'Order ID is : '. $orderid . '.<br />'; if ($row2['qty'] == 10) echo "<div> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="accounts@agraphics.ie"> <input type="hidden" name="lc" value="IE"> <input type="hidden" name="item_name" value="10 Christmas Cards"> <input type="hidden" name="item_number" value="<? echo $orderid; ?>"> <input type="hidden" name="amount" value="12.99"> <input type="hidden" name="currency_code" value="EUR"> <input type="hidden" name="button_subtype" value="services"> <input type="hidden" name="shipping" value="2.99"> <input type="hidden" name="return" value="http://www.digitalscribe/thanks.php"> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </div>"; if ($row2['qty'] == 20) echo "<div> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="accounts@agraphics.ie"> <input type="hidden" name="lc" value="IE"> <input type="hidden" name="item_name" value="20 Christmas Cards"> <input type="hidden" name="item_number" value="<? echo $orderid; ?>"> <input type="hidden" name="amount" value="21.99"> <input type="hidden" name="currency_code" value="EUR"> <input type="hidden" name="button_subtype" value="services"> <input type="hidden" name="shipping" value="2.99"> <input type="hidden" name="return" value="http://www.digitalscribe/thanks.php"> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </div>"; ?> </div> <div id="footer" class="clear"><div id="sign"><div id="sign_text">Personalised<br /> Books</div> </div></div> </div></div> </body> </html> <?php mysql_free_result($cardpayment); ?> Hi, I would like to do the following but not sure how. If the you/user is on index.php of http://www.domain.com/ show one page If not show another How would I do this? Thanks I have 2 queries that I want to join together to make one row
Dear All, I wish to have 2 drop down boxes, Country Select Box and Locality Select Box. The locality select box will be affected by the value chosen in the country select box. All is working fine except that the locality select box is not being populated. I know that the problem is in the sql statement WHERE country_id='$co' because i am having an error that $co is an undefined variable. All the rest works fine because i have replaced the $co variable directly with a number (say 98) for a particular country id and it worked fine. In what way can i define this variable $co so that it is accepted by my sql statement? Thank you for your help in advance. MySQL Tables indicated below: CREATE TABLE countries( country_id INT(3) UNSIGNED NOT NULL AUTO_INCREMENT, country_name VARCHAR(30) NOT NULL, PRIMARY KEY(country_id), UNIQUE KEY(country_name), INDEX(country_id), INDEX(country_name)) ENGINE=MyISAM; CREATE TABLE localities( locality_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, country_id INT(3) UNSIGNED NOT NULL, locality_name VARCHAR(50), PRIMARY KEY (locality_id), INDEX (country_id), INDEX (locality_name)) ENGINE=MyISAM; Extract PHP script included below: // connect to database require_once(MYSQL); if(isset($_POST['submitted'])) { // trim the incoming data /* this line runs every element in $_POST through the trim() function, and assigns the returned result to the new $trimmed array */ $trimmed=array_map('trim',$_POST); // clean the data $co=mysqli_real_escape_string($dbc,$trimmed['country']); $lc=mysqli_real_escape_string($dbc,$trimmed['locality']); } ?> <form action="form.php" method="post"> <p>Country <select name="country"> <option>Select Country</option> <?php $q="SELECT country_id, country_name FROM countries"; $r=mysqli_query($dbc,$q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); while($row=mysqli_fetch_array($r)) { $country_id=$row[0]; $country_name=$row[1]; echo '<option value="' . $country_id . '"'; if(isset($trimmed['country']) && ($trimmed['country']==$country_id)) echo 'selected="selected"'; echo '>' . $country_name . '</option>\n'; } ?> </select> </p> <p>Locality <select name="locality"> <option>Select Locality</option> <?php $ql="SELECT locality_id, country_id, locality_name FROM localities WHERE country_id='$co' ORDER BY locality_name"; $rl=mysqli_query($dbc,$ql) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); while($row=mysqli_fetch_array($rl)) { $locality_id=$row[0]; $country_id=$row[1]; $locality_name=$row[2]; echo '<option value="' . $locality_id . '"'; if(isset($trimmed['locality']) && ($trimmed['locality']==$locality_id)) echo 'selected="selected"'; echo '>' . $locality_name . '</option>\n'; } // close database connection mysqli_close($dbc); ?> </select> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> Hi I have made a view all albums page for my website and I want it to only show 10 records. If there are more than 10 I would like a next or previous button to appear and for them to take you to the next 10 records or previous 10 records. Please can somebody show me where I can learn how to do this? I know it has something to do with msql_num_rows so I have a variable called $numrows I'll post the code I currently have here <form name="view_all_albums_frm" id="view_all_albums_frm"> <table width="793" border="0" cellspacing="5" id="all_albums_tbl" cellpadding="0"> <tr> <th scope="col">ID</th> <th scope="col">Album</th> <th scope="col">Album Description</th> <th scope="col">Edit</th> <th scope="col">Delete</th> </tr> <tr> <?php $qGetAlbums = ("SELECT * FROM albums ORDER BY `id` asc"); $rGetAlbums = mysql_query($qGetAlbums) or die(mysql_error()); $numrows = mysql_num_rows($rGetAlbums); while($AllAlbums = mysql_fetch_assoc($rGetAlbums)) { ?> <th height="26" scope="col"><?php echo $AllAlbums['id']; ?></th> <th height="26" scope="col"><?php echo $AllAlbums['album_name']; ?></th> <th scope="col"><?php echo $AllAlbums['album_description']; ?></th> <th scope="col"> </th> <th scope="col"> </th> </tr> <?php } ?> </table> </form> I can't understand for the life of me - why the value for the variable: $total_vit_k is 2 in the red box: http://content.screencast.com/users/rockstarvisible/folders/Jing/media/beafff1f-2168-47b8-91bb-950ace0722c2/2012-03-21_1437.png. The reason why I can't understand this is because $total_vit_k is the weekly total for everything from jan 29 to feb 4 but there's no values for those dates logged in the mysql table it's pulling from. Please help me. It should be displaying 0 Mcg in the red box but it isn't. I know it's something wrong in my code. When I echo out all the values in the while loop like below, the browser echos out nothing for the queries from jan 29 2012 to feb 4 2012. code below is from file 2: Code: [Select] while ($row = mysql_fetch_assoc($query_run)){ echo "<br /><br /><b><i>" . '$sql_food ' . $sql_food."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_total_servings ' . $sql_total_servings."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_day ' . $sql_day."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_month ' . $sql_month."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_year ' . $sql_year."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_vit_k ' . $sql_vit_k."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . ' $sql_servings ' . $sql_servings."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . ' $total_vit_k ' . $total_vit_k."</b></i><br /><br/ >"; include 'inside_while.acc-over.php'; } full code for file2: Code: [Select] <?php if(!function_exists('getWeeklyVitK') ){ function getWeeklyVitK($value, $bday, $bmonth, $byear, $eday, $emonth, $eyear){ //initialize the variables so no errors occur $query_month =$bmonth; $query_year =$byear; $query_day = $bday; //initialize variables $total_vit_k = 0; //$total_cal = 0; //$total_protein = 0; //$total_fiber = 0; //$total_carbs = 0; //$total_sugar = 0; //$total_sodium = 0; //$total_chol = 0; if ($value==1){ echo "Something went wrong - tell pavankat[at]gmail."; break; } if ($value==2){ // if $value = 2 // end day >= start day // end month = start month // end year = start year $day_temp = $eday; while($bday<=$day_temp){ $query_day = $bday; //redeclare the mysql query include 'acc-over-sql-queries.php'; if ($query_run = mysql_query($query_value2)){ while ($row = mysql_fetch_assoc($query_run)){ include 'inside_while.acc-over.php'; } } $bday++; } return round($total_vit_k, 2); } if ($value==3){ // if $value = 3 // end day and beg day don't matter // end month > beg month // end year = beg year for($bmonth; $bmonth<=$emonth; $bmonth++){ $query_month = $bmonth; $days_in_month = date('t',mktime(0,0,0,$query_month,1,$byear)); $day_temp = $days_in_month; echo "<br />day_temp variable:<u> ".$day_temp. "</u><br />"; while($bday<=$day_temp){ $query_day = $bday; //redeclare the mysql query include 'acc-over-sql-queries.php'; echo "<br />".'$query_value3:' . $query_value3 . "<br />"; if ($query_run = mysql_query($query_value3)){ while ($row = mysql_fetch_assoc($query_run)){ echo "<br /><br /><b><i>" . '$sql_food ' . $sql_food."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_total_servings ' . $sql_total_servings."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_day ' . $sql_day."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_month ' . $sql_month."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_year ' . $sql_year."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . '$sql_vit_k ' . $sql_vit_k."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . ' $sql_servings ' . $sql_servings."</b></i><br /><br/ >"; echo "<br /><br /><b><i>" . ' $total_vit_k ' . $total_vit_k."</b></i><br /><br/ >"; include 'inside_while.acc-over.php'; } } $bday++; } $bday = 1; } //return round($total_vit_k, 2); return $total_vit_k; } if ($value==4){ // if $value = 4 // end day and beg day dont matter // end month and beg month dont matter // end year > beg year for($byear; $byear<=$eyear; $byear++){ $query_year = $byear; $month_temp = 12; while($bmonth<=$month_temp){//while loop starts $query_month = $bmonth; //cycle through the days $days_in_month = date('t',mktime(0,0,0,$query_month,1,$byear)); $day_temp = $days_in_month; while($bday<=$day_temp){ $query_day = $bday; //redeclare the mysql query include 'acc-over-sql-queries.php'; if ($query_run = mysql_query($query_value4)){ while ($row = mysql_fetch_assoc($query_run)){ include 'inside_while.acc-over.php'; } } //-----------------------------------$bday++ unless stuff if ($byear < $eyear){ $bday++; }else if ($byear == $eyear){ if ($bmonth < $emonth){ $bday++; }else if($bmonth == $emonth){ if ($bday < $eday){ $bday++; }else if($bday == $eday){ $bday = $day_temp+1; } } } //-----------------------------------$bday++ unless stuff }//while day loop end $bday = 1; //-----------------------------------$bmonth++ unless stuff if ($byear < $eyear){ $bmonth++; }else if ($byear == $eyear){ if ($bmonth < $emonth){ $bmonth++; }else if($bmonth == $emonth){ $bmonth = 13; } } //-----------------------------------$bmonth++ unless stuff }//while loop ends if ($byear <= $eyear){ $bmonth = 1; } } return round($total_vit_k, 2); } } } ?> full code for the contents of the while loop: Code: [Select] <?php $sql_food = $row["name"]; $sql_year = $row["calendar_year"]; $sql_month = $row["calendar_month"]; $sql_day = $row["calendar_day"]; $sql_total_servings = $row["total_servings"]; $sql_vit_k = $row["vit_k"]; $sql_vit_k = $sql_vit_k/$sql_total_servings; $sql_servings = $row["servings"]; if ($sql_servings == 0){ $total_vit_k += $sql_vit_k; }else{ $total_vit_k += $sql_vit_k * $sql_servings; } ?> full code for the sql query getting included in the previous file: Code: [Select] $query_value3 = "SELECT foods.id, users_calendar.id, `name`, `source`,`vit_k`, `cal`,`protein`, `fiber`, `carbs`, `sugar`, `sodium`, `chol`, `total_servings`, `calendar_month`, `calendar_day`, `calendar_year`, `servings` FROM `foods` LEFT JOIN users_calendar ON foods.id=users_calendar.food_id WHERE users_calendar.user_id =". $_SESSION['user_id']." && " . $query_day . "=calendar_day && ".$query_month."=calendar_month && ".$byear."=calendar_year ORDER BY users_calendar.id"; Hi can any one help iv built a cms but when i had a page how easy is it to have a show or hide while making changes to the page many thanks for any help I apologize in advance for any misuse of terminology. I find that I am rather ignorant in such things. I'm working on a WordPress theme. Specifically on the part that shows the "next: link-to-next-post" and "previous: link-to-prev-post" links. Here is the code that I have: Code: [Select] <?php $nextvar=next_post_link('%link'); $prevvar=previous_post_link('%link'); ?> <?php if (isset($nextvar)) { ?> <h3>Next</h3> <p><?php next_post_link('%link'); ?></p> <? } ?> <?php if (isset($prevvar)) { ?> <h3>Previous</h3> <p><?php previous_post_link('%link'); ?></p> <? } ?> The first part intends to check if the links exist. And this works fine. However, the only output I'm getting are the values of $nextvar and $prevvar. The headers are nonexistent. What's wrong? Any help is much appreciated, and I thank you in advance. Hi all I know this contains a bit of JavaScript but it comes from some dynamically created pages using php which are causing it an issue. Here's my scenario. I have a DB with locations, regions, jobtitles and names in it. My users can select from the DB a specific job title or a location. This can produce a report of information from a couple of people, up to over 100 (who can still be filtered by any of the above DB columns) I want to dynamically produce some JS buttons to show / hide any sections which are irrelevant to the user. eg I select by job title, it gives me all the managers, duty managers, staff, cleaners, etc from the DB for all locations. I then want 5 buttons to be on the page, each with a different region on it. (this I can do) I can dynamically label the divs around each of the user information. The issue I have is making the buttons do what I want. So if you press a button labelled "North West" it hides all records which are not from northwest region. Here's what I have so far, I just can't seem to get the functionality right as I know very little about JS. Code: [Select] <script language=javascript type='text/javascript'> function showdiv(pass) { var divs = document.getElementsByTagName('div'); for(i=0;i<divs.length;i++){ if(divs[i].id.match(pass)){//if they are 'see' divs if (document.getElementById) // DOM3 = IE5, NS6 divs[i].style.visibility="visible";// show/hide else if (document.layers) // Netscape 4 document.layers[divs[i]].display = 'visible'; else // IE 4 document.all.divs[i].visibility = 'visible'; } else { if (document.getElementById) divs[i].style.visibility="hidden"; else if (document.layers) // Netscape 4 document.divs[i].visibility = 'hidden'; else // IE 4 document.all.divs[i].visibility = 'hidden'; } } } </script> and then one my php has processed I get a record such as. Code: [Select] <div id='NEREGION'> <table border='1' > <tr><td colspan='4'>Glasgow </td></tr> <tr><td colspan='2' >Employee Name : **********</td><td >Employee Number : *****</td><td colspan='2'>Start Date 25th November 2002</td></tr> <tr><td colspan='3'> </td><td rowspan='3'><img src='image.php?ed=2063&y2007=1&y2008=1&y2009=0&y2010=0&y2011=0&forename=1234&surname=5436' height ='400px' width='350px'></td></tr><tr><td colspan='2'>20th June 2007</td><td> NFR Petrol Delivery - Refresher Course</td></tr><tr><td colspan='2'>2nd December 2008</td><td> Incremental Sales</td></tr></table></div> Any ideas? Hi All, I want to be able to show selected pages of my website as PDF using a 'PDF' button much like this site does: http://www.westmeon.org.uk/index.php?option=com_content&task=blogsection&id=8&Itemid=35 I presume that I will need to install some sort of software on my server (which runs the latest PHP, MySQL etc.) but after hours of searching online I cannot find a simple way of doing this. Does anyone have any suggestions or pointers for how I can do this? FYI my website is written in PHP drawing data from a MySQL database. Regards, Neil I found this function and take no credit for it, I'm trying to get it to show HH:MM:SS when I have the total number of seconds, but nothing is showing on the screen function sec2hms ($sec, $padHours = false) { // start with a blank string $hms = ""; // do the hours first: there are 3600 seconds in an hour, so if we divide // the total number of seconds by 3600 and throw away the remainder, we're // left with the number of hours in those seconds $hours = intval(intval($sec) / 3600); // add hours to $hms (with a leading 0 if asked for) $hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT). ":" : $hours. ":"; // dividing the total seconds by 60 will give us the number of minutes // in total, but we're interested in *minutes past the hour* and to get // this, we have to divide by 60 again and then use the remainder $minutes = intval(($sec / 60) % 60); // add minutes to $hms (with a leading 0 if needed) $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ":"; // seconds past the minute are found by dividing the total number of seconds // by 60 and using the remainder $seconds = intval($sec % 60); // add seconds to $hms (with a leading 0 if needed) $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT); // done! return $hms; } The part of the code to show the data is below: Code: [Select] while ($row = mysql_fetch_array($result)) { $sec = time() - strtotime($row['starttime']); echo $sec; // print to screen to make sure $sec had a value sec2hms($sec); } Any guidance on where I went wrong? How would I show the PHP code on the website page? I'm not sure if this should be under PHP or HTML or what, but, like on the forums where you see the <?php echo 'sdfjksdf'; ?> etc. How do I make it so I can write PHP on the website? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320886.0 I'm working on a simple ad server and would like to display the ads in order (not random). I'm fairly certain I can do something like this: Code: [Select] // Get the last ad id, or becomes 0 if not available $lastid = ($_GET['lastid'] == '') ? '0' : $_GET['lastid']; // Get the next ad in order, or get the first one available mysql_query("SELECT adcode FROM ads WHERE zone='$zoneid' AND id > $lastid ORDER BY id ASC LIMIT 1"); The above code would get the first ad or the next ad in order.. How do I go back to the beginning when I run out of ads to show? Why is it that only certain images come through. I made sure all extensions were there but some jpegs come through others don't some pngs not others. Any thoughts? Code: [Select] <?php $hostname='yobb'; $username='ybbb'; $password='Anbbbb!'; $dbname='b29'; $usertable='bbbb; $myconn=mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); if ((($_FILES["file"]["type"] =="image/gif") || ($_FILES["file"]["type"] =="image/jpeg") || ($_FILES["file"]["type"] =="image/pjpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"]< 200000)) { if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br/>"; } else { if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo "File already exists. Choose another name."; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); } } } else { echo "Invalid file"; } $path="uploads/" . $_FILES["file"]["name"]; $name=$_POST["name"]; $state=$_POST["state"]; if (!myconn) { die ('Could not connect: ' . $mysql_error()); } $db_selected=mysql_select_db('your1729',$myconn); if (!$db_selected) { die ('Can\'t use your1729 : ' . mysql_error()); } mysql_query("INSERT INTO photo(name,photopath,state) VALUES ('$name','$path','$state')") or die(mysql_error()); mysql_close($myconn); ?> i am doing a little project but I get stuck on a problem. How do I show the content of my SQL database in PHP or HTML. I want it to show the title at the top, the text in the middle and maybe a price at the bottom. How do I do that? I can't seem to find a tutorial which covers only that, and I don't have the time to search each tutorial for some usefull information right now. And a second thing I want is that it will show the database in one list on a specific webpage. So people can look trough the list and find the thing they want and than click on it so they awill get directed to that item from the database. |