PHP - Show Only 4 Values After . (dividing)
Code: [Select]
(substr($killdeaths=$Kills/$Deaths,0,4));im sure im doing it wrong Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
Hi, I'm trying to make a page that records the training I do. I've got a column for time (total time for the whole training session), and one for laps (how many laps completed). I've got another for average lap time, which I've calculated as Code: [Select] $avg_lap_time = $time / $laps; Everything is displaying fine except the average lap time, which is just displaying as 0. Any idea how to fix this? More of the code is below. Code: [Select] <table class="tenk"> <tr><th>*</th><th>Date</th><th>Course</th><th>Course Distance</th><th>Laps</th><th>Time </th><th>Average lap time </th></tr> <?php $result = @mysql_query($select . $from . $where); if (!$result) { echo '</table>'; exit('<p>Error retrieving info from database!<br />'. 'Error: ' . mysql_error() . '</p>'); } $row_counter = 1; //create row counter with default value 0 while ($results = mysql_fetch_array($result)) { echo "<tr valign='top'>\n"; $training_date = $results['training_date']; $course_name = $results['course_name']; $course_distance = $results['course_distance']; $laps = $results['laps']; $time = $results['time']; $avg_lap_time = $time / $laps; echo "<td>"; echo $row_counter++; echo "</td>\n"; echo "<td>$training_date</td>\n"; echo "<td>$course_name</td>\n"; echo "<td>$course_distance</td>\n"; echo "<td>$laps</td>\n"; echo "<td>$time</td>\n"; echo "<td> $avg_lap_time </td>\n"; echo "</tr>\n"; } ?> </table> In a script links are captured from the internet by $link, then display it by echo $link The links have the general format of http://domain.com/something/filename.html I am looking for a simple way to display capture some elements from $link and display "domain.com" and "filename" In other words, I need a code to remove other parts of the link provided by $link I have about 300 users, and I'm trying to group them geographically according what part of the state their county is in OR if they're reading my site because they have a favorite college team. I've created a page that I want to show the total count for each group. There will be 13 groups, and I'd rather not have 13 queries. Basically, I think, I can't make heads or tails of nested loops. I'd like it to look like this: Region 1 (## members) Region 2 (## members) Region 3 (## members) etc. ... ... ... ... ... I assume there will be IF and ElseIF statements. Here is what I'm starting with, but I can't even get the first group working: Code: [Select] $query = 'SELECT * FROM wp_usermeta WHERE meta_key = "wp_1_s2member_custom_fields"'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { $meta_value = unserialize($line['meta_value']); echo '<div>Region 1 (' . $d1 . ' Users)</div>'; if ($meta_value['county'] == '1' || $meta_value['county'] == '2') { ++$d1; } }; 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 }
Dear All Members here is my table data.. (4 Columns/1row in mysql table)
id order_no order_date miles How to split(miles) single column into (state, miles) two columns and output like following 5 columns /4rows in mysql using php code.
(5 Columns in mysql table) id order_no order_date state miles 310 001 02-15-2020 MI 108.53 310 001 02-15-2020 Oh 194.57 310 001 02-15-2020 PA 182.22
310 001 02-15-2020 WA 238.57 ------------------my php code -----------
<?php
if(isset($_POST["add"]))
$miles = explode("\r\n", $_POST["miles"]);
$query = $dbh->prepare($sql);
$lastInsertId = $dbh->lastInsertId(); if($query->execute()) {
$sql = "update tis_invoice set flag='1' where order_no=:order_no"; $query->execute();
} ----------------- my form code ------------------
<?php -- Can any one help how to correct my code..present nothing inserted on table
Thank You Edited February 8, 2020 by karthicbabuHi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
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 all, Just curious why this works: Code: [Select] while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){ $import="INSERT into $prodtblname ($csvheaders1) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]')"; } And this does not: $headdata_1 = "'$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]'"; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){ $import="INSERT into $prodtblname ($csvheaders1) values($headdata_1)"; }it puts $data[#'s] in the database fields instead of the actual data that '$data[0]','$data[1]'... relates to. I wrote a script to create the values in $headdata_1 based on the number of headers in $csvheaders1 but can't seem to get it working in the sql statement. Thanks Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) 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 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 all I have a pice of code that I want to only show the image if it's empty: Code: [Select] <?php if(!empty($node->field_img['und'][0]['filename'])); { ?> <li><img src="http://mysite.co.uk/sites/default/files/brand-images/<?php print $node->field_img['und'][0]['filename']; ?>" style="max-width:270px; text-align:center;" /></li> <?php } ?> However, it shows an image placeholder (Red cross) even when it's empty? Many thanks for your help Pete 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? i have this code but it shows the password of the user to... Code: [Select] <?php $database="dynamicg_sites"; mysql_connect ("localhost","dynamicg_sites","boom123"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT * FROM sites order by votes DESC" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<br>\n"; print "There are $num_rows News Articles"; print "<br>\n"; print "<table width=457 border=0>\n"; print "<tr>\n"; print "<td>\n"; echo "Title:"; print "</td>\n"; print "<td>\n"; echo "Description:"; print "</td>\n"; print "<td>\n"; echo "Votes:"; print "</td>\n"; print "</tr>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=2/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; print "<br />\n"; print "<br />\n"; ?>i was wondering how do i make this only show certain columns... thanks in advance... 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? The school district that I work for has been using a slide show PHP script that I designed, which uses random images from a database. I have now been asked to build in an option where they can enter text into the database and the script takes the text and either creates an image that is 1000pixels wide and 700 pixels tall with the text filled in the image or it just have the text re-sized to fit a text box with the same dimensions as above, so the students can see the text displayed from down the hall on the monitors. I would also like the script to have the ability to explode the text so the words can stay large in case of the user entering a long winded entry. Thank you in advance for any help. 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. 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 |