Im trying to display all the movies with specific hashtag.
The results are not showing but there are no errors.
However i should get movie poster image and title as result. :/
In my database, this is 'tags' row of one movie
#watchonline #movies-with-subs #hdmovies
and tag.php
<?php
require "db.inc.php";
if (isset($_GET['tag'])) {
$tag = preg_replace('#[^a-z0-9_-]#i', '', $_GET["tag"]);
$fulltag = "#" . $tag;
echo $fulltag;
$ASDsql = "SELECT * FROM movie WHERE tags LIKE '$fulltag' OR tags =
'$fulltag'";
$tagQuery = mysqli_query($db, $ASDsql);
$count = mysqli_num_rows($tagQuery);
if($count > 0) {
while ($hastags = mysqli_fetch_array($tagQuery)) {
$id = $hastags['id'];
$movie_title = $hastags['movie_title'];
$movie_url = $hastags['movie_url'];
$movie_image = $hastags['movie_image'];
$movie_identity = $hastags['movie_identity'];
echo "<div class='item'><a href='movie.php?movie=$id'><img
src='$movie_image'><p>$movie_title</p></a></div>";
}
}else {
echo "No movies under that tag";
}
}
?>
I've checked db.inc.php file it's all good.
My output is "No movies under that tag";
Im sorry if this is a copy i really looked and could not find an answer
try this :
$ASDsql = "SELECT * FROM movie WHERE tags LIKE '%$fulltag%' OR tags =
'%$fulltag%'";
or may be the table is not having any value
Related
I have added my code below, i am new to php and mysql and trying to search mysql using php based on user inputs and working really fine. But not sure how to highlight the user input value while displaying from mysql.
$output = NULL;
if(isset($_POST['submit'])){
$mysqli = new mysqli("localhost","root","","test");
$search = $mysqli->real_escape_string($_POST['search']);
$resultSet = $mysqli->query("SELECT * FROM books WHERE BookContent LIKE '%$search%'");
if($resultSet->num_rows>0){
while($rows = $resultSet->fetch_assoc()){
$BookContent = $rows['BookContent'];
//$output = preg_replace("/($search)/i",'<span class="highlight">$1</span>', $output);
echo $output = "" ."Your search results--> $BookContent"."<br>";
}
}else{
echo $output = "No result" ;
}
}
?>
just add this in your page.
CSS:
.highlight{background-color:yellow}
jQuery:
$("body").highlight("<?php echo $search; ?>");
I am trying to fill the article title automatically into an event creation form inside a EasySocial stream module. Therefor I need to insert the current article title as title variable inside the .php file that creates the event.
If I just try
$title = TITLE;
it works and the event gets the title "TITLE". But if I try to catch the current article title first and output the article title as title variable, it does not work. Obviously I am doing something wrong but I can not discover how to get it working. I got this so far:
$articleTitle = '';
$input = JFactory::getApplication()->input;
if ( ($id = (int) $input->get('id')) )
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('title')->from('#__content')->where('id = ' . $id);
$db->setQuery($query);
$articleTitle = $db->loadResult();
}
echo $articleTitle;
This is working and I can see the article title on my site. But when I try to set it as $title to be set, it is not working any longer:
$title = $articleTitle;
Any advice what I am doing wrong at the final step?
Your articleTitle is not string but db result
if (!$result) {
echo 'No title ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo $row[0]; // title
$doc = JFactory::getDocument();
$title = $doc->getTitle();
$title equals title of the page
Don't forget echo before $title
I am going out of my mind as it is. I am trying to pass a variable from a page that shows all albums thumbnail image and name to a page that will display all the pictures in that gallery using that passed variable, but the variable is empty in the url on the target page. I have seen similar cases on the web and on this site and I've applied the suggestions but it's still the same. Here is the code that lists the thumbnail and passes the variable(id).
<?php
include ("config.php");
$conn = mysqli_connect(DB_DSN,DB_USERNAME,DB_PASSWORD,dbname);
$albums = mysqli_query($conn,"SELECT * FROM albums");
if (mysqli_num_rows($albums) == 0) {
echo "You have no album to display. Please upload an album using the form above to get started. ";
}
else{
echo "Albums created so far:<br><br>";
echo "<table rows = '4'><tr>";
while ($thumb = mysqli_fetch_array($albums)) {
echo '<td><a href ="view.php?id="'.$thumb['id'].'"/><img src = "'.$thumb['thumbnail'].'"/><br>'.$thumb['album_name'].'<br>'.$thumb['id'].'</a></td>';
}
echo "</tr></table>";
}
?>
The code for getting the passed variable is as follows:
<?php
include("config.php");
$conn = mysqli_connect(DB_DSN,DB_USERNAME,DB_PASSWORD);
$db = mysqli_select_db($conn,dbname);
if (isset($_GET['id'])) {
$album_id = $_GET['id'];
$pic = "SELECT * FROM photos WHERE album_id ='$album_id'";
$picQuery = mysqli_query($conn,$pic);
if (!$picQuery) {
exit();
}
if (mysqli_num_rows($picQuery) == 0) {
echo "Sorry, no Pictures to display for this album";
}
else{
echo "Pictures in the gallery:<br><br>";
while ($result = mysqli_fetch_assoc($picQuery)) {
echo "<img src='".$result['photo_path']."'/>";
}
}
}
?>
Please help as i have spent the last two days trying to get it right.
First, your's code is weak against sql injections:
$album_id = $_GET['id']; // here
$pic = "SELECT * FROM photos WHERE album_id ='$album_id'";
Use either $album_id = intval($_GET['id']) or prepared statements functionality.
Second, add debug lines to your code, like:
<?php
include("config.php");
if (isset($_GET['id'])) {
$album_id = intval($_GET['id']);
var_dump($album_id); // should print actual passed id
$conn = mysqli_connect(DB_DSN,DB_USERNAME,DB_PASSWORD);
var_dump($conn _id); // should print conn resource value
$db = mysqli_select_db($conn, dbname);
var_dump($db); // should print 'true' if db select is ok
$pic = "SELECT * FROM photos WHERE album_id ='$album_id'";
$picQuery = mysqli_query($conn, $pic);
var_dump($picQuery); // should print query resource value
if (!$picQuery) {
exit();
}
if (mysqli_num_rows($picQuery) == 0) {
echo "Sorry, no Pictures to display for this album";
} else {
echo "Pictures in the gallery:<br><br>";
while (($result = mysqli_fetch_assoc($picQuery)) !== false) {
var_dump($result ); // should print fetched assoc array
echo "<img src='".$result['photo_path']."'/>";
}
}
}
Notice $album_id = intval($_GET['id']) and while (($result = mysqli_fetch_assoc($picQuery)) !== false) parts
Then follow link view.php?id=<existing-album-id> and observe debug result. On which step debug output differs from expected - there problem is.
im having a simple mysql/php problem. so i am adding in Image titles for my website, and the code is displayed below. It works, but when you dont put a image, it shows up as blank. I need it to show up as 'No image title' (bc i will use this for image description to). It basically gets the image name, then takes the title from that row.
So how do i do it? :/ im still very new to PHP.
<?php
if (isset($imgtitleset))
{
$sql = "SELECT image_title FROM images WHERE image_name = '$image_main'";
$result = mysql_query ($sql);
while ($row = mysql_fetch_array($result))
{
$imgtitle= $row["image_title"];
echo "$imgtitle";
}
}
else {
echo 'no image title';
}
?>
Change the while loop like so:
while ($row = mysql_fetch_array($result)) {
$imgtitle= $row["image_title"];
if($imgtitle != '') {
echo $imgtitle;
} else {
echo 'no image title';
}
}
Also, I'm not sure what the $imgtitleset variable is for, but you can probably get rid of the if statement checking to see whether it's set.
Edit: the whole thing should probably look like this:
<?php
$sql = "SELECT image_title FROM images WHERE image_name = '$image_main'";
$result = mysql_query ($sql);
while ($row = mysql_fetch_array($result)) {
$imgtitle= $row["image_title"];
if($imgtitle != '') {
echo $imgtitle;
} else {
echo 'no image title';
}
}
?>
This all depends on what $imgtitleset is equal to. It is clearly set against something:
while ($row = mysql_fetch_array($result)) {
$imgtitle = $row["image_title"];
if (isset($imgtitle))
echo "$imgtitle";
else
echo 'no image title';
}
This would mean if nothing was found in the database then it will echo the no image title. However like I said, this could depend on what $imgtitleset is, maybe post the code for that?
If you only expect the select to return a single row, then use if rather than while and return the error on else:
<?php
if (isset($imgtitleset))
{
$sql = "SELECT image_title FROM images WHERE image_name = '$image_main'";
$result = mysql_query ($sql);
if ($row = mysql_fetch_array($result))
{
$imgtitle= $row["image_title"];
echo "$imgtitle";
}
else {
echo 'no image title';
}
}
?>
I need a little help of my brilliant friends.
Actually i m new to development so that i have no much idea how can i show my page in words like www.testsite.com/index.php?pname=**Home** except of www.testsite.com/index.php?pid=**1**
i have the following code for showing page in number
if (!$_GET['pid']) {
$pid = '1';
} else {
$pid = ereg_replace("[^0-9]", "", $_GET['pid']); }
and the sql code
$sqlCommand = "SELECT id, link FROM main_page WHERE showing='1' ORDER BY id ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$menu='';
while ($row = mysqli_fetch_array($query)) {
$pid = $row["id"];
$link = $row["link"];
if ($linklabel){
$menu .=''. $link .'';
}}
i want to show and href name of page not id how can i do that.
help plz
Your example will fail if I enter *1*2*3*
you should be searching for the contents of
**(contents)**
and nothing else.
That will get you the name and the number.
Here is my example
$string = "**123naasdme456**";
preg_match("/[^\*+](?P<val>\w+)[^\*+]/",$string,$matches);
echo $matches[0];
will echo 123naasdme456
and here it is implemented into your code
function getReal($urlVar)
{
if(preg_match("/[^\*+](?P<val>\w+)[^\*+]/",$urlVar,$matches))
{
return $matches[0];
}
return false; // or default value
}
$pid = getReal($_GET['pid']);
$name = getReal($_GET['pname']);
You should add an extra field in your database (table main_page) with the name name or something similar. Then you could:
if (!$_GET['pname']) {
$pid = 'home';
} else {
$pid = mysql_real_escape_string($pid);
$sql = mysql_query("SELECT name FROM main_page WHERE name = '$pid'");
if (mysql_num_rows($sql) == 1))
{
echo "Content";
} else {
echo "404 error. Couldn't find the page you were looking for.";
}
}
URL Rewriting. http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/