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
New to php. Trying to create a list of images with text in a loop. The script works fine with just , but I want to add a class name to it so that I can control it with css, but I am getting an error. Seems not to flow cleanly with HTML. Any suggestions?
$rs = $conn->Execute("SELECT ProductName, ProductID FROM Products ");
//opens a recordset from the connection object
while (!$rs->EOF) {
$fv1=$rs->Fields("ProductID");
$fv2=$rs->Fields("ProductName");
print "<div class="product-img"> ";
print "<a href='moredetails.php?productid=$fv1'>";
print "<img src = \"thumbs/artifact-$fv1.jpg\" alt = \"Artifact-$fv1\"</a><br>";
print "<a href='moredetails.php?productid=$fv1'>";
print "$fv2</a><br>";
print "</div>";
$rs->MoveNext();
}
$rs->Close();
The double quotation will close the php function, try to use a single quotation for your class attr.
print "<div class='product-img'> ";
or escape it
print "<div class=\"product-img\"> ";
Change
print "<div class="product-img"> ";
to
print "<div class=\"product-img\"> ";
Related
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;
}
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>";
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']);
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>";
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 have fixed my earlier problem, but now the loop produces 8 or more images for each. In one gallery I have one a single image but get it eight times, not ten, not three, what's with the eight loops?
while($row = mysql_fetch_array($result)){
$AID = $row['AID'];
$ThumbFilePath = $row['ThumbFilePath'];
$Title = $row['Title'];
$DisplayOrder = $row['DisplayOrder'];
foreach($row as $cell)
{
echo "<div id='clear'></div>";
echo "<div id='thumb_container'>";
echo "<a href='gallery_detail.php?AID=$AID'><img src='http://markdinwiddie.com/PHP2012/$ThumbFilePath' title='Enlarge' alt='Enlarge' border='0'></a>";
echo "<div id='name_spacer'></div>";
echo "<div id='thumbdesc'>";
echo "$Title";
echo "</div>";
echo "</div>";
}
}
You have a nested loop.
while($row = mysql_fetch_arry($result)){ //once for each row in the database
foreach($row as $cell){ //once for each field in the table
...
}
}
I'm guessing your table has 8 fields. Remove the foreach{}.
8 columns selected in $result
so $row is an array consist of 8 element.
foreach($row as $cell)
foreach will loop 8 times.