Php mysql query headers

Function for Retrieving Table Headers in PHP mySQL

By creating appropriate PHP functions and regular expressions, it is possible to eliminate unnecessary code and prepare HTML for specific regex expressions. This approach can help you effectively extract the desired information without relying on amateur HTML work.

PHP mySQL get table headers function

For your situation, either MySQLi or PDO_MySQL will suffice.

while ($row = mysql_fetch_assoc($post))

It is important to note that relying on mysql_* function is not recommended.

A PHP code snippet that retrieves the names of fields from a MySQL database.

0.id 1.todo 2.due date 3.priority 4.type 5.status 6.notes 

This information, which has been sourced from the php.net documentation, may be of assistance to you.

How about mysql_fetch_assoc($post) ?

To obtain an array exclusively for field names.

$post = mysql_fetch_assoc($post); $fields = array(); foreach($post as $title => $value)

You can utilize this within a while loop to iterate through every row and retrieve both the names and values of their fields.

while($p = mysql_fetch_assoc($post)) < $title = $p['title']; $timestamp = $p['timestamp']; //And so on. >

Pierpaolo’s suggestion is valid — it’s advisable to switch to a different MySQL implementation as the current one is set to be removed in PHP 5.5/5.6 or at a later date.

Getting data from the URL in PHP?, If you’re talking about accessing query string parameters from within products.php, you can use the super-global $_GET, which is an associative array of all the query string parameters passed to your script: echo $_GET [‘page’]; // 12

How to extract Heading tags in PHP from a string?

To start with, it is necessary to tidy up the HTML (as shown in the example using $html_str).

$tidy_config = array( "indent" => true, "output-xml" => true, "output-xhtml" => false, "drop-empty-paras" => false, "hide-comments" => true, "numeric-entities" => true, "doctype" => "omit", "char-encoding" => "utf8", "repeated-attributes" => "keep-last" ); $xml_str = tidy_repair_string($html_str, $tidy_config); 

Afterward, it is possible to parse the XML ($xml_str) and convert it to a DOMDocument.

$doc = DOMDocument::loadXML($xml_str); 

Lastly, Horia Dragomir’s technique can be utilized.

$list = $doc->getElementsByTagName("h1"); for ($i = 0; $i < $list->length; $i++) < print($list->item($i)->nodeValue . "
\n"); >

Another option for performing intricate queries on the DOMDocument is to utilize XPath. Further information can be found at http://www.php.net/manual/en/class.domxpath.php.

$xpath = new DOMXPath($doc); $list = $xpath->evaluate("//h1"); 

Even though this post is quite old, I still feel it’s worth mentioning the most effective method I used to obtain heading tags in bulk.

Although this method functions like a regex, it behaves slightly differently in PHP.

Incorporate this into your preg_match statement.

The content of $group[1] will be determined by whatever is found within the heading tag. $group[0] will encompass all content. test

This will consider any spaces and also take into account if anyone includes a «class/id».

the class/id (group) is ignored.

As a practice, I make sure to remove any white space, line breaks, and tabs when examining HTML tags. By replacing them with a single space, it helps to reduce dotalls and minimize large amounts of white space. This is important to maintain proper formatting when using regex in certain cases.

  • Naturally, I am only selecting between 1 to 2 heading tags. To capture all, modify it to range from 0 to 9.
  • If there are any other modifications or corrections to my code that anyone would like to contribute, please reply. I am eager to receive feedback.
  • While there is a common argument that Regex is ineffective with HTML, this is not necessarily true. If you carefully design your PHP functions and regex expressions to remove unnecessary clutter and prepare the HTML for regex-specific expressions, you can successfully extract the desired content. By developing a sufficient number of regex functions, even poorly designed HTML can be effectively replaced.

You can access the test page for regular expressions using this link.

In case you are interested in utilizing regular expressions, my belief is that:

Provided that your header tags are not nested, this method ought to function. As previously mentioned by others, utilizing regular expressions may not be the most effective approach if you do not have authority over the HTML.

Http — How can I get PHP to display the headers it, Look at the $_SERVER variable to see what it contains. The linked manual page has a lot of useful information, but also simply do a var_dump on it to see what’s actually in it. Many of the entries will or won’t be filled in, depending on what the client decides to do, and odd quirks of PHP.

PHP — retrieve token from header

If you are unaware of how to obtain headers, you can refer to http://php.net/manual/en/function.getallheaders.php for guidance.

To obtain the token, the following code can be used as a sample.

Csv — How to get the header value on getcsv in PHP, I want to get the value of column header in getcsv but I can’t. Example inputs: Name , Address , Age John , California, 26 Michael, L.A , 29. If I am in row2 column2, I want to get the name of header which is Address. But my code returns as L.A. This is my code:

Php : Show the headers received from the browser

The function that you should use is get_headers(), as previously mentioned.

This function, called «get_headers», retrieves all the server response headers for an HTTP request.

$url = 'http://www.example.com'; print_r(get_headers($url)); 

Displays every piece of data transmitted by the server.

[0] => HTTP/1.1 200 OK [1] => Date: Sat, 29 May 2004 12:28:13 GMT [2] => Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) [3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT [4] => ETag: "3f80f-1b6-3e1cb03b" [5] => Accept-Ranges: bytes [6] => Content-Length: 438 [7] => Connection: close [8] => Content-Type: text/html ) 
Update

Information sent by browsers can be accessed through the super global variable $_SERVER . This variable provides all relevant browser-related information, as demonstrated in the following code snippet.

echo $_SERVER['HTTP_USER_AGENT']; 
  • This code, REQUEST_METHOD , provides the HTTP request method, which can be GET, HEAD, PUT, or POST.
  • The MSDTHOT identified as HTTP_HOST provides details about the host.
  • The Cookie header’s raw information can be obtained from HTTP_COOKIE as per the [Source].

The link I prefer directs to the documentation for the «apache-request-headers» function on the PHP website.

Retrieves the headers of the ongoing HTTP request.

Obtain these through the use of either $_GET[‘requestName’] , $_POST[‘requestName’] , or $_REQUEST[‘requestName’] which allows for a GET or POST request.

Discover $_COOKIE[‘varName’] to enjoy cookies or consider checking out $_SESSION[] for other options.

PHP | get_headers() Function, How to Upload Image into Database and Display it using PHP ? PHP | get_headers() Function. View Discussion. Improve Article. Save Article. Last Updated : 20 May, 2019; The get_headers() function in PHP is used to fetch all the headers sent by the server in the response of an HTTP request.

Источник

PHP/mySQL, get column headers?

IS it possible in PHP to grab the headers following a mySQL query?

SELECT [headings] from tablename.

I’m looking for a generic PHP function that will include the headings,
so that I can display a meaningful table.

IS it possible in PHP to grab the headers following a mySQL query?

SELECT [headings] from tablename.

I’m looking for a generic PHP function that will include the headings,
so that I can display a meaningful table.

If you use mysql_fetch_assoc() or mysql_fetch_array() with MYSQL_ASSOC
as the 2nd parameter then you’ll get an array indexed with the column
names.

$res = mysql_query(‘select a, b, c from foo’);
$row = mysql_fetch_assoc($res);
print ‘

‘;
foreach($row as $name => $value) print «

«;
>
print ‘

‘;
while($row) print ‘

‘;
foreach($row as $value) print «

«;
>
print ‘

‘;
$row = mysql_fetch_assoc($res);
>
print ‘

$name
$value

‘;

You can also use the mysql_fetch_field() and mysql_field_name()
functions.

IS it possible in PHP to grab the headers following a mySQL query?

SELECT [headings] from tablename.

I’m looking for a generic PHP function that will include the headings,
so that I can display a meaningful table.


Sorry, is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.

IS it possible in PHP to grab the headers following a mySQL query?

SELECT [headings] from tablename.

I’m looking for a generic PHP function that will include the headings,
so that I can display a meaningful table.

IS it possible in PHP to grab the headers following a mySQL query?

If you use mysql_fetch_assoc() or mysql_fetch_array() with MYSQL_ASSOC
as the 2nd parameter then you’ll get an array indexed with the column
names.

$res = mysql_query(‘select a, b, c from foo’);
$row = mysql_fetch_assoc($res);
print ‘

‘;
foreach($row as $name => $value) print «

«;
>
print ‘

‘;
while($row) print ‘

‘;
foreach($row as $value) print «

«;
>
print ‘

‘;
$row = mysql_fetch_assoc($res);
>
print ‘

$name
$value

‘;

You can also use the mysql_fetch_field() and mysql_field_name()
functions.

Thanks, Chris (and others), that did the trick.
Mick

Источник

Читайте также:  TAG index
Оцените статью