Display data from mysql that has specified string

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts: 282
Location: Holland Rotterdam

Display data from mysql that has specified string

I have a simple script to show the visited url
but from my sql table I would like to display only the 'tag=variables', not id= or other query_strings.

Is their some possibility to get only the tag= variables?

Code: Select all

<?php
// connect to the "tests" database
$conn = new mysqli('127.0.0.1', 'tracker', '123456', 'tracker');

// check connection
if (mysqli_connect_errno()) {
  exit('Connect failed: '. mysqli_connect_error());
}

$today = date('Y-n-j');

// SELECT sql query
$sql = "SELECT * FROM `visitor_tracker` WHERE date='$today' and not query_string='' ORDER BY `visitor_tracker`.`id` DESC limit 15"; 

// perform the query and store the result
$result = $conn->query($sql);

// if the $result contains at least one row
if ($result->num_rows > 0) {
  // output data of each row from $result
  while($row = $result->fetch_assoc()) {
    echo '<tr><td> <a href="http://145.53.93.209/'. $row['web_page']. '?'. $row['query_string']. '" title="" class="postlink" target="_top">'. $row['query_string']. '</a> </td><br> ' ;
  }
}
else {
  echo '0 results';
}

$conn->close();
?>
Here under are some examples from the query_string
but i would like not to have id= or others like name= but only the tag=

Code: Select all

tag=nature 
id=628 
tag=politiek 
name=Guest&album=Beatrix-Blik-Collectie 
name=Guest&album=Beatrix-Blik-Collectie 
id=628 
id=628 
tag=AEX 

Admin Posts: 805
Try this sql query:

Code: Select all

$sql ="SELECT * FROM visitor_tracker WHERE date='$today' AND query_string LIKE '%tag=%' ORDER BY visitor_tracker.id DESC limit 15";
Or, your code, but with this while() statement:

Code: Select all

while($row = $result->fetch_assoc()) {
  if(stripos($row['query_string'], 'tag=') !== false) echo '<tr><td> <a href="http://145.53.93.209/'. $row['web_page']. '?'. $row['query_string']. '" title="" class="postlink" target="_top">'. $row['query_string']. '</a> </td><br>';
}

JanMolendijk Posts: 282
Thank you so mutch `thanks thanks thanks` working in once

Similar Topics