I'm trying to hide a youtube player when there is no yt id in the row/colum, I'm trying but don't know what i'm doing wrong. thank you very much
include 'config.php';
if (isset($_GET['id'])){
$naamID = mysql_real_escape_string($_GET['nameID']);
$id = mysql_real_escape_string($_GET['id']);
$idnext = $id + 1;
$gn = (" SELECT * FROM category WHERE nameID='".$nameID."'") or die(mysql_error());
$go = (" SELECT * FROM post WHERE id='".$id."' and youtube='".$id."'") or die(mysql_error());
$gnn = mysql_query($gn) or die(mysql_error());
$goo = mysql_query($go) or die(mysql_error());
$gnnn = mysql_fetch_array($gnn);
$gooo = mysql_fetch_array($goo);
// down here is the problem
if(!empty($gooo)){
echo 'no video player';
} else {
echo '<h1> '.$gooo["title"].'</h1><br />';
echo '<iframe width="560" height="315" src="//www.youtube.com/embed/'.$gooo["youtube"].'" frameborder="0" allowfullscreen></iframe><br />';
}
The function empty returns true if the variable is empty so remove !.
if(empty($gooo)){
echo 'no video player';
} else {
echo '<h1> '.$gooo["title"].'</h1><br />';
echo '<iframe width="560" height="315" src="//www.youtube.com/embed/'.$gooo["youtube"].'" frameborder="0" allowfullscreen></iframe><br />';
}
Related
This is my sample code please help me guys
<?php
$con =mysql_connect("localhost", "" , "");
$sdb= mysql_select_db("image",$con);
$sql = "SELECT * FROM `tbl_image` WHERE id=21";
$mq = mysql_query($sql) or die ("not working query");
$row = mysql_fetch_array($mq) or die("line 44 not working");
$s = $row['img_url'];
echo '<img src="'.$s.'">';
?>
loop row.
$mq = mysql_query($sql) or die ("not working query");
while ($row = mysql_fetch_array($mq)) {
echo '<img src="' . $row['img_url'] . '" >';
}
should change your last 2 lines to this
while ($row = mysql_fetch_assoc($result)) {
$s = $row['img_url'];
echo '<img src="'.$s.'">';
}
<?php
$con = mysql_connect("localhost", "" , "");
$sdb = mysql_select_db("image",$con);
$sql = "SELECT * FROM `tbl_image` WHERE id=21";
//echo "SELECT * FROM `tbl_image` WHERE id=21"; //and run the query in database if it is working fine then you can use while loop.
$mq = mysql_query($sql) or die ("not working query"); // if this line is not working try eho the above query like i have mentioned in comments.
while ( $row = mysql_fetch_array($mq)) {
echo '<img src="' . $row['img_url'] . '" >';
}
?>
You can try following code.
while($row=mysql_fetch_object($qry))
{
$result[] = $row['img_url'];
echo '<img src="' . $row['img_url'] . '" >';
}
print_r($result)
I want to display images from my MySQL database to an website that I'm working on but when I visit the site I see just a box with a broken image or lot of symbols.
In my MySQL database the image type is LONGBLOB (MIME: image/jpeg).
This is the code that I'm using (I have HTML codes before the PHP codes so I'm using a buffer).
<?php
mysql_connect("localhost", "root", "") or die('connection error');
mysql_select_db("produse");
$per_page = 25;
$pages_query = mysql_query("SELECT COUNT('id') FROM filtrederetea");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($GET['page'])) ? (int)$GET['page'] : 1;
$start = ($page -1) *$per_page;
$query = mysql_query("SELECT * FROM filtrederobinet");
echo "<table>";
if(isset($_GET["id"]))
{
$id = mysql_real_escape_string($_GET['id']);
$query = mysql_query("SELECT * FROM filtrederetea");
while ($query_row = mysql_fetch_assoc($query)) {
$imagedata = $query_row['img'];
'<img src="data:image/jpeg;base64,' . base64_encode($query_row['img']);
};
header('Content-Type: image/jpeg');
echo "($imagedata)";
}
else
echo "error";
while ($query_row = mysql_fetch_assoc($query)) {
echo "<tr>";
echo "<td>";
echo.$query_row["img"];
echo "</td>";
echo "<td>";
?>
<img src=<?php echo $query_row["img"]; ?> width="130" height="130">
<?php
echo "</td>";
echo "</tr>";
}
echo "</table>";
if ($pages >=1) {
for ($x=1;$x<=$pages;$x++) {
echo ''.$x.' ';
}
}
ob_end_flush()
?>
I've discoverd a bug into my script. I will try to explain it.
I've made 2 pages into category.php
This one here below shows all content related to a category:
/category.php?nameID=Test
When I go to the first content related to this category for example:
/category.php?nameID=Test&id=2 I receive information from MYSQL about post ID 2, also all posts related to that category named 'test' below. Which I clearly don't want to get. only the Post ID
<?php
// BEGIN OF SHOWING CONTENT PAGE
if (isset($_GET['id'])){
$naamID = mysql_real_escape_string($_GET['nameID']);
$id = mysql_real_escape_string($_GET['id']);
$idnext = $id + 1;
$gn = (" SELECT * FROM category WHERE name='".$naamID."'") or die(mysql_error());
$go = (" SELECT * FROM post WHERE id='".$id."'") or die(mysql_error());
$gnn = mysql_query($gn) or die(mysql_error());
$goo = mysql_query($go) or die(mysql_error());
$gnnn = mysql_fetch_array($gnn);
$gooo = mysql_fetch_array($goo);
?>
<?php
echo '<p>';
if(empty($gooo['youtube'])){
} else {
?> <h1> <?php echo htmlspecialchars($gooo["title"]); ?> </h1><br />
<?php
$fullurl1 = $gooo['youtube'];
$videoid1=substr($fullurl1,-11);
?>
<?php
echo '<p><i>Edit this post</i><br />';
echo '<iframe width="560" height="315" src="//www.youtube.com/embed/'.$videoid1.'" frameborder="0" allowfullscreen></iframe><br />';
echo '</p>';
}
if(empty($gooo['pic'])){
} else {
?> <h1> <?php echo htmlspecialchars($gooo["title"]); ?> </h1><br />
<?php
echo '<p><i>Edit this post</i><br />';
echo '<img src="'.$gooo["pic"].'" style="max-height: auto; max-width: 600px;"/><br></p>';
}
echo '</p>';
}
?>
I dont know what you exactly want please be specific
But your code should be like this ->
$gnn = mysql_query("SELECT * FROM category WHERE name='$naamID'") or die(mysql_error());
$goo = mysql_query("SELECT * FROM post WHERE id= $id ") or die(mysql_error());
$gnnn = mysql_fetch_array($gnn);
$gooo = mysql_fetch_array($goo);
The above code will fetch only one row from each table. Also you had put $id in single quotes that makes it a string
Comment below if you need more help
I am trying to create dynamic pages on my website, but it fails.
When I try the code on Xampp it works perfect. There is another thing that I don't understand.
It will catch the id, but not the title or anything with characters from the database.
When I try $title = $_GET['title']; it won't work. It works only with $_GET['id'];
Any help?
Here is the code:
index.php
<?php
include('inc/code.inc.php');
$fetch = mysql_query("SELECT * FROM `star` ORDER BY `title`");
while ($output = mysql_fetch_assoc($fetch))
{
echo ''. $output['title'] .'<br />';
}
?>
run.inc.php
<?php
include_once('inc/code.inc.php');
$newID = $_GET['id'];
$fetch = mysql_query("SELECT * FROM `star` WHERE `id` = $newID");
while ($output = mysql_fetch_assoc($fetch))
{
echo $output['title'] . '<br />' . $output['explain'];
}
?>
Here is the code that won't work:
index.php
<?php
include('inc/code.inc.php');
$fetch = mysql_query("SELECT * FROM `star` ORDER BY `title`");
while ($output = mysql_fetch_assoc($fetch))
{
echo ''. $output['title'] .'<br />';
}
?>
run.inc.php
<?php
include_once('inc/code.inc.php');
$newID = $_GET['title'];
$fetch = mysql_query("SELECT * FROM `star` WHERE `title` = $newID");
while ($output = mysql_fetch_assoc($fetch))
{
echo $output['title'] . '<br />' . $output['explain'];
}
?>
Add title to your URL GET parameter please..Like you have added ID
<?php
include('inc/code.inc.php');
$fetch = mysql_query("SELECT * FROM `star` ORDER BY `title`");
while ($output = mysql_fetch_assoc($fetch))
{
echo '<a href = "run.inc.php?id='. $output['id'] .'"'.'?title='. $output['title'] .'</a><br />';
}
?>
Modify the url according to your needs please.
If you are comparing a string like $_GET['title'] to the column, you need to escape it (as opposed to a numeric ID, which does not need to be escaped).
Try this for run.inc.php
$newID = $_GET['title'];
$fetch = mysql_query("SELECT * FROM `star` WHERE `title` = '$newID'");
while ($output = mysql_fetch_assoc($fetch))
{
echo $output['title'] . '<br />' . $output['explain'];
}
?>
I'm new at php and JavaScript so I hope you can help me!
below is a php code! it take data from my db and display my photos and photo's title. what I want to do is if you click on one of this photos and than a new php expe: photo.php opens and you can see the same photo alone not with the other ones.
<?php
$link = mysql_connect("localhost", "root","");
mysql_select_db("test", $link);
$query = "select * from post order by id DESC;";
$results = mysql_query($query, $link) or die ("you comand can't be executed!".mysql_error());
if($results){
$i = 1;
while ($row = mysql_fetch_assoc($results)){
echo $row['title']. "<img src=/1/" . $row['location']. " width=580px > " . "<br /><br /><br />";
}
}
?> '
<?php
$link = mysql_connect("localhost", "root","");
mysql_select_db("test", $link);
$query = "select * from post order by id DESC;";
$results = mysql_query($query, $link) or die ("you comand can't be executed!".mysql_error());
if($results){
$i = 1;
while ($row = mysql_fetch_assoc($results)){
//send photo_id (id of photo from your table) from url NOTE: I've put link here
echo $row['title']. "<a href='index.php?photo_id=".$row['id']."'><img src=/1/" . $row['location']. " width=580px ></a> " . "<br /><br /><br />";
}
if(isset($_GET['photo_id'])) {
//here you get only one id of photo now retrieve the data from database and display the image
}
}
?>
You will get the photo by the help of the url value here photo_id.
do this way you are getting results from database and you are
displaying them with tile and image your aim is to click on
image or image title go to a new page and display image alone
the image title as link in first page
if($results){
$i = 1;
while ($row = mysql_fetch_assoc($results)){
<a href='new page url?id=<?php echo $row["id"] ?>'>
echo $row['title'];
echo "</a>"
}
}
where $row['id'] is database unique id if have no it is always preferred
to create a database with unique id and in new page get the uid
using $id=$_GET['id'] and
do as below
if($results){
$i = 1;
while ($row = mysql_fetch_assoc($results)){
if($id==$roe['id']{
echo $row['title']. "<img src=/1/" . $row['location']. " width=580px > ";
}
}
}