How can I turn my search results into links in php? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
My search is running perfectly but I need to link each result to a description page. Any ideas as to how to do it?
<?php
session_start();
require_once 'login.php';
$conn = mysqli_connect($server,$user,$password,$dbase);
if(!$conn){
die("Failure to connect".mysqli_connect_error());
}
$id = $_SESSION['twitcher'];
$srch = $_POST['searchstr'];
$sql = "select * from gallery where title like '%$srch%'";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result) > 0){
while ($rows=mysqli_fetch_assoc($result)){
echo $rows['title'].$br.$br;
}
}else echo "No posts found.";
mysqli_close($conn);
?>

Exactly as #Dagon stated: You need to simply echo out a link tag (<a>)
while ($rows=mysqli_fetch_assoc($result)) {
echo "<a href='/link_to_where_you_want_to_go'>" . $rows['title'] . "</a>" . $br . $br;
}

Related

image not picking up the path [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
this my code but unable to display image from db in php.i think this is not pick up the path.any one can help in this regard.
<?php
include('connect.php');
$result = $db->prepare("SELECT image FROM info WHERE empid= '". $empid ."'");
$result->bindParam('. $empid .', $empid);
$result->execute();
for($i=0; $rows = $result->fetch(); $i++){
echo '<img src="images/".$row["image"]." ">';
echo '<img src="images/".$row["image"]. > ' ;
}
?>
You either concatenate the id onto the text string containing the query or use a parameter place holder and then bind a value to it. Not both, as you were doing.
The most secure way is to use parameters.
<?php
include('connect.php');
// I assume you have set $empid somewhere in the missing code here
$result = $db->prepare("SELECT image FROM info WHERE empid= :empid");
$result->bindParam(':empid', $empid, , PDO::PARAM_INT);
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
// also changed these 2 rows to correct the concatenation
echo '<img src="images/"' . $row["image"] . '">';
echo '<img src="images/"' . $row["image"] . '">';
}
?>

Print out UPDATE and DELETE query [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
At bottom of INSERT php/sql code, i use echo to print out query result to fix errors, in this way:
... code ...
$result = MYSQL_QUERY($sqlQuery);
echo $sqlQuery
Exist a solution to print out UPDATE and DELETE queries like above?
TKS All
Based on the comments to OP, you need to change the way you run the query if you want this to work. Below is how I would've done it.
$update = "UPDATE mod_document_images SET image_os_res = '" . $checkbox_os . "', image_ne_aut = '" . $checkbox_ne . "', image_ge_cat = '" . $image_gen_cat . "' WHERE image_id = " . $image_id;
echo "Query: " . $query; // Echo the query containing the variables supplied
$result = mysql_query($update); // Run the update and store the result in $result

error with sql syntax [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i tried without single quotes and with it does not work.
$insert_query="INSERT INTO users_line
(name,surname,company_name,tel_number,cell_number,email,location,main_image,about_us)
VALUES('$name','$surname','$company_name','$tel_number','$cell_number','$email','$location','$main_image','$about_us')";
if(mysqli_query($connect,$insert_query==true)){
echo " <script>alert('successfully Posted') </script> ";
} else{ echo " h1> Did not work </h1>";
try
$connect->query($insert_query) to run the query.
Try this.
$insert_query="INSERT INTO
users_line (name,surname,company_name,tel_number,cell_number,email,location,main_image,about_us)
VALUES('$name', '$surname','$company_name', '$tel_number', '$cell_number', '$email', '$location', '$ main_image', '$about_us')";
mysqli_query($connect,$insert_query);
if(mysqli_affected_rows($connection) > 0){
echo "It is working";
}
else{
echo "Not Working!";
You had echo " h1> Did not work </h1>"; that should be echo "<h1> Did not work </h1>";

Only the first entry from database is displayed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have 2 php files that retrieve a BLOB image from mysql DB. My DB has stored a couple of different images, as i try to display them on the browser, only the first image is displayed multiple times, for example: The DB table has stored 5 images, the browser is going to display the first image 5 times.
here is a snippet from my main php file:
$strSQL = "SELECT * FROM images";
$rs = mysql_query($strSQL) or die (mysql_error());
echo "<table>";
while($row = mysql_fetch_array($rs)) {
echo "<tr><td>";
echo " <img src=load_pic.php?id=".$row["id"]." id='img' width='100' height='100'></a>";
echo "</td></tr>";
}
echo "</table>"
and the php file that gets the images "load_pic.php"
$q="select * from images";
$rec=mysql_fetch_array(mysql_query($q));
$data=$rec['image'];
header('Content-Length: '.strlen($data));
header("Content-type: image/".$rec['type']);
echo $data;
Your load_pic.php script is not using the id parameter. It should be:
$q = "select * from images where id = " . mysql_real_escape_string($_GET['id']);

How to get the result in the form of anchor tags in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hello i am beginner to PHP.I am not getting an idea regarding how to get all the rows as an output in the form of anchor tags .Here is my following code where blogtable is the name of the table . For instance i have five rows in a table . I want the entire rows as links as a resultant.By executing the following code i am getting the records in a table but unable to transform these results into anchor tags.Kindly suggest me an idea to get each and every row in the form of anchor tag.Thanks in advance.
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("test");
$data = mysql_query("select * from blogtable");
while ($col = mysql_fetch_field($data)) {
echo $col->name;
}
while ($row = mysql_fetch_row($data)) {
for ($i = 0; $i < count($row); $i++) {
echo"<br/>";
echo"$row[$i]></a>";
echo"<br/>";
}
}
?>
Just add your link inside the for loop:
echo "<a href='http://example.com'>" . $row[$i] . "</a>";
Try this: echo "".$row[$i]."";
echo"$row[$i]></a>;
This is not the correct syntax for an anchor tag. Try something like:
echo "<a href='some site'>$row[$i]</a>";

Categories