Php image error in displaying - php

When i run this query images are displaying from php correctly.
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("dawat");
$submit=$_GET['str'] ;
$sql = mysql_query("SELECT * FROM searchengine WHERE pagecontent LIKE '%$_GET%' ");
while($row=mysql_fetch_array($sql)) {
echo "<img src=image.php?pagecontent=".$row['pagecontent']." />";
}
?>
And code of image.php:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysql_connect("localhost","root","");
if(!$conn)
{
echo mysql_error();
}
$db = mysql_select_db("dawat",$conn);
if(!$db)
{
echo mysql_error();
}
$pagecontent = $_GET['pagecontent'];
$q = "SELECT pageurl FROM searchengine where pagecontent='$pagecontent'";
$sql = mysql_query("$q",$conn);
if($sql)
{
$row = mysql_fetch_array($sql);
echo $row['pageurl'];
}
else
{
echo mysql_error();
}
?>
And when i run same code of above just few changes in search script:
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("dawat");
$submit=$_GET['str'] ;
$sql = mysql_query("SELECT pageurl, BIT_COUNT(pagecontent^'$submit')
FROM searchengine WHERE pagecontent < 20 ORDER BY pagecontent ASC;
") or die(mysql_error());
while($row=mysql_fetch_array($sql)) {
echo "<img src=image.php?pagecontent=".$row['pagecontent']." />";
}
?>
It is showing errors that undefined index:pagecontent and also not showing images.Please help and thanks in advance.

In your query
$sql = mysql_query("SELECT pageurl, BIT_COUNT(pagecontent^'$submit')
FROM searchengine WHERE pagecontent < 20 ORDER BY pagecontent ASC;
") or die(mysql_error());
You are not fetching the column pagecontent and is trying to access it in
echo "<img src=image.php?pagecontent=".$row['pagecontent']." />";
^
So change your query to,
$sql = mysql_query("SELECT pageurl,pagecontent, BIT_COUNT(pagecontent^'$submit')
FROM searchengine WHERE pagecontent < 20 ORDER BY pagecontent ASC;
") or die(mysql_error());

Try it and get print value from $sql.. you will get idea from how to return it..
$sql = mysql_query("SELECT pageurl,pagecontent, BIT_COUNT(pagecontent^'$submit')
FROM searchengine WHERE pagecontent < 20 ORDER BY pagecontent ASC;
") or die(mysql_error());

Related

SELECT 2 Identical databases to get 2 website orders on one list

I'm trying to connect two databases into a mysql query and it's also great!
After that, I try to find data on the order in the correct database to get meta_value from it.
But it mixes meta_value $ first name and sometimes duplicates them on the rows.
If I just conect 1 database, they will come out as they should
Anybody can see what goes wrong?
Url to example: https:// http://kundeservice.coalsmile.com/test4.php
<?php
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$v1 = "coalsmil_wp282";
$v2 = "coalsmil_wp111";
$v3 = "coalsmil_wp72";
$v4 = "coalsmil_wp193";
$v5 = "coalsmil_wp555";
$v6 = "coalsmil_wp366";
$v7 = "coalsmil_wp74";
$v8 = "coalsmil_wp721";
$v9 = "coalsmil_wp924";
$v10 = "coalsmil_wp253";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
//Here I connect to both databases
$query103 = mysqli_query($conn, "SELECT * FROM `$v1`.`wpd2_posts`
where post_status='wc-processing' or post_status='wc-completed'
or post_status='wc-failed' UNION
SELECT * FROM `$v2`.`wpd2_posts`
where post_status='wc-processing' or post_status='wc-completed'
or post_status='wc-failed' order by post_date DESC ") or die(mysqli_error($conn));
?>
<br>
<h2>Database 3</h2>
<table style="width: 100%">
<tr>
<td>ID</td>
<td>??</td>
<td>??</td>
<td>??</td>
<td>??</td>
<td>??</td>
</tr>
<?php
while($row = mysqli_fetch_array($query103))
{
// Here I try to find what database the customer is on
$id2 = $row['ID'];
if($row['ID'] == ''){
echo "intet id";
}else {
$query = mysqli_query($conn, "SELECT * FROM `$v1`.`wpd2_posts` where ID = '$id2' ORDER BY id") or die(mysqli_error($conn));
if(mysqli_num_rows($query) == '') {
$query = mysqli_query($conn, "SELECT * FROM `$v2`.`wpd2_posts` where ID = '$id2' ORDER BY id") or die(mysqli_error($conn));
if(mysqli_num_rows($query) == '') {
}else{
$version = "coalsmil_wp111";
}
}else{
$version = "coalsmil_wp282";
}
}
echo "<tr>";
echo "<td>". $row['ID']."</td>";
echo "<td>". $row['post_date']."</td>";
echo "<td>". $row['post_status']."</td>";
//And here I try to get the data out
$querynavn = mysqli_query($conn, "SELECT meta_value FROM `$version`.`wpd2_postmeta` where meta_key='_shipping_first_name' and post_id='$id2' ") or die(mysqli_error($conn));
while($row2 = mysqli_fetch_array($querynavn))
{
$fornavn = urldecode($row2['meta_value']);
}
echo "<td>". $fornavn."</td>";
echo "<td>".$version."</td>";
echo "<td>6</td>";
echo "</tr>";
}
?>
</table>
If you're connections are on the same database server you can specify the schema (database name) to select things from both over one connection. You do this by using schema_name.table_name instead of just the table's name.
So like:
SELECT * FROM schema_name.wpd2_posts WHERE ...
In your case you could use UNION to put it all together:
SELECT * FROM `schema1.wpd2_posts`
where post_status='wc-processing' or post_status='wc-completed'
or post_status='wc-failed' UNION
SELECT * FROM `schema2.wpd2_posts`
where post_status='wc-processing' or post_status='wc-completed'
or post_status='wc-failed' order by post_date DESC LIMIT 10
On a side note you could make this query a bit more readable by using the IN() clause for your critera:
WHERE post_status IN('wc-processing', 'wc-completed','wc-failed')

PHP - While loop not showing table records

In below code it shows table row value outside while loop but not shows inside while loop. While loop not working; Please let me know whats wrong in it?
<?php
$sql = "SELECT * FROM cl_banner ORDER BY id;";
$res = q($sql) or die(mysql_error());
if($res && mysql_num_rows($res)>0)
{
while($row = mysql_fetch_assoc($res));
{
echo $row["title"];
echo "hi";
} // End While
} // End If
?>
<?php
$sql = "SELECT * FROM cl_banner ORDER BY id";
^^^^
$res = mysql_query($sql) or die(mysql_error());
^^^^^^^^^^
if($res && mysql_num_rows($res)>0)
{
while($row = mysql_fetch_assoc($res));
{
echo $row["title"];
echo "hi";
} // End While
} // End If
?>
Try this:
<?php
$sql = "SELECT * FROM cl_banner ORDER BY id";
$res = mysql_query($sql) or die(mysql_error());
if($res && mysql_num_rows($res)>0)
{
while($row = mysql_fetch_assoc($res))
{
echo $row["title"];
echo "hi";
} // End While
} // End If
?>

mysql_num_rows returning zero

<?php
session_start();
$con=mysql_connect("localhost","root","samy");
mysql_select_db("project");
if($con)
{
echo "Connected Successfully ";
}
else
{
echo "Error" . $sql . "<br>" . mysql_connect_error();
}
$name=$_SESSION['name'];
echo $name;
$sql1 = mysql_query("select cust_id from registered_user where name ='.$name.' ");
$r = mysql_num_rows($sql1);
echo $r;
$row1 = mysql_fetch_array($sql1);
$cid = $row1['cust_id'];
echo $cid;
?>
Since num_rows is returning zero therefore $cid is also not printing.
Don't know what's the error;
You should remove the dot(.).
$sql1 = mysql_query("select cust_id from registered_user where name ='$name'");
^ ^
Also suggest to add error reporting like this
$sql1 = mysql_query("select cust_id from registered_user where name ='$name'")
or die(mysql_error());

Loop for Arrays in php

<?php
session_start();
$link = mysqli_connect("localhost", "xxx", "xxxxxx", "xxx");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$id = $_GET['id'];
if ($result = mysqli_query($link, "SELECT * FROM Subscribe WHERE STo = '".$id."' ORDER BY ID LIMIT 6")) {
while($row = mysqli_fetch_array($result))
{
$idS = $row['SWho'];
echo $idS;
if ($result = mysqli_query($link, "SELECT * FROM accounts WHERE ID = '".$idS."' ORDER BY ID LIMIT 6")) {
while($row = mysqli_fetch_array($result))
{
echo "<img src='Member_ProfilePics/";
echo $row['PP'] . '.' . $row['Ext'];
echo "' width=42 height=40 style='float: left'>";
}
}
}
//<img src='Member_ProfilePics/john.jpg' width=42 height=40 style='float: left'>
}
?>
here in my code, i want to output the list of STo. and connect to other database and output the following rows in each STo.
Sample to be output:
(picture of id=1) 1
(picture of id=2) 2
(picture of id=3) 3
(picture of id=4) 4
(picture of id=5) 5
(picture of id=6) 6
How?
my code is not looping.
Sample output of my code:
(picture of id=1) 1
You are using the same variables for both the loops:
if ($result = mysqli_query($link, "SELECT * FROM Subscribe WHERE STo = '".$id."' ORDER BY ID LIMIT 6")) {
while($row = mysqli_fetch_array($result)) {
....
if ($result = mysqli_query($link, "SELECT * FROM accounts WHERE ID = '".$idS."' ORDER BY ID LIMIT 6")) {
while($row = mysqli_fetch_array($result)) {
...
}
}
}
}
Try to change the seconda value to these
if ($result = mysqli_query($link, "SELECT * FROM Subscribe WHERE STo = '".$id."' ORDER BY ID LIMIT 6")) {
while($row = mysqli_fetch_array($result)) {
....
if ($result2 = mysqli_query($link, "SELECT * FROM accounts WHERE ID = '".$idS."' ORDER BY ID LIMIT 6")) {
while($row2 = mysqli_fetch_array($result2)) {
...
}
}
}
}

Php print single id issue

So here's what I want.. When user clicks on some link e.g. http://www.keevik.com/vicevi.php?id=24 that script prints out only that single id.
Here's my code
/* Get data. */
$sql = "SELECT * FROM $tbl_name ORDER BY id DESC LIMIT $start, $limit";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<a href ='vicevi.php?id=".$row['id']."'>".$row['id']."</a>";
echo "<br>";
echo nl2br($row["VicText"]);
echo "<hr>";
}
So, when I click on some link it doesn't do what I actually want :S
$sql = "SELECT * FROM $tbl_name ORDER BY id DESC LIMIT $start, $limit";
if(isset($_GET['id']))
{
$id=intval($_GET['id']);
$sql = "SELECT * FROM $tbl_name WHERE id=$id";
}
$result = mysql_query($sql);
if(!$result)
{
echo 'no data found!';
}
else
{
// etc..
}

Categories