PHP - Csv Column Heading Php
I am generating a csv dynamically and getting it downloaded from php but after download the csv only contain the data from database not the heading or the column name of the database. Similar TutorialsFor a long time, I think I have been using heading tags wrong on websites.
They always show like this on Google.
Websitename websitename.com/category?name=mystery Posted by Night Flyer; 7 days ago; 5 views. « first; « prev; 1 of 1; next »; last ». Contact Us; @ 2014 websitename Inc. All Rights Reserved.As you can see, Google takes all the heading tags on my page and puts them in the description of the search result. So I have finally come to the conclusion that I should not be using heading tags for those things. Am I correct on that? My Php Buddies, I have mysql tbl columns these:
id: Now, I want to display their row data by excluded a few columns. Want to exclude these columns: date_&_time account_activation_code account_activation_status id_verification_video_file_url password
So, the User's (eg. your's) homepage inside his account should display labels like these where labels match the column names but the underscores are removed and each words' first chars CAPITALISED:
Id: 1
For your convenience only PART 1 works. Need help on Part 2 My attempted code:
PART 1 <?php // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Query to get columns from table $query = $conn->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'members' AND TABLE_NAME = 'users'"); while($row = $query->fetch_assoc()){ $result[] = $row; } // Array of all column names $columnArr = array_column($result, 'COLUMN_NAME'); foreach ($columnArr as $value) { echo "<b>$value</b>: ";?><br><?php } ?> PART 2 <?php //Display User Account Details echo "<h3>User: <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br> <?php $excluded_columns = array("date_&_time","account_activation_code","account_activation_status","id_verification_video_file_url","password"); foreach ($excluded_columns as $value2) { echo "Excluded Column: <b>$value2</b><br>"; } foreach ($columnArr as $value) { if($value != "$value2") { $label = str_replace("_"," ","$value"); $label = ucwords("$label"); //echo "<b>$label</b>: "; echo "$_SESSION[$value]";?><br><?php echo "<b>$label</b>: "; echo "${$value}";?><br><?php } } ?> PROBLEM: Columns from the excluded list still get displayed. Edited November 19, 2018 by phpsaneHellow, i need help please, writing code and it doesn't work. please help...
Here it is
WHERE start_date BETWEEN 'start_date".strtotime('-3 day')."' AND 'start_date'";without this code everithing works fine Thank you Hi, I'm trying to get the last number from a column of numbers, add 1 to it and use this to insert a new value in the column. The column is not the primary key, indexed, or auto insert, it's just a plain old int field. $newid = mysql_query('SELECT IDCOL FROM prods ORDER BY IDCOL DESC LIMIT 1'); // the above just doesn't work--it returns 0, there are over 1200 products--I'm going nuts over this. //$newid += 1; I've commented this out, it works though (in that it adds 1 to 0) $sql = mysql_query("INSERT INTO prods (IDCOL , Prod_Code, blah... blah..) VALUES('$newid','$prod_code','blah... blah...')") or die (mysql_error()); //this works (but inserts 0 as the newID) You'd think this would be so easy. Thanks Steve I fairly new to PHP. This seems very obvious but I cannot find an answer. O programmer friend of mine said that I should never store a calculated value in a table because it was redundant. SO I have a very simple shopping cart. In the confirmation email, I ask the database for the line items of the order. So I'm pulling the quantity and price from the database. In the email I created a var called $ext which is $price * $disc which works. I cannot figure out how to total $ext. I created a var called $subtotal. Heres the code. $result = mysql_query("SELECT * FROM order_detail, products WHERE $ordid = orderid AND order_detail.productid = products.serial"); while($row = mysql_fetch_array($result)) { $prodid = $row['productid']; $qty = $row['quantity']; $price = $row['price']; $prodname = $row['name']; $proddesc = $row['description']; $ext = $qty * $price; $subtotal = 0; $subtotal = ($subtotal + $ext); } Any help would be appreciated. hi guys, i made this code list US states in six columns....the problem is that it lists it across rather than down it lists it like thi Alabama Alaska Arizona blah1 blah2 blah3 blah4 blah5 blah6 when I want it to list like this Alabama blah2 Alaska blah3 Arizona blah 4 blah1 blah5 but not just two columns....I want 4 columns here is my code $query = mysql_query("SELECT * FROM states ORDER BY name ASC"); echo '<center><table width="250" border="0" cellpadding="5" cellspacing="0"> <tr>'; while($show = mysql_fetch_array($query)) { $column = 1+$column; if($column == 6) { $column = '1'; $break = '</td></tr>'; } else { $break = ''; } echo '<td> <table > <tr class="style5"> <td width="50%" align="left" height="23" nowrap>'.$show['name'].'</td> <td height="23" valign="middle" > </td> </tr> </table> '.$break.''; } echo '</table></center>'; I want to echo the contents of column 4 for my username only, and it doesn't show anything. I can do if ($memberQuery->fetchColumn(4) < 2)() though. Code: [Select] $host = 'localhost'; $database = ''; $db_username = ''; $db_password = ''; if (($db = new PDO("mysql:host=$host;dbname=$database", $db_username, $db_password)) == NULL) { echo $db->getMessage(); } $memberQuery = $db->prepare("SELECT * FROM members WHERE username=:username"); $memberQuery->execute(array(':username' => $_SESSION['username'])); $result = $memberQuery->fetchColumn(4); echo "$result"; How can i get the last row data from a certain column? Hey, I've got a query in which a variable is interpreted as a column and I don't why this is caused. $upgrade_time_sql = "SELECT * FROM todo_upgrades WHERE profile_id = ".$profile_id." AND level = ".$profile_data['level2_'.$show.'']." AND type = ".$show.""; $upgrade_time_res = mysql_query($upgrade_time_sql) or die (mysql_error()); $show is filled with the content "storage" The mysql_error is "Unknown column 'storage' in 'where clause'" Thanks for helping. Php Buddies, Line 67: $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE $_SESSION['search_column'] = ?"; I get error for the above:
How to fix this ?
Context: <?php //include('error_reporting.php'); ini_set('error_reporting','E_ALL');//Same as: error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); require('conn.php'); ?> <form name = "search" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="keywords">Keywords:*</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required> <br> <label for="search_column">Search in ... ?</label> <select name="search_column" id="search_column"> <option value="page_url">Page Url</option> <option value="link_anchor_text">Link Anchor Text</option> <option value="page_description">Page Description</option> <option value="keyphrase">Keyphrase</option> <option value="keywords">Keywords</option> </select> <br> <label for="tos_agreement">Agree to TOS or not ? *</label> <select name="tos_agreement" id="tos_agreement" required> <option value="Yes">Yes</option> <option value="No">No</option> </select> <br> <input type="button" name="search_links" id="search_links" value="Search Links!"> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(ISSET($_POST['search_links'])) { if(ISSET($_POST['page_url'])) { $_SESSION['search_column'] = $_POST['page_url']; } elseif(ISSET($_POST['link_anchor_text'])) { $_SESSION['search_column'] = $_POST['link_anchor_text']; } elseif(ISSET($_POST['page_description'])) { $_SESSION['search_column'] = $_POST['page_description']; } elseif(ISSET($_POST['keyphrase'])) { $_SESSION['search_column'] = $_POST['keyphrase']; } elseif(ISSET($_POST['keywords'])) { $_SESSION['search_column'] = $_POST['keywords']; } //Re-write the following 4 lines ... mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $conn->set_charset('utf8mb4'); //Always set Charset. $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE $_SESSION['search_column'] = ?"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'s',$_SESSION['search_column']); $result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords); mysqli_stmt_execute($stmt); mysqli_stmt_fetch($stmt); while(mysqli_stmt_fetch($stmt)) { echo "url"; echo "<br>"; echo "anchor_text"; echo "<br>"; echo "description"; echo "<br>"; echo "keyphrases"; echo "<br>"; echo "keywords"; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { echo "1. QUERY failed!"; } if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrases'],$_POST['keywords']); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); while($row = mysqli_fetch_array($result,mysqli_assoc)) { $page_url = $row['page_url']; echo $page_url; echo "<br>"; $link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "<br>"; $page_description = $row['page_description']; echo $page_description; echo "<br>"; $keyphrases = $row['keyphrases']; echo $keyphrases; echo "<br>"; $keywords = $row['keywords']; echo $keywords; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("2. QUERY failed!"); } } } ?>Edited July 16, 2020 by 2020 I have become able to display due data in due column but the same value is showing for each customer - what is the wrong I am doing? Here is the code, please somebody help! while ($row_custact = mysqli_fetch_assoc($query_custact)){ $currentuser = $row_custact['cust_id']; $sql_inccur ="SELECT i.inc_date, t.inctype_type, i.inc_amount, i.inc_text, c.cust_no, c.cust_name, i.inc_receipt From customer AS c LEFT JOIN incomes AS i ON c.cust_id = i.cust_id LEFT JOIN inctype AS t ON i.inctype_id = t.inctype_id WHERE c.cust_id = '$currentuser' ORDER BY inc_date DESC"; $query_inccur = mysqli_query($db_link, $sql_inccur); checkSQL($db_link, $query_inccur); while ($row_inccur = mysqli_fetch_assoc($query_inccur)){ $inc_amount = $row_inccur['inc_amount']; $inc_text = $row_inccur['inc_text']; //Iterate over income types and add matching incomes to $total $total_row = $total_row + $row_inccur['inc_amount']; $total_paid = $total_paid + $total_row; // part for total due finding.. and "inc_text" is due column $total_row_due = $total_row_due + $row_inccur['inc_text']; $total_due = $total_due + $total_row_due; // this part gathers only total due paied for an account if($row_inccur['inctype_type']=='Duepay') { $total_duepay = $total_duepay + $row_inccur['inc_amount']; } $remaining_due = $total_row_due - $total_duepay; //echo $remaining_due; } //echo $currentuser; echo '<tr> <td> <a href="customer.php?cust='.$row_custact['cust_id'].'">'.$row_custact['cust_no'].'</a> </td> <td>'.$row_custact['cust_name'].'</td> <td>'.$row_custact['custsex_name'].'</td> <td> '.$remaining_due. ' // showing due left, here is the problem </td> <td>'.$row_custact['cust_address'].'</td> <td>'.$row_custact['cust_phone'].'</td> <td>'.date("d.m.Y",$row_custact['cust_since']).'</td> </tr>'; }
I have a table and one column has links that point to index.php?id= but I want it to display the info of that row of my database. On the index.php page i have this code Code: [Select] <?php include "dbaptsConfig.php"; // test id, you need to replace this with whatever id you want the result from $id = "1"; // what you want to ask the db $query = "SELECT * FROM `apartments` WHERE `id` = ".$id; // actually asking the db $res = mysql_query($query, $ms); // recieving the answer from the db (you can only use this line if there is always only one result, otherwise will give error) $result = mysql_fetch_assoc($res); // if you uncomment the next line it prints out the whole result as an array (prints out the image as weird characters) // print_r($result); // print out specific information (not the whole array) echo "id: ".$result['id']."<br />"; echo "username: ".$result['username']."<br />"; echo "type: ".$result['type']."<br />"; echo "title: ".$result['title']."<br />"; echo "description: ".$result['description']."<br />"; echo "county: ".$result['county']."<br />"; echo "town: ".$result['town']."<br />"; echo "phone: ".$result['phone']."<br />"; echo "rooms: ".$result['rooms']."<br />"; echo "bath: ".$result['bath']."<br />"; echo "squa ".$result['square']."<br />"; echo "rent: ".$result['rent']."<br />"; echo "time: ".$result['time']."<br />"; ?>I know there is something wrong with this cause I always get the same info no matter which apartment I click. Do I use the $_GET function and how do I implement this?
Hello,
I have a table like this: CREATE TABLE days ( id INT AUTO_INCREMENT, daya INT, dayb INT, PRIMARY KEY (id) ); INSERT INTO days VALUES (70, 19, 18), (69, 20, 17), (68, 24, 25), (67, 19, 18), (66, 19, 17), (65, 17, 16);
$sql = "SELECT d1.id AS id1, d2.id AS id2, IF((d1.daya-d2.daya)=1,1,0) + IF((d1.daya-d2.dayb)=1,1,0) + IF((d1.dayb-d2.daya)=1,1,0) + IF((d1.dayb-d2.dayb)=1,1,0) AS tcount FROM days AS d1 , days AS d2 WHERE d1.id IS NOT NULL AND d2.id IS NOT NULL AND d1.id > d2.id"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["id1"] . "</td><td>". $row["id2"] . "</td><td>" . $row["tcount"]. "</td></tr>"; } echo "</table>";
Id1 Id2 Count 50 49 1 50 48 0 49 48 0 50 47 1 49 47 1 48 47 0 50 46 1 49 46 1 48 46 0 47 46 1 50 45 1 49 45 1 48 45 0 47 45 1 46 45 1 I need to convert the table into this form: id1 goes down the first column, and id2 is in the first row. How can i do this, please? can you give me some help? thank you! id2 49 48 47 46 45 id1 50 1 0 1 1 1 49 0 1 1 1 48 0 0 0 47 1 1 46 1 45
I have an SQL query: SELECT username, dl_sumtotal FROM `vb_user` ORDER BY dl_sumtotal DESC LIMIT 0 , 30 Right now, its results display like this: username3: 500 username1: 400 username2: 300 How can I give these results a numbered column so it displays like this: 1: username3: 500 2: username1: 400 3: username2: 300 I would like to output that number in my PHP script. thanks for any help. Php Buddies, Just how do you insert an uploaded img via html for ($_POST) to mysql tbl and what type of column should it be ? Also, how to link the img from the mysql column to a webpage ? Following html links the img from a folder/directory to a webpage: <a href="../html-link.htm"><img src="flower.jpg" style="width:82px; height:86px" title="White flower" alt="Flower"></a> I have a table with "votes" column. I basically want to retrieve the sum of all the votes columns associated with a user. This is the full code. It gives me "NULL" output. $count_votes = $db->prepare("SELECT SUM(votes) as total FROM entries WHERE user_id = :user_id"); $count_votes->bindParam(':user_id', $user_id); $count_votes->execute(); $t_votes = $count_votes->fetchColumn(); $get_votes = $t_votes['total']; echo $get_votes;
But if I remove the user_id bind paramter, it gives me the results. But I need that parameter to show which user has how many votes. $count_votes = $db->prepare("SELECT SUM(votes) as total FROM entries"); $count_votes->execute(); $t_votes = $count_votes->fetchColumn(); $get_votes = $t_votes['total']; echo $get_votes;
What am I doing wrong? Here is where I'm starting: Code: [Select] SELECT * FROM wp_usermeta WHERE meta_key = 'wp_1_s2member_custom_fields' AND meta_value LIKE '%3%' As the PHP produces the page, I'm going to have 15 different options coming from the Code: [Select] meta_value LIKE part. I'm assuming I can set up my 15 different DIVs, each with their own IF statement involving the meta_value. Right? I'm not going to have to have 15 different queries, am I? I assume it would start like this: 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)) But from there, I don't know if it's possible to deal with partial data with IF statements. |